Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,18 @@
|
|
1 |
-
from streamlit_webrtc import webrtc_streamer
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from streamlit_webrtc import webrtc_streamer, RTCConfiguration
|
2 |
+
import av
|
3 |
+
import cv2
|
4 |
|
5 |
+
cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
|
6 |
+
|
7 |
+
class VideoProcessor:
|
8 |
+
def recv(self, frame):
|
9 |
+
frm = frame.to_ndarray(format="bgr24")
|
10 |
+
|
11 |
+
faces = cascade.detectMultiScale(cv2.cvtColor(frm, cv2.COLOR_BGR2GRAY), 1.1, 3)
|
12 |
+
|
13 |
+
for x,y,w,h in faces:
|
14 |
+
cv2.rectangle(frm, (x,y), (x+w, y+h), (0,255,0), 3)
|
15 |
+
|
16 |
+
return av.VideoFrame.from_ndarray(frm, format='bgr24')
|
17 |
+
|
18 |
+
webrtc_streamer(key="key", video_processor_factory=VideoProcessor,rtc_configuration= RTCConfiguration{"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]}) )
|