import streamlit as st import cv2 import numpy as np # Import your chosen deep learning framework (TensorFlow or PyTorch) # ... import tensorflow # Load the pre-trained object detection model model = cv2.dnn_DetectionModel("path/to/model.weights", "path/to/model.cfg") model.setInputParams(size=(416, 416), scale=1/255) # Optional: Load EasyOCR model if using reader = EasyOCR("en") # Change "en" to your desired language code def detect_plates(image): # Preprocess image for model input (resizing, normalization, etc.) # ... classes, confidences, boxes = model.detect(image) for (class_id, confidence, box) in zip(classes.flatten(), confidences.flatten(), boxes): 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 x_min, y_min, x_max, y_max = box plate_roi = image[y_min:y_max, x_min:x_max] # Perform character recognition (if not using EasyOCR, implement your own) plate_text = "..." if reader is not None: result = reader.readtext(plate_roi) plate_text = result[0][1] # Display bounding box and plate text (or confidence score if not using OCR) cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (255, 0, 0), 2) if reader is not None: cv2.putText(image, plate_text, (x_min, y_min - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 0), 2) else: cv2.putText(image, f"Confidence: {confidence:.2f}", (x_min, y_min - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 0), 2) return image def main(): """Streamlit app""" st.title("Number Plate Detection App") uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"]) if uploaded_file is not None: image = cv2.imdecode(np.fromstring(uploaded_file.read(), np.uint8), cv2.IMREAD_COLOR) results = detect_plates