Spaces:
Sleeping
Sleeping
File size: 1,223 Bytes
dea614a 5a745f9 d97bd9d dea614a aa7ee12 dea614a 5a745f9 aa7ee12 5a745f9 e47ba72 dea614a e2846a4 aa7ee12 dea614a e2846a4 e47ba72 dea614a |
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 29 30 |
import gradio as gr
import numpy as np
import cv2
from PIL import Image
def detect_faces(image , slider ) :
# detect faces
# convert image in to numpy array
image_np = np.array(image)
# convert image into gray
gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
# use detectmultiscale function to detect faces using haar cascade
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
faces = face_cascade.detectMultiScale(gray_image, scaleFactor=slider, minNeighbors=5, minSize=(30, 30))
# draw rectangle along detected faces
for (x, y, w, h) in faces:
cv2.rectangle(image_np, (x, y), (x+w, y+h), (255, 0, 0), 5)
return image_np , len(faces)
# slider = gr.Slider(minimum=1, maximum=2, step=.1, label="Adjust the ScaleFactor")
iface = gr.Interface( fn=detect_faces,
inputs=["image",gr.Slider(minimum=1, maximum=2, step=.1, label="Adjust the ScaleFactor")],
outputs=["image", gr.Label("faces count ")] ,
title="Face Detection using Haar Cascade Classifier ",
description="Upload an image,and the model will detect faces and draw bounding boxes around them.",
)
iface.launch() |