-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (36 loc) · 1.26 KB
/
Copy pathapp.py
File metadata and controls
55 lines (36 loc) · 1.26 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import streamlit as st
import cv2
import tempfile
import os
from main import process_frame
st.set_page_config(page_title="PPE Detection System", layout="wide")
st.title("PPE Detection System")
st.sidebar.title("Options")
mode = st.sidebar.radio("Choose Input Source", ["Upload Video", "Use Camera"])
if mode == "Upload Video":
uploaded_file = st.file_uploader("Upload a video file", type=["mp4", "avi", "mov"])
if uploaded_file is not None:
tfile = tempfile.NamedTemporaryFile(delete=False)
tfile.write(uploaded_file.read())
tfile.close()
cap = cv2.VideoCapture(tfile.name)
stframe = st.empty()
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
processed_frame = process_frame(frame)
stframe.image(processed_frame, channels="BGR")
cap.release()
os.unlink(tfile.name)
elif mode == "Use Camera":
cap = cv2.VideoCapture(0)
stframe = st.empty()
stop = st.sidebar.button("Stop Camera")
while cap.isOpened():
ret, frame = cap.read()
if not ret or stop:
break
processed_frame = process_frame(frame)
stframe.image(processed_frame, channels="BGR")
cap.release()