Son Ngo
yolo conflict
925abef
raw
history blame
903 Bytes
import streamlit as st
import cv2
from PIL import Image
import numpy as np
from ultralytics import YOLO
# Load YOLO model (latest version)
model = YOLO('yolo/best.pt')
st.title("YOLO Object Detection Web App")
# Upload image
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Convert the file to an OpenCV image
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
st.write("Processing...")
# Convert the image to a format compatible with YOLO
image_np = np.array(image)
image_cv = cv2.cvtColor(image_np, cv2.COLOR_RGB2BGR)
# Perform YOLO detection
results = model(image_cv)
# Render the results
detected_image = np.squeeze(results.render())
# Display result
st.image(detected_image, caption="Detected Image", use_column_width=True)