Spaces:
Sleeping
Sleeping
File size: 2,651 Bytes
927e481 e91f981 927e481 e91f981 927e481 e91f981 927e481 e91f981 927e481 e91f981 927e481 e91f981 927e481 e91f981 927e481 e91f981 927e481 e91f981 927e481 e91f981 927e481 e91f981 |
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import streamlit as st
from open_image_models import LicensePlateDetector
from PIL import Image
import cv2
import numpy as np
from rich.console import Console
# Set up the rich console for better terminal output
console = Console()
# 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.")
st.markdown("---")
# Model selection dropdown
selected_model = st.selectbox("π Select a License Plate Detection Model", PlateDetectorModel)
# File uploader for images
uploaded_file = st.file_uploader("π Upload an image...", type=["jpg", "png", "jpeg", "webp"])
if uploaded_file is not None:
# Load the image using PIL
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image', use_column_width=True)
st.write("")
st.write("π **Detecting license plates...**")
# Convert the PIL image to an OpenCV format (NumPy array)
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 using `rich` for colorful output in the console
console.print(f"[bold green]Detections: [/bold green] {detections}")
# Streamlit display for detections
if detections:
st.success(f"β
{len(detections)} License Plates Detected!")
for i, detection in enumerate(detections):
st.write(f"**Plate {i+1}:** {detection}")
else:
st.warning("β οΈ No license plates detected!")
# Annotate and display the image with detected plates
annotated_image = lp_detector.display_predictions(image_cv2)
# Convert the annotated image from BGR to RGB for Streamlit display
annotated_image_rgb = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
st.image(annotated_image_rgb, caption='Annotated Image with Detections', use_column_width=True)
# Add some additional style or layout to make the app more attractive
st.markdown("""
<style>
.stButton>button {
font-size: 16px;
background-color: #4CAF50;
color: white;
border-radius: 8px;
}
</style>
""", unsafe_allow_html=True)
|