Spaces:
Sleeping
Sleeping
File size: 668 Bytes
c2a08d9 1bef287 73d4a55 1bef287 |
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 |
import cv2
import gradio as gr
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
def detect_faces(frame):
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
print(f"Detected {len(faces)} faces")
return len(faces)
import gradio as gr
camera = cv2.VideoCapture(0)
def detect_faces_in_video():
success, frame = camera.read()
if success:
num_faces = detect_faces(frame)
return int(num_faces)
else:
return None
iface = gr.Interface(fn=detect_faces_in_video, inputs="webcam", outputs="number", title="Webcam Face Detection")
iface.launch() |