oliverlibaw's picture
Update app.py
73d4a55
raw
history blame contribute delete
668 Bytes
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()