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) original_placeholder = st.empty() flipped_placeholder = st.empty() 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 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 stop if st.button("Stop Streaming"): break cap.release() st.write("Stream stopped.")