-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdetectors.py
36 lines (27 loc) · 892 Bytes
/
detectors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
:/helper class
"""
import cv2
class FaceDetector(object):
def __init__(self):
self.classifier = cv2.CascadeClassifier('/home/parth/Desktop/internal/xml/frontal_face.xml')
def detect(self, image, biggest_only=True):
is_color = len(image) == 3
if is_color:
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
else:
image_gray = image
scale_factor = 1.2
min_neighbors = 5
min_size = (30, 30)
flags = cv2.CASCADE_FIND_BIGGEST_OBJECT | \
cv2.CASCADE_DO_ROUGH_SEARCH if biggest_only else \
cv2.CASCADE_SCALE_IMAGE
face_coord = self.classifier.detectMultiScale(
image_gray,
scaleFactor=scale_factor,
minNeighbors=min_neighbors,
minSize=min_size,
flags=flags
)
return face_coord