gghsgn commited on
Commit
c791f53
·
verified ·
1 Parent(s): 6a01ab8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -84,21 +84,26 @@ if upload_option == "Image Upload":
84
 
85
  elif upload_option == "Webcam":
86
  st.sidebar.write("Webcam Capture")
87
- run = st.checkbox('Run Webcam')
 
88
  FRAME_WINDOW = st.image([])
89
 
90
- camera = cv2.VideoCapture(0)
91
-
92
- while run:
93
- success, frame = camera.read()
94
- if not success:
95
- st.error("Unable to read from webcam. Please check your camera settings.")
96
- break
97
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
98
- processed_frame = video_frame_callback(frame)
99
- FRAME_WINDOW.image(processed_frame)
100
-
101
- camera.release()
 
 
 
 
 
102
  else:
103
  st.write("Please select an option to start.")
104
-
 
84
 
85
  elif upload_option == "Webcam":
86
  st.sidebar.write("Webcam Capture")
87
+ run_webcam = st.sidebar.button('Run Webcam')
88
+ stop_webcam = st.sidebar.button('Stop Webcam')
89
  FRAME_WINDOW = st.image([])
90
 
91
+ if run_webcam:
92
+ camera = cv2.VideoCapture(0)
93
+ st.session_state['run'] = True
94
+
95
+ if 'run' in st.session_state and st.session_state['run']:
96
+ while True:
97
+ success, frame = camera.read()
98
+ if not success:
99
+ st.error("Unable to read from webcam. Please check your camera settings.")
100
+ break
101
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
102
+ processed_frame = video_frame_callback(frame)
103
+ FRAME_WINDOW.image(processed_frame)
104
+ if stop_webcam:
105
+ st.session_state['run'] = False
106
+ camera.release()
107
+ break
108
  else:
109
  st.write("Please select an option to start.")