teseractocr / app.py
sussahoo's picture
Update app.py
edbee95
raw
history blame
980 Bytes
import gradio as gr
import cv2
import pytesseract
import numpy as np
from PIL import Image
import urllib
def process_image(image):
image = np.array(image)
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
gray, img_bin = cv2.threshold(gray,128,255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)
gray = cv2.bitwise_not(img_bin)
kernel = np.ones((2, 1), np.uint8)
img = cv2.erode(gray, kernel, iterations=1)
img = cv2.dilate(img, kernel, iterations=1)
generated_text = pytesseract.image_to_string(img)
return generated_text
title = "Interactive demo: Tesseract OCR"
description = "Demo for tesseract ocr"
article = "<p style='text-align: center'></p>"
examples =[["image_0.png"]]
iface = gr.Interface(fn=process_image,
inputs=gr.inputs.Image(type="pil"),
outputs=gr.outputs.Textbox(),
title=title,
description=description,
article=article)
iface.launch(debug=True)