Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from mtcnn.mtcnn import MTCNN
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
|
| 6 |
# Function to detect faces using MTCNN
|
| 7 |
def detect_faces(image):
|
|
@@ -12,12 +13,15 @@ def detect_faces(image):
|
|
| 12 |
detector = MTCNN()
|
| 13 |
faces = detector.detect_faces(image_rgb)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
# Draw bounding boxes around detected faces
|
| 16 |
for face in faces:
|
| 17 |
x, y, width, height = face['box']
|
| 18 |
cv2.rectangle(image, (x, y), (x + width, y + height), (255, 0, 0), 2)
|
| 19 |
|
| 20 |
-
return image,
|
| 21 |
|
| 22 |
# Gradio Interface
|
| 23 |
iface = gr.Interface(
|
|
|
|
| 2 |
from mtcnn.mtcnn import MTCNN
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
# Function to detect faces using MTCNN
|
| 8 |
def detect_faces(image):
|
|
|
|
| 13 |
detector = MTCNN()
|
| 14 |
faces = detector.detect_faces(image_rgb)
|
| 15 |
|
| 16 |
+
# Extract and format face information
|
| 17 |
+
formatted_faces = [{"x": face['box'][0], "y": face['box'][1], "width": face['box'][2], "height": face['box'][3]} for face in faces]
|
| 18 |
+
|
| 19 |
# Draw bounding boxes around detected faces
|
| 20 |
for face in faces:
|
| 21 |
x, y, width, height = face['box']
|
| 22 |
cv2.rectangle(image, (x, y), (x + width, y + height), (255, 0, 0), 2)
|
| 23 |
|
| 24 |
+
return image, json.dumps(formatted_faces)
|
| 25 |
|
| 26 |
# Gradio Interface
|
| 27 |
iface = gr.Interface(
|