Spaces:
Sleeping
Sleeping
File size: 1,246 Bytes
0cafcbd b5a56e1 0cafcbd c803588 0cafcbd c803588 0cafcbd c803588 0cafcbd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import cv2
import streamlit as st
import numpy as np
from PIL import Image
st.title("Live Webcam Stream - Original and Flipped")
# Start webcam capture
cap = cv2.VideoCapture(0)
# Create two columns to display the original and flipped video streams
col1, col2 = st.columns(2)
original_placeholder = col1.empty()
flipped_placeholder = col2.empty()
# Stream the video
while True:
success, frame = cap.read()
if not success:
st.error("Failed to capture image")
break
# Convert original frame to RGB format
original_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
original_img = Image.fromarray(original_frame)
# Flip the frame horizontally
flipped_frame = cv2.flip(original_frame, 1)
flipped_img = Image.fromarray(flipped_frame)
# Display both original and flipped frames in their respective columns
original_placeholder.image(original_img, caption="Original Video Stream", use_column_width=True)
flipped_placeholder.image(flipped_img, caption="Flipped Video Stream", use_column_width=True)
# Stop streaming if the user presses the button
stop_button = st.button("Stop Streaming")
if stop_button:
break
cap.release()
st.write("Stream stopped.")
|