Raumkommander commited on
Commit
df11c7f
·
verified ·
1 Parent(s): 0a5f939

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -12
app.py CHANGED
@@ -1,26 +1,41 @@
1
  import streamlit as st
 
2
  import av
3
- from streamlit_webrtc import webrtc_streamer, VideoProcessorBase
4
 
5
- # Video Processor Class for Rotation
6
- class RotatedVideoProcessor(VideoProcessorBase):
7
- def recv(self, frame):
8
- img = frame.to_ndarray(format="bgr24") # Convert frame to NumPy array
9
- rotated_img = av.VideoFrame.from_ndarray(img[::-1], format="bgr24") # Rotate 180 degrees
10
- return rotated_img # Return the rotated frame
11
 
12
  # Streamlit UI
13
  st.title("Live Webcam Streaming with Rotation")
14
 
15
- # Text Input Field
16
  user_input = st.text_input("Enter some text:")
17
  if st.button("Confirm"):
18
  st.write(f"You entered: {user_input}")
19
 
20
- # Original Stream
 
 
 
 
 
21
  st.subheader("Original Video Stream")
22
- webrtc_streamer(key="original", media_stream_constraints={"video": True, "audio": False})
 
 
 
 
23
 
24
- # Rotated Stream
25
  st.subheader("Rotated Video Stream")
26
- webrtc_streamer(key="rotated", video_processor_factory=RotatedVideoProcessor, media_stream_constraints={"video": True, "audio": False})
 
 
 
 
 
 
1
  import streamlit as st
2
+ from streamlit_webrtc import webrtc_streamer, VideoTransformerBase
3
  import av
4
+ import cv2
5
 
6
+ # Video Transformer Class for Rotating Stream
7
+ class RotatedVideoTransformer(VideoTransformerBase):
8
+ def transform(self, frame):
9
+ img = frame.to_ndarray(format="bgr24")
10
+ rotated_img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE) # Rotate 90 degrees
11
+ return av.VideoFrame.from_ndarray(rotated_img, format="bgr24")
12
 
13
  # Streamlit UI
14
  st.title("Live Webcam Streaming with Rotation")
15
 
16
+ # Text Input and Confirm Button
17
  user_input = st.text_input("Enter some text:")
18
  if st.button("Confirm"):
19
  st.write(f"You entered: {user_input}")
20
 
21
+ # WebRTC Connection Config with STUN Server
22
+ rtc_configuration = {
23
+ "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
24
+ }
25
+
26
+ # Original Webcam Stream
27
  st.subheader("Original Video Stream")
28
+ webrtc_streamer(
29
+ key="original",
30
+ media_stream_constraints={"video": True, "audio": False},
31
+ rtc_configuration=rtc_configuration, # Add STUN server
32
+ )
33
 
34
+ # Rotated Webcam Stream
35
  st.subheader("Rotated Video Stream")
36
+ webrtc_streamer(
37
+ key="rotated",
38
+ video_transformer_factory=RotatedVideoTransformer,
39
+ media_stream_constraints={"video": True, "audio": False},
40
+ rtc_configuration=rtc_configuration, # Add STUN server
41
+ )