Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,34 +8,33 @@ st.title("Live Webcam Stream - Original and Flipped")
|
|
8 |
# Start webcam capture
|
9 |
cap = cv2.VideoCapture(0)
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
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 |
-
|
|
|
39 |
|
40 |
-
cap.release()
|
41 |
-
st.write("Stream stopped.")
|
|
|
8 |
# Start webcam capture
|
9 |
cap = cv2.VideoCapture(0)
|
10 |
|
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()
|
18 |
+
flipped_placeholder = col2.empty()
|
19 |
|
20 |
+
# Capture and display the webcam feed frame by frame
|
21 |
+
frame = cap.read()[1] # Capture the first frame
|
22 |
+
if frame is not None:
|
23 |
+
# Convert original frame to RGB format
|
24 |
+
original_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
25 |
+
original_img = Image.fromarray(original_frame)
|
26 |
+
|
27 |
+
# Flip the frame horizontally
|
28 |
+
flipped_frame = cv2.flip(original_frame, 1)
|
29 |
+
flipped_img = Image.fromarray(flipped_frame)
|
30 |
+
|
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 |
|
|
|
|