Spaces:
Runtime error
Runtime error
sagemaker
commited on
Commit
·
5c62f32
1
Parent(s):
d4c5491
init
Browse files- app.py +65 -0
- data/12_Group_Group_12_Group_Group_12_39.jpg +0 -0
- data/31_Waiter_Waitress_Waiter_Waitress_31_55.jpg +0 -0
- data/9_Press_Conference_Press_Conference_9_86.jpg +0 -0
- example.png +0 -0
- haar_cascades/haarcascade_eye.xml +0 -0
- haar_cascades/haarcascade_frontalface_default.xml +0 -0
- haar_cascades/haarcascade_smile.xml +0 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import imutils
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
face_detector = cv2.CascadeClassifier("haar_cascades/haarcascade_frontalface_default.xml")
|
7 |
+
|
8 |
+
def detect_faces(img, size, neighbours, scale):
|
9 |
+
frame = np.array(img)
|
10 |
+
frame = frame[:, :, ::-1].copy()
|
11 |
+
frame = imutils.resize(frame, width=500)
|
12 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
13 |
+
|
14 |
+
faceRects = face_detector.detectMultiScale(
|
15 |
+
gray, scaleFactor=scale, minNeighbors=neighbours, minSize=(size, size),
|
16 |
+
flags=cv2.CASCADE_SCALE_IMAGE)
|
17 |
+
|
18 |
+
box_data = []
|
19 |
+
|
20 |
+
class_labels = {
|
21 |
+
0: "face"
|
22 |
+
}
|
23 |
+
|
24 |
+
for (x,y,w,h) in faceRects:
|
25 |
+
frame = cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
|
26 |
+
|
27 |
+
midX = int(x+w/2)
|
28 |
+
midY = int(y+h/2)
|
29 |
+
box = {
|
30 |
+
"position": {
|
31 |
+
"middle": [midX, midY],
|
32 |
+
"width": float(w),
|
33 |
+
"height": float(h)
|
34 |
+
},
|
35 |
+
"domain" : "pixel",
|
36 |
+
"class_id" : 0
|
37 |
+
}
|
38 |
+
box_data.append(box)
|
39 |
+
|
40 |
+
predictions = {"predictions": {
|
41 |
+
"box_data": box_data,
|
42 |
+
"class_labels": class_labels
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
re_im =cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
47 |
+
return re_im
|
48 |
+
|
49 |
+
image = gr.components.Image()
|
50 |
+
out_im = gr.components.Image()
|
51 |
+
|
52 |
+
size_slider = gr.components.Slider(minimum=5, maximum=50, value=30, step=5, label="MinSize in Pixel")
|
53 |
+
neighbour_slider = gr.components.Slider(minimum=1, maximum=20, value=5, step=1, label="Min Number of Neighbours")
|
54 |
+
scale_slider = gr.components.Slider(minimum=1.1, maximum=2.0, value=1.3, step=0.1, label="Scale Factor")
|
55 |
+
|
56 |
+
description = """Face Detection with Haar Cascades using OpenCV"""
|
57 |
+
|
58 |
+
|
59 |
+
Iface = gr.Interface(
|
60 |
+
fn=detect_faces,
|
61 |
+
inputs=[image, size_slider, neighbour_slider, scale_slider],
|
62 |
+
outputs=out_im,
|
63 |
+
examples=[["data/9_Press_Conference_Press_Conference_9_86.jpg"], ["data/12_Group_Group_12_Group_Group_12_39.jpg"], ["data/31_Waiter_Waitress_Waiter_Waitress_31_55.jpg"]],
|
64 |
+
title="Haar Cascade Object Detection",
|
65 |
+
).launch()
|
data/12_Group_Group_12_Group_Group_12_39.jpg
ADDED
![]() |
data/31_Waiter_Waitress_Waiter_Waitress_31_55.jpg
ADDED
![]() |
data/9_Press_Conference_Press_Conference_9_86.jpg
ADDED
![]() |
example.png
ADDED
![]() |
haar_cascades/haarcascade_eye.xml
ADDED
The diff for this file is too large to render.
See raw diff
|
|
haar_cascades/haarcascade_frontalface_default.xml
ADDED
The diff for this file is too large to render.
See raw diff
|
|
haar_cascades/haarcascade_smile.xml
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
opencv-python
|
2 |
+
imutils
|