File size: 574 Bytes
6955481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2
import numpy as np
import gradio as gr
import pytesseract

def ocr_image(img):
  """Performs OCR on an image using OpenCV and PyTesseract."""
  # Preprocess image (optional)
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

  # OCR using PyTesseract
  text = pytesseract.image_to_string(thresh)
  return text

# Create the Gradio interface
iface = gr.Interface(
    fn=ocr_image,
    inputs="image",
    outputs="text",
    title="OCR with OpenCV and PyTesseract"
)

iface.launch()