AndrewLam489 commited on
Commit
b71952c
·
verified ·
1 Parent(s): 150a67b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -21
app.py CHANGED
@@ -1,24 +1,20 @@
1
  import streamlit as st
2
- import cv2
 
3
 
4
- def main():
5
- st.set_page_config(page_title="Streamlit WebCam App")
6
- st.title("Webcam Display Steamlit App")
7
- st.caption("Powered by OpenCV, Streamlit")
8
- cap = cv2.VideoCapture(0)
9
- frame_placeholder = st.empty()
10
- stop_button_pressed = st.button("Stop")
11
- while cap.isOpened() and not stop_button_pressed:
12
- ret, frame = cap.read()
13
- if not ret:
14
- st.write("Video Capture Ended")
15
- break
16
- frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
17
- frame_placeholder.image(frame,channels="RGB")
18
- if cv2.waitKey(1) & 0xFF == ord("q") or stop_button_pressed:
19
- break
20
- cap.release()
21
- cv2.destroyAllWindows()
22
 
23
- if __name__ == "__main__":
24
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from streamlit_webrtc import webrtc_streamer
3
+ import av
4
 
5
+ st.title("Webcam Display Streamlit App")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ # Define the callback for transforming frames (without applying any filters)
8
+ def transform(frame: av.VideoFrame):
9
+ img = frame.to_ndarray(format="bgr24") # Convert to NumPy array (BGR format)
10
+
11
+ # Simply return the image without applying any filters
12
+ return av.VideoFrame.from_ndarray(img, format="bgr24")
13
+
14
+ # Display the video stream
15
+ webrtc_streamer(
16
+ key="streamer",
17
+ video_frame_callback=transform, # The transform function is only used to process frames
18
+ sendback_audio=False, # We don't need audio in this case
19
+ mode="SENDRECV", # Bidirectional mode to send and receive video
20
+ )