Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
import av
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
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 |
-
# Streamlit buttons (optional, to stop the stream or interact further)
|
15 |
-
stop_button_pressed = st.button("Stop")
|
16 |
-
|
17 |
-
# Display the video stream
|
18 |
-
webrtc_streamer(
|
19 |
-
key="streamer",
|
20 |
-
video_frame_callback=transform, # The transform function is only used to process frames
|
21 |
-
sendback_audio=False, # We don't need audio in this case
|
22 |
-
mode=WebRtcMode.RECVONLY, # We are only receiving the video stream (not sending any video back)
|
23 |
-
)
|
24 |
-
|
25 |
-
# If you want a "Stop" button that halts the webcam stream, you can handle this through Streamlit
|
26 |
-
if stop_button_pressed:
|
27 |
-
st.write("Stream stopped.")
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|