-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathface_features.py
More file actions
46 lines (40 loc) · 1.17 KB
/
Copy pathface_features.py
File metadata and controls
46 lines (40 loc) · 1.17 KB
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
37
38
39
40
41
42
43
44
45
46
# coding=utf-8
"""
light 人脸特征检测
"""
import dlib
import cv2
import settings
from face_detector import FaceDetector
class FaceFeatures(FaceDetector):
def __init__(self, ):
super().__init__()
self.marks_detector = dlib.shape_predictor(settings.shape_predictor_68_face_landmarks)
def detect_features(self, rect):
"""
:param rect: must bu dlib.rect object, not 2d tuple
:return:
"""
features = self.marks_detector(self.img, rect)
return features
def get_marks(self, rect):
"""
:param rect: must have method: left, top, right, bottom
:return: marks: list, contains face features' position like (x, y)
"""
features = self.detect_features(rect)
marks = []
for index, pt in enumerate(features.parts()):
pos = (pt.x, pt.y)
marks.append(pos)
return marks
if __name__ == '__main__':
f = FaceFeatures()
f.load_img('data/crowd/0001.jpg')
faces = f.detect_face()
for face in faces:
marks = f.get_marks(face['position'])
f.add_marks(marks)
f.add_faces(faces)
f.show()
cv2.waitKey(0)