Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,41 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import av
|
3 |
-
|
4 |
|
5 |
-
# Video
|
6 |
-
class
|
7 |
-
def
|
8 |
-
img = frame.to_ndarray(format="bgr24")
|
9 |
-
rotated_img =
|
10 |
-
return rotated_img
|
11 |
|
12 |
# Streamlit UI
|
13 |
st.title("Live Webcam Streaming with Rotation")
|
14 |
|
15 |
-
# Text Input
|
16 |
user_input = st.text_input("Enter some text:")
|
17 |
if st.button("Confirm"):
|
18 |
st.write(f"You entered: {user_input}")
|
19 |
|
20 |
-
#
|
|
|
|
|
|
|
|
|
|
|
21 |
st.subheader("Original Video Stream")
|
22 |
-
webrtc_streamer(
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
# Rotated Stream
|
25 |
st.subheader("Rotated Video Stream")
|
26 |
-
webrtc_streamer(
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
)
|