Spaces:
Paused
Paused
File size: 929 Bytes
1bd0a3d 5a766cf 1bd0a3d 5a766cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
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() |