Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,37 @@
|
|
1 |
import streamlit as st
|
2 |
import cv2
|
|
|
3 |
|
4 |
-
|
5 |
-
st.set_page_config(page_title="Streamlit WebCam App")
|
6 |
-
st.title("Webcam Display Steamlit App")
|
7 |
-
st.caption("Powered by OpenCV, Streamlit")
|
8 |
-
cap = cv2.VideoCapture(0)
|
9 |
-
frame_placeholder = st.empty()
|
10 |
-
stop_button_pressed = st.button("Stop")
|
11 |
-
while cap.isOpened() and not stop_button_pressed:
|
12 |
-
ret, frame = cap.read()
|
13 |
-
if not ret:
|
14 |
-
st.write("Video Capture Ended")
|
15 |
-
break
|
16 |
-
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
17 |
-
frame_placeholder.image(frame,channels="RGB")
|
18 |
-
if cv2.waitKey(1) & 0xFF == ord("q") or stop_button_pressed:
|
19 |
-
break
|
20 |
-
cap.release()
|
21 |
-
cv2.destroyAllWindows()
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import cv2
|
3 |
+
from ultralytics import YOLO
|
4 |
|
5 |
+
model = YOLO('best.pt')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def track(source):
|
8 |
+
result = model.track(source=source)
|
9 |
+
return result
|
10 |
+
|
11 |
+
st.set_page_config(page_title="Streamlit WebCam App")
|
12 |
+
st.title("Webcam Display Steamlit App")
|
13 |
+
cap = cv2.VideoCapture(0)
|
14 |
+
frame_placeholder = st.empty()
|
15 |
+
st_frame = st.empty()
|
16 |
+
stop_button_pressed = st.button("Stop")
|
17 |
+
while cap.isOpened() and not stop_button_pressed:
|
18 |
+
ret, frame = cap.read()
|
19 |
+
if not ret:
|
20 |
+
st.write("Video Capture Ended")
|
21 |
+
break
|
22 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
23 |
+
frame_placeholder.image(frame, channels="RGB")
|
24 |
+
|
25 |
+
resultado = track(frame)
|
26 |
+
res_plotted = resultado[0].plot()
|
27 |
+
|
28 |
+
st_frame.image(res_plotted,
|
29 |
+
caption='Detected Video',
|
30 |
+
channels="RGB",
|
31 |
+
#use_column_width=True
|
32 |
+
)
|
33 |
+
|
34 |
+
if cv2.waitKey(1) & 0xFF == ord("q") or stop_button_pressed:
|
35 |
+
break
|
36 |
+
cap.release()
|
37 |
+
cv2.destroyAllWindows()
|