Raumkommander2 commited on
Commit
0cafcbd
·
1 Parent(s): b5a56e1

1st commit

Browse files
Files changed (1) hide show
  1. app.py +35 -2
app.py CHANGED
@@ -1,4 +1,37 @@
 
1
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
1
+ import cv2
2
  import streamlit as st
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ st.title("Live Webcam Stream - Original and Flipped")
7
+
8
+ # Start webcam capture
9
+ cap = cv2.VideoCapture(0)
10
+ original_placeholder = st.empty()
11
+ flipped_placeholder = st.empty()
12
+
13
+ while True:
14
+ success, frame = cap.read()
15
+ if not success:
16
+ st.error("Failed to capture image")
17
+ break
18
+
19
+ # Convert original frame to RGB format
20
+ original_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
21
+ original_img = Image.fromarray(original_frame)
22
+
23
+ # Flip the frame horizontally
24
+ flipped_frame = cv2.flip(original_frame, 1)
25
+ flipped_img = Image.fromarray(flipped_frame)
26
+
27
+ # Display both original and flipped frames
28
+ original_placeholder.image(original_img, caption="Original Video Stream", use_column_width=True)
29
+ flipped_placeholder.image(flipped_img, caption="Flipped Video Stream", use_column_width=True)
30
+
31
+ # Stop streaming if the user presses stop
32
+ if st.button("Stop Streaming"):
33
+ break
34
+
35
+ cap.release()
36
+ st.write("Stream stopped.")
37