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.")