Spaces:
Sleeping
Sleeping
Commit
·
1bef287
1
Parent(s):
af0419b
Create main.py
Browse files
main.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install gradio
|
2 |
+
|
3 |
+
import cv2
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
|
7 |
+
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
|
8 |
+
|
9 |
+
def detect_faces(frame):
|
10 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
11 |
+
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
12 |
+
print(f"Detected {len(faces)} faces")
|
13 |
+
return len(faces)
|
14 |
+
|
15 |
+
import gradio as gr
|
16 |
+
|
17 |
+
camera = cv2.VideoCapture(0)
|
18 |
+
|
19 |
+
def detect_faces_in_video():
|
20 |
+
success, frame = camera.read()
|
21 |
+
if success:
|
22 |
+
num_faces = detect_faces(frame)
|
23 |
+
return int(num_faces)
|
24 |
+
else:
|
25 |
+
return None
|
26 |
+
|
27 |
+
iface = gr.Interface(fn=detect_faces_in_video, inputs=None, outputs="number", title="Webcam Face Detection")
|
28 |
+
iface.launch()
|