Spaces:
Build error
Build error
| import cv2 | |
| import streamlit as st | |
| import time | |
| from streamlit_webrtc import webrtc_streamer, WebRtcMode, RTCConfiguration | |
| RTC_CONFIGURATION = RTCConfiguration( | |
| {"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]} | |
| ) | |
| webrtc_ctx = webrtc_streamer( | |
| key="WYH", | |
| mode=WebRtcMode.SENDRECV, | |
| rtc_configuration=RTC_CONFIGURATION, | |
| media_stream_constraints={"video": True, "audio": False}, | |
| async_processing=False, | |
| ) | |
| st.title("webcam live feed") | |
| run = st.toggle('Start Webcam') | |
| FRAME_WINDOW = st.image([]) | |
| camera = cv2.VideoCapture(0) | |
| time.sleep(2) | |
| if not camera.isOpened(): | |
| print("Cannot open camera") | |
| exit() | |
| while run: | |
| _, frame = camera.read() | |
| if not _: | |
| print("Can't receive frame (steam end?).Exiting ...") | |
| break | |
| else: | |
| #cc = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
| FRAME_WINDOW.image(frame, channels = "BGR") | |
| else: | |
| st.write('Stopped') | |