Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,37 +2,20 @@ import streamlit as st
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
from ultralytics import YOLO
|
|
|
|
| 5 |
|
| 6 |
# Load YOLO model (Download "yolov8n.pt" first if not available)
|
| 7 |
model = YOLO("yolov8n.pt")
|
| 8 |
|
| 9 |
st.title("🎥 YOLO Object Detection Live Stream")
|
| 10 |
|
| 11 |
-
# Open Webcam
|
| 12 |
-
cap = cv2.VideoCapture(0)
|
| 13 |
-
if not cap.isOpened():
|
| 14 |
-
st.error("Error: Could not access the webcam.")
|
| 15 |
-
st.stop()
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
| 26 |
-
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 27 |
-
|
| 28 |
-
# Run YOLO object detection
|
| 29 |
-
results = model(frame)
|
| 30 |
-
img_pot = result[0].plot()
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
# Show processed frame in Streamlit
|
| 35 |
-
stframe.image(img_pot, channels="RGB")
|
| 36 |
-
|
| 37 |
-
# Release webcam
|
| 38 |
-
cap.release()
|
|
|
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
from ultralytics import YOLO
|
| 5 |
+
from camera_input_live import camera_input_live
|
| 6 |
|
| 7 |
# Load YOLO model (Download "yolov8n.pt" first if not available)
|
| 8 |
model = YOLO("yolov8n.pt")
|
| 9 |
|
| 10 |
st.title("🎥 YOLO Object Detection Live Stream")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
image = camera_input_live()
|
| 14 |
|
| 15 |
+
uploaded_image = PIL.Image.open(image)
|
| 16 |
+
uploaded_image_cv = cv2.cvtColor(numpy.array(uploaded_image), cv2.COLOR_RGB2BGR)
|
| 17 |
+
visualized_image = utils.predict_image(uploaded_image_cv, conf_threshold)
|
| 18 |
+
results = model(frame)
|
| 19 |
+
img_plot = result[0].plot()
|
| 20 |
|
| 21 |
+
st.image(img_plot, channels = "BGR")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|