FACEDETECTION / app.py
AIMLdeepanshu's picture
Create app.py
535a129 verified
raw
history blame contribute delete
827 Bytes
import cv2
import gradio as gr
import numpy as np
# Load Haar cascade
face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
def detect_faces(image, scale):
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
faces = face_cascade.detectMultiScale(gray, scale, 4)
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
return image
iface = gr.Interface(
fn=detect_faces,
inputs=[
gr.Image(type="numpy", label="Upload Image"),
gr.Slider(1.00, 2.00, value=1.1, step=0.01, label="Scale Factor"),
],
outputs=gr.Image(type="numpy", label="Detected Faces"),
title="Face Detection with Haar Cascade",
description="Adjust the scale factor using the slider to improve face detection accuracy or speed."
)
iface.launch()