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