File size: 1,940 Bytes
41356b7
44ad3d8
41356b7
44ad3d8
41356b7
 
 
 
 
80caae0
41356b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80caae0
41356b7
 
 
 
 
 
 
44ad3d8
41356b7
44ad3d8
41356b7
 
4fcae56
41356b7
44ad3d8
41356b7
44ad3d8
 
41356b7
 
 
4fcae56
41356b7
 
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
# Install necessary libraries
import streamlit as st
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
import cv2
import numpy as np
from PIL import Image

# Step 1: Download the YOLO model weights from your Hugging Face repository
weights_path = hf_hub_download(repo_id="krishnamishra8848/Nepal-Vehicle-License-Plate-Detection", filename="last.pt")

# Step 2: Load the YOLO model
model = YOLO(weights_path)

# Step 3: Function to process and display results
def detect_license_plate(image):
    # Convert the PIL image to a numpy array
    img = np.array(image)
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

    # Perform inference
    results = model(img)

    # Draw bounding boxes and confidence scores
    for result in results:
        if hasattr(result, 'boxes') and result.boxes is not None:
            for box, conf in zip(result.boxes.xyxy, result.boxes.conf):
                x1, y1, x2, y2 = map(int, box)  # Convert to integers
                cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)  # Green rectangle
                label = f"Confidence: {conf:.2f}"
                cv2.putText(img, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

    # Convert back to RGB for Streamlit display
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    return Image.fromarray(img)

# Streamlit Interface
st.title("Nepal Vehicle License Plate Detection")
st.write("Upload an image to detect license plates.")

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

if uploaded_file is not None:
    # Display the uploaded image
    image = Image.open(uploaded_file)
    st.image(image, caption="Uploaded Image", use_column_width=True)

    # Run detection
    st.write("Processing...")
    result_image = detect_license_plate(image)

    # Display the results
    st.image(result_image, caption="Detection Results", use_column_width=True)