File size: 950 Bytes
9a97cfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()