Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
import numpy as np
|
5 |
-
|
6 |
import cv2
|
7 |
-
|
8 |
from PIL import Image
|
9 |
|
10 |
-
|
11 |
-
|
12 |
def detect_faces(image , slider ) :
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
faces = face_cascade.detectMultiScale(gray_image, scaleFactor=slider, minNeighbors=5, minSize=(30, 30))
|
29 |
-
|
30 |
-
# draw rectangle along detected faces
|
31 |
-
|
32 |
-
for (x, y, w, h) in faces:
|
33 |
-
|
34 |
-
cv2.rectangle(image_np, (x, y), (x+w, y+h), (255, 0, 0), 5)
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
return image_np
|
39 |
|
|
|
40 |
|
41 |
-
|
42 |
-
slider = gr.Slider(minimum=1, maximum=2, step=.1, label="Adjust the ScaleFactor")
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
iface = gr.Interface( fn=detect_faces,
|
47 |
-
|
48 |
-
inputs=["image","slider"],
|
49 |
-
|
50 |
-
outputs="image",
|
51 |
-
|
52 |
-
title="Face Detection using Haar Cascade Classifier ",
|
53 |
-
|
54 |
-
description="Upload an image,and the model will detect faces and draw bounding boxes around them.",
|
55 |
-
|
56 |
-
)
|
57 |
-
|
58 |
-
|
59 |
|
60 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import numpy as np
|
|
|
3 |
import cv2
|
|
|
4 |
from PIL import Image
|
5 |
|
|
|
|
|
6 |
def detect_faces(image , slider ) :
|
7 |
+
# detect faces
|
8 |
+
|
9 |
+
# convert image in to numpy array
|
10 |
+
image_np = np.array(image)
|
11 |
+
|
12 |
+
# convert image into gray
|
13 |
+
gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
|
14 |
+
|
15 |
+
# use detectmultiscale function to detect faces using haar cascade
|
16 |
+
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
|
17 |
+
faces = face_cascade.detectMultiScale(gray_image, scaleFactor=slider, minNeighbors=5, minSize=(30, 30))
|
18 |
+
|
19 |
+
# draw rectangle along detected faces
|
20 |
+
for (x, y, w, h) in faces:
|
21 |
+
cv2.rectangle(image_np, (x, y), (x+w, y+h), (255, 0, 0), 5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
return image_np
|
23 |
|
24 |
+
slider = gr.Slider(1, 2, step=.1, label="Adjust the ScaleFactor", value=1.5)
|
25 |
|
26 |
+
iface = gr.Interface( fn=detect_faces,inputs=["image","slider"],outputs="image",title="Face Detection using Haar Cascade Classifier ",description="Upload an image,and the model will detect faces and draw bounding boxes around them.",)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
iface.launch()
|