File size: 1,079 Bytes
305bca8
 
 
 
 
 
 
 
3f8f22d
305bca8
 
 
 
 
 
 
 
 
 
66caf4b
7f11d39
305bca8
 
 
 
7f11d39
a6d6b8f
305bca8
 
 
 
 
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
31
32
33
import numpy as np
import cv2
import gradio as gr

# Load Haar Cascade classifier
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")

# Face Detection Function
def detect_faces(image_np,slider):
    # Convert image to grayscale
    gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)

    # Detect faces
    faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))

    # Draw rectangles around faces
    for (x, y, w, h) in faces:
        cv2.rectangle(image_np, (x, y), (x + w, y + h), (0, 255, 0), 2)

    return image_np,len(faces)
# slider = gr.Slider(minimum=1, maximum=2, step=.1, label="Adjust the ScaleFactor")

# Create Gradio Interface
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",
    description="Upload an image, and the model will detect faces and draw bounding boxes around them."
)

iface.launch()