N3tron commited on
Commit
c3953cb
·
verified ·
1 Parent(s): cb3b592

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -23
app.py CHANGED
@@ -132,29 +132,31 @@ def main():
132
  app = FaceAnalysis(name='buffalo_l')
133
  app.prepare(ctx_id=0, det_size=(640, 640))
134
 
135
- # Start capturing video from webcam
136
- cap = cv2.VideoCapture(0)
137
-
138
- # Process each frame in real-time
139
- while True:
140
- # Capture frame-by-frame
141
- ret, frame = cap.read()
142
- if not ret:
143
- break
144
-
145
- # Perform face recognition
146
- frame = recognize_faces(frame, names, embeddings, app)
147
-
148
- # Display the resulting frame
149
- st.image(frame, channels="BGR", use_column_width=True)
150
-
151
- # Break the loop if 'q' is pressed
152
- if cv2.waitKey(1) & 0xFF == ord('q'):
153
- break
154
-
155
- # Release the capture
156
- cap.release()
157
- cv2.destroyAllWindows()
 
 
158
 
159
 
160
 
 
132
  app = FaceAnalysis(name='buffalo_l')
133
  app.prepare(ctx_id=0, det_size=(640, 640))
134
 
135
+ # Display a button to start webcam
136
+ if st.button("Start Webcam"):
137
+ # Start capturing video from webcam
138
+ cap = cv2.VideoCapture(0)
139
+
140
+ # Process each frame in real-time
141
+ while True:
142
+ # Capture frame-by-frame
143
+ ret, frame = cap.read()
144
+ if not ret:
145
+ break
146
+
147
+ # Perform face recognition
148
+ frame = recognize_faces(frame, names, embeddings, app)
149
+
150
+ # Display the resulting frame
151
+ st.image(frame, channels="BGR", use_column_width=True)
152
+
153
+ # Break the loop if 'q' is pressed or the user closes the Streamlit app
154
+ if st.button("Stop"):
155
+ break
156
+
157
+ # Release the capture
158
+ cap.release()
159
+ cv2.destroyAllWindows()
160
 
161
 
162