File size: 1,663 Bytes
927e481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
from open_image_models import LicensePlateDetector
from PIL import Image
import cv2
import numpy as np

# Define the available models
PlateDetectorModel = ['yolo-v9-t-640-license-plate-end2end', 
                      'yolo-v9-t-512-license-plate-end2end', 
                      'yolo-v9-t-384-license-plate-end2end', 
                      'yolo-v9-t-256-license-plate-end2end']

# Streamlit interface
st.title("License Plate Detection with Open Image Models")
st.write("Select a model and upload an image to perform license plate detection.")

# Model selection dropdown
selected_model = st.selectbox("Select a License Plate Detection Model", PlateDetectorModel)

# File uploader for images
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg", "webp"])

if uploaded_file is not None:
    # Load the image
    image = Image.open(uploaded_file)
    st.image(image, caption='Uploaded Image', use_column_width=True)
    st.write("")
    st.write("Detecting license plates...")

    # Convert the image to an OpenCV format
    image_np = np.array(image)
    image_cv2 = cv2.cvtColor(image_np, cv2.COLOR_RGB2BGR)

    # Initialize the License Plate Detector
    lp_detector = LicensePlateDetector(detection_model=selected_model)

    # Perform license plate detection
    detections = lp_detector.predict(image_cv2)

    # Display the detected plates
    st.write(f"Detections: {detections}")

    # Annotate and display the image with detected plates
    annotated_image = lp_detector.display_predictions(image_cv2)
    st.image(annotated_image, caption='Annotated Image with Detections', use_column_width=True)