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
| def Face_landmarks(image_path):
print("[INFO] loading facial landmark predictor...")
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
image = cv2.imread(image_path)
size = image.shape
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
rects = detector(gray, 0)
if len(rects) > 2:
print("[ERR] too many faces fount...")
# print("[Error] {} faces found...".format(len(rect)))
sys.exit(1)
if len(rects) < 1:
print("[ERR] face not found...")
# print("[Error] face not found...".format(len(rect))
sys.exit(1)
for rect in rects:
(bX, bY, bW, bH) = face_utils.rect_to_bb(rect)
print("[INFO] face frame {}".format(bX, bY, bW, bH))
shape = predictor(gray, rect)
shape = face_utils.shape_to_np(shape)
points = shape.tolist()
# (0,0),(x,0),(0,y),(x,y)
points.append([0, 0])
points.append([int(size[1]-1), 0])
points.append([0, int(size[0]-1)])
points.append([int(size[1]-1), int(size[0]-1)])
# (x/2,0),(0,y/2),(x/2,y),(x,y/2)
points.append([int(size[1]/2), 0])
points.append([0, int(size[0]/2)])
points.append([int(size[1]/2), int(size[0]-1)])
points.append([int(size[1]-1), int(size[0]/2)])
cv2.destroyAllWindows()
return points
|