-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpoly_points_face_points_video.py
109 lines (93 loc) · 2.53 KB
/
poly_points_face_points_video.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import cv2
import numpy as np
import dlib
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
cap = cv2.VideoCapture(0)
while True:
_, img = cap.read()
gray = cv2.cvtColor(src=img, code=cv2.COLOR_BGR2GRAY)
faces = detector(gray)
for face in faces:
x1 = face.left()
y1 = face.top()
x2 = face.right()
y2 = face.bottom()
landmarks = predictor(image = gray, box=face)
# Jaw Points 0-16
doc = []
for n in range(0,17):
x = landmarks.part(n).x
y = landmarks.part(n).y
doc.append([x,y])
pts = np.array(doc).astype(np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img, [pts], False, (0,255,255))
# Right Brow Points 17-21
doc = []
for n in range(17,22):
x = landmarks.part(n).x
y = landmarks.part(n).y
doc.append([x,y])
pts = np.array(doc).astype(np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img, [pts], False, (0,255,255))
#Left Brow Points 22-26
doc = []
for n in range(22,27):
x = landmarks.part(n).x
y = landmarks.part(n).y
doc.append([x,y])
pts = np.array(doc).astype(np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img, [pts], False, (0,255,255))
#Nose Points 27-35
doc = []
for n in range(27,36):
x = landmarks.part(n).x
y = landmarks.part(n).y
doc.append([x,y])
pts = np.array(doc).astype(np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img, [pts], False, (0,255,255))
#Right Eye 36-41
doc = []
for n in range(36,42):
x = landmarks.part(n).x
y = landmarks.part(n).y
doc.append([x,y])
pts = np.array(doc).astype(np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img, [pts], False, (0,255,255))
#Left Eye 42-47
doc = []
for n in range(42,48):
x = landmarks.part(n).x
y = landmarks.part(n).y
doc.append([x,y])
pts = np.array(doc).astype(np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img, [pts], False, (0,255,255))
#Mouth Points 48-60
doc = []
for n in range(48,61):
x = landmarks.part(n).x
y = landmarks.part(n).y
doc.append([x,y])
pts = np.array(doc).astype(np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img, [pts], False, (0,255,255))
#Lips Points 61-67
doc = []
for n in range(61,68):
x = landmarks.part(n).x
y = landmarks.part(n).y
doc.append([x,y])
pts = np.array(doc).astype(np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img, [pts], False, (0,255,255))
cv2.imshow(winname="Face", mat=img)
if cv2.waitKey(delay=1) == 27:
break
cap.release()
cv2.destroyAllWindows()