Raumkommander commited on
Commit
0597779
·
verified ·
1 Parent(s): 6bda89e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -5,13 +5,18 @@ from PIL import Image
5
 
6
  st.title("Live Webcam Stream - Original and Flipped")
7
 
8
- # Start webcam capture
9
- cap = cv2.VideoCapture(0)
10
- print(cap)
11
- # Check if the webcam is opened successfully
12
  if not cap.isOpened():
13
- st.error("Failed to access the webcam. Please check your device.")
14
- else:
 
 
 
 
 
 
 
15
  # Create two columns to display the original and flipped video streams
16
  col1, col2 = st.columns(2)
17
  original_placeholder = col1.empty()
@@ -31,10 +36,9 @@ else:
31
  # Display both original and flipped frames in their respective columns
32
  original_placeholder.image(original_img, caption="Original Video Stream", use_column_width=True)
33
  flipped_placeholder.image(flipped_img, caption="Flipped Video Stream", use_column_width=True)
34
-
35
  # Stop streaming if the user presses the button
36
  stop_button = st.button("Stop Streaming")
37
  if stop_button:
38
  cap.release()
39
  st.write("Stream stopped.")
40
-
 
5
 
6
  st.title("Live Webcam Stream - Original and Flipped")
7
 
8
+ # Try accessing the webcam (with different indexes)
9
+ cap = cv2.VideoCapture(0) # First try index 0
 
 
10
  if not cap.isOpened():
11
+ st.warning("Webcam not found. Trying with index 1.")
12
+ cap = cv2.VideoCapture(1) # Try index 1 if index 0 fails
13
+ if not cap.isOpened():
14
+ st.error("Failed to access the webcam. Please check your device or permissions.")
15
+ else:
16
+ st.write("Webcam accessed using index 1.")
17
+
18
+ # If camera is available, proceed with the processing
19
+ if cap.isOpened():
20
  # Create two columns to display the original and flipped video streams
21
  col1, col2 = st.columns(2)
22
  original_placeholder = col1.empty()
 
36
  # Display both original and flipped frames in their respective columns
37
  original_placeholder.image(original_img, caption="Original Video Stream", use_column_width=True)
38
  flipped_placeholder.image(flipped_img, caption="Flipped Video Stream", use_column_width=True)
39
+
40
  # Stop streaming if the user presses the button
41
  stop_button = st.button("Stop Streaming")
42
  if stop_button:
43
  cap.release()
44
  st.write("Stream stopped.")