File size: 1,142 Bytes
7f4eb24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from PIL import Image
import cv2
import numpy as np
import cvlib as cv
from cvlib.object_detection import draw_bbox

# Streamlit UI
st.title("Object Detection with YOLO")
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])

if uploaded_image is not None:
    image = Image.open(uploaded_image)
    st.image(image, caption="Uploaded Image", use_column_width=True)

    if st.button("Detect Objects"):
        st.write("Detecting objects...")

        # Convert the uploaded image to a NumPy array
        image_np = np.array(image)

        # Use YOLOv3 for object detection
        bbox, label, conf = cv.detect_common_objects(image_np)

        # Draw bounding boxes on the image
        output_image = draw_bbox(image_np, bbox, label, conf)

        # Convert the NumPy array back to an image
        output_image = Image.fromarray(output_image)

        # Display the image with bounding boxes
        st.image(output_image, caption="Objects Detected", use_column_width=True)

st.text("Upload an image and click the 'Detect Objects' button to see object detection results using YOLO.")