Spaces:
Paused
Paused
import gradio as gr | |
# try: | |
# from PIL import Image | |
# except ImportError: | |
# import Image | |
import cv2 | |
import pytesseract | |
sample_img = cv2.imread(r'/content/image.png') | |
def ocr_core(img): | |
text = pytesseract.image_to_string(img) | |
return text | |
def get_grayscale(image): | |
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
def remove_noise(image): | |
return cv2.medianBlur(image,5) | |
def thresholding(image): | |
return cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1] | |
def final_ocr(img): | |
gray = get_grayscale(img) | |
thresh = thresholding(gray) | |
noiseless = remove_noise(thresh) | |
return ocr_core(noiseless) | |
def greet(name): | |
return "Hello " + name + "!!" | |
# iface = gr.Interface(fn=greet, inputs="text", outputs="text") | |
# iface.launch() | |
demo = gr.Interface(fn=final_ocr, | |
inputs=gr.inputs.Image(type="pil"), | |
outputs=gr.outputs.Textbox()) | |
demo.launch() |