|
import streamlit as st |
|
from ultralytics import YOLO |
|
import cv2 |
|
from PIL import Image |
|
import numpy as np |
|
|
|
|
|
model = YOLO("yolov8x.pt") |
|
|
|
|
|
st.title("YOLOv8 Object Detection - Image Upload") |
|
|
|
|
|
st.write("Upload an image, and YOLOv8 will predict the objects in the image with bounding boxes.") |
|
|
|
|
|
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
image = Image.open(uploaded_file) |
|
st.image(image, caption="Uploaded Image", use_column_width=True) |
|
|
|
|
|
img_array = np.array(image) |
|
|
|
|
|
results = model.predict(img_array, conf=0.5, iou=0.4) |
|
|
|
|
|
st.write(f"Detected {len(results)} objects.") |
|
|
|
|
|
annotated_img = results[0].plot() |
|
|
|
|
|
annotated_img_pil = Image.fromarray(annotated_img) |
|
|
|
|
|
st.image(annotated_img_pil, caption="Processed Image with Bounding Boxes", use_column_width=True) |
|
|