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