File size: 1,061 Bytes
0cafcbd
b5a56e1
0cafcbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b5a56e1
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
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.")