Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from open_image_models import LicensePlateDetector
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import cv2
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Define the available models
|
| 8 |
+
PlateDetectorModel = ['yolo-v9-t-640-license-plate-end2end',
|
| 9 |
+
'yolo-v9-t-512-license-plate-end2end',
|
| 10 |
+
'yolo-v9-t-384-license-plate-end2end',
|
| 11 |
+
'yolo-v9-t-256-license-plate-end2end']
|
| 12 |
+
|
| 13 |
+
# Streamlit interface
|
| 14 |
+
st.title("License Plate Detection with Open Image Models")
|
| 15 |
+
st.write("Select a model and upload an image to perform license plate detection.")
|
| 16 |
+
|
| 17 |
+
# Model selection dropdown
|
| 18 |
+
selected_model = st.selectbox("Select a License Plate Detection Model", PlateDetectorModel)
|
| 19 |
+
|
| 20 |
+
# File uploader for images
|
| 21 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg", "webp"])
|
| 22 |
+
|
| 23 |
+
if uploaded_file is not None:
|
| 24 |
+
# Load the image
|
| 25 |
+
image = Image.open(uploaded_file)
|
| 26 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 27 |
+
st.write("")
|
| 28 |
+
st.write("Detecting license plates...")
|
| 29 |
+
|
| 30 |
+
# Convert the image to an OpenCV format
|
| 31 |
+
image_np = np.array(image)
|
| 32 |
+
image_cv2 = cv2.cvtColor(image_np, cv2.COLOR_RGB2BGR)
|
| 33 |
+
|
| 34 |
+
# Initialize the License Plate Detector
|
| 35 |
+
lp_detector = LicensePlateDetector(detection_model=selected_model)
|
| 36 |
+
|
| 37 |
+
# Perform license plate detection
|
| 38 |
+
detections = lp_detector.predict(image_cv2)
|
| 39 |
+
|
| 40 |
+
# Display the detected plates
|
| 41 |
+
st.write(f"Detections: {detections}")
|
| 42 |
+
|
| 43 |
+
# Annotate and display the image with detected plates
|
| 44 |
+
annotated_image = lp_detector.display_predictions(image_cv2)
|
| 45 |
+
st.image(annotated_image, caption='Annotated Image with Detections', use_column_width=True)
|