Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,30 +3,28 @@ import cv2
|
|
| 3 |
import gradio as gr
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
-
|
| 7 |
# Load Haar Cascade classifier
|
| 8 |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
|
| 9 |
-
|
| 10 |
# Face Detection Function
|
| 11 |
-
def detect_faces(image_np):
|
| 12 |
-
img=np.array(gray_image)
|
| 13 |
# Convert image to grayscale
|
| 14 |
-
gray_image = cv2.cvtColor(
|
| 15 |
|
| 16 |
# Detect faces
|
| 17 |
-
faces = face_cascade.detectMultiScale(gray_image, scaleFactor=
|
| 18 |
|
| 19 |
# Draw rectangles around faces
|
| 20 |
for (x, y, w, h) in faces:
|
| 21 |
cv2.rectangle(image_np, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
| 22 |
|
| 23 |
-
return
|
| 24 |
|
| 25 |
# Create Gradio Interface
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=detect_faces,
|
| 28 |
-
inputs="image",
|
| 29 |
-
outputs="image",
|
| 30 |
title="Face Detection",
|
| 31 |
description="Upload an image, and the model will detect faces and draw bounding boxes around them."
|
| 32 |
)
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from PIL import Image
|
| 5 |
|
|
|
|
| 6 |
# Load Haar Cascade classifier
|
| 7 |
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
|
| 8 |
+
|
| 9 |
# Face Detection Function
|
| 10 |
+
def detect_faces(image_np,slider):
|
|
|
|
| 11 |
# Convert image to grayscale
|
| 12 |
+
gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
|
| 13 |
|
| 14 |
# Detect faces
|
| 15 |
+
faces = face_cascade.detectMultiScale(gray_image, scaleFactor=slider, minNeighbors=5, minSize=(30, 30))
|
| 16 |
|
| 17 |
# Draw rectangles around faces
|
| 18 |
for (x, y, w, h) in faces:
|
| 19 |
cv2.rectangle(image_np, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
| 20 |
|
| 21 |
+
return image_np, len(faces)
|
| 22 |
|
| 23 |
# Create Gradio Interface
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=detect_faces,
|
| 26 |
+
inputs=["image",gr.Slider(minimum=1,maximum=2,step=.1,label= "adjust the scaleFactor")],
|
| 27 |
+
outputs=["image",gr.Label("faces count")],
|
| 28 |
title="Face Detection",
|
| 29 |
description="Upload an image, and the model will detect faces and draw bounding boxes around them."
|
| 30 |
)
|