Spaces:
Sleeping
Sleeping
File size: 881 Bytes
f129397 f96b4e6 f129397 b6d0899 f96b4e6 f129397 f96b4e6 f129397 f96b4e6 f129397 |
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 |
import numpy as np
import cv2
import gradio as gr
def detect_faces(image_file):
image_np = cv2.imread(image_file.name)
gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(10, 10))
if len(faces) > 0:
print("Face detected!")
else:
print("No faces detected.")
for (x, y, w, h) in faces:
cv2.rectangle(image_np, (x, y), (x+w, y+h), (0, 255, 0), 2)
return image_np
interface = gr.Interface(
fn=detect_faces,
inputs="file",
outputs="image",
title="Face Detection with Haar Cascade",
description="Upload an image file, and the model will detect faces and draw bounding boxes around them.",
)
interface.launch() |