vinay9171 commited on
Commit
54369db
1 Parent(s): 80aa451

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ # Import your chosen deep learning framework (TensorFlow or PyTorch)
5
+ # ...
6
+ import tensorflow
7
+
8
+ # Load the pre-trained object detection model
9
+ model = cv2.dnn_DetectionModel("path/to/model.weights", "path/to/model.cfg")
10
+ model.setInputParams(size=(416, 416), scale=1/255)
11
+
12
+ # Optional: Load EasyOCR model if using
13
+ reader = EasyOCR("en") # Change "en" to your desired language code
14
+
15
+ def detect_plates(image):
16
+ # Preprocess image for model input (resizing, normalization, etc.)
17
+ # ...
18
+ classes, confidences, boxes = model.detect(image)
19
+
20
+ for (class_id, confidence, box) in zip(classes.flatten(), confidences.flatten(), boxes):
21
+ if class_id == (class_index for class_index in range(len(model.names)) if model.names[class_index] == "license_plate"): # Adjust class index based on your model
22
+ x_min, y_min, x_max, y_max = box
23
+ plate_roi = image[y_min:y_max, x_min:x_max]
24
+
25
+ # Perform character recognition (if not using EasyOCR, implement your own)
26
+ plate_text = "..."
27
+ if reader is not None:
28
+ result = reader.readtext(plate_roi)
29
+ plate_text = result[0][1]
30
+
31
+ # Display bounding box and plate text (or confidence score if not using OCR)
32
+ cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (255, 0, 0), 2)
33
+ if reader is not None:
34
+ cv2.putText(image, plate_text, (x_min, y_min - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 0), 2)
35
+ else:
36
+ cv2.putText(image, f"Confidence: {confidence:.2f}", (x_min, y_min - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 0), 2)
37
+
38
+ return image
39
+
40
+ def main():
41
+ """Streamlit app"""
42
+ st.title("Number Plate Detection App")
43
+
44
+ uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"])
45
+ if uploaded_file is not None:
46
+ image = cv2.imdecode(np.fromstring(uploaded_file.read(), np.uint8), cv2.IMREAD_COLOR)
47
+ results = detect_plates