SS8297 commited on
Commit
47a0b3b
·
1 Parent(s): 380e4d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -1,14 +1,24 @@
1
  import cv2
2
  import streamlit as st
 
3
 
4
  st.title("webcam live feed")
5
- run = st.checkbox('Run')
6
  FRAME_WINDOW = st.image([])
7
  camera = cv2.VideoCapture(0)
 
 
 
 
 
8
 
9
  while run:
10
  _, frame = camera.read()
11
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
12
- FRAME_WINDOW.image(frame)
 
 
 
 
13
  else:
14
  st.write('Stopped')
 
1
  import cv2
2
  import streamlit as st
3
+ import time
4
 
5
  st.title("webcam live feed")
6
+ run = st.toggle('Start Webcam')
7
  FRAME_WINDOW = st.image([])
8
  camera = cv2.VideoCapture(0)
9
+ time.sleep(2)
10
+
11
+ if not camera.isOpened():
12
+ print("Cannot open camera")
13
+ exit()
14
 
15
  while run:
16
  _, frame = camera.read()
17
+ if not _:
18
+ print("Can't receive frame (steam end?).Exiting ...")
19
+ break
20
+ else:
21
+ frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
22
+ FRAME_WINDOW.image(frame)
23
  else:
24
  st.write('Stopped')