Apollo-Soyuz commited on
Commit
9a97cfe
1 Parent(s): c5ceb43

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import pytesseract
4
+
5
+ # Function to recognize license plate in the uploaded image
6
+ def recognize_license_plate(image):
7
+ # Load the image
8
+ img = cv2.imdecode(image, cv2.IMREAD_COLOR)
9
+
10
+ # Convert the image to grayscale
11
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
12
+
13
+ # Apply thresholding to preprocess the image
14
+ _, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
15
+
16
+ # Use pytesseract to perform OCR (Optical Character Recognition)
17
+ text = pytesseract.image_to_string(thresh, config='--psm 6')
18
+
19
+ # Display the recognized text
20
+ return text.strip()
21
+
22
+ # Create Gradio interface
23
+ gr.Interface(fn=recognize_license_plate,
24
+ inputs=gr.inputs.Image(source="upload", type="pil"),
25
+ outputs="text",
26
+ title="License Plate Recognition",
27
+ description="Upload an image of a car containing a license plate.").launch()