File size: 924 Bytes
febf97f
 
47a0b3b
c46e0ec
 
 
 
 
 
 
 
 
 
 
 
 
febf97f
 
47a0b3b
febf97f
 
47a0b3b
 
 
 
 
febf97f
 
 
47a0b3b
 
 
 
a78c7ed
 
febf97f
a78c7ed
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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')