Spaces:
Runtime error
Runtime error
import gradio as gr | |
import cv2 | |
import pytesseract | |
# Function to recognize license plate in the uploaded image | |
def recognize_license_plate(image): | |
# Load the image | |
img = cv2.imdecode(image, cv2.IMREAD_COLOR) | |
# Convert the image to grayscale | |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
# Apply thresholding to preprocess the image | |
_, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) | |
# Use pytesseract to perform OCR (Optical Character Recognition) | |
text = pytesseract.image_to_string(thresh, config='--psm 6') | |
# Display the recognized text | |
return text.strip() | |
# Create Gradio interface | |
gr.Interface(fn=recognize_license_plate, | |
inputs=gr.inputs.Image(source="upload", type="pil"), | |
outputs="text", | |
title="License Plate Recognition", | |
description="Upload an image of a car containing a license plate.").launch() | |