Raumkommander commited on
Commit
9fdee07
·
verified ·
1 Parent(s): dbd9537

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -1,20 +1,26 @@
1
  import streamlit as st
2
- import cv2
3
- import numpy as np
4
- from streamlit_webrtc import webrtc_streamer, VideoTransformerBase
5
 
6
- class RotatedVideoTransformer(VideoTransformerBase):
7
- def transform(self, frame):
 
8
  img = frame.to_ndarray(format="bgr24") # Convert frame to NumPy array
9
- rotated_img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE) # Rotate 90 degrees
10
  return rotated_img # Return the rotated frame
11
 
 
12
  st.title("Live Webcam Streaming with Rotation")
13
 
 
 
 
 
 
14
  # Original Stream
15
  st.subheader("Original Video Stream")
16
- webrtc_streamer(key="original")
17
 
18
  # Rotated Stream
19
  st.subheader("Rotated Video Stream")
20
- webrtc_streamer(key="rotated", video_transformer_factory=RotatedVideoTransformer)
 
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})