Face-Detection / app.py
sdafd's picture
Update app.py
4df9103
raw
history blame
905 Bytes
import gradio as gr
from mtcnn.mtcnn import MTCNN
import cv2
import numpy as np
# Function to detect faces using MTCNN
def detect_faces(image):
# Convert image to RGB format
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Detect faces using MTCNN
detector = MTCNN()
faces = detector.detect_faces(image_rgb)
# Draw bounding boxes around detected faces
for face in faces:
x, y, width, height = face['box']
cv2.rectangle(image, (x, y), (x + width, y + height), (255, 0, 0), 2)
return image
# Gradio Interface
iface = gr.Interface(
fn=detect_faces,
inputs=gr.Image(type="numpy", label="Input Image"),
outputs=gr.Image(type="numpy", label="Output Image"),
live=True,
interpretation="default",
title="MTCNN Face Detection",
description="Detect faces in an image using MTCNN.",
)
# Launch the Gradio Interface
iface.launch()