-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
32 lines (27 loc) · 870 Bytes
/
main.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
import cv2
import dlib
cap = cv2.VideoCapture(0)
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
def node():
_, frame = cap.read()
gray = cv2.cvtColor(src=frame, 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)
for n in range(0,68):
x = landmarks.part(n).x
y = landmarks.part(n).y
cv2.circle(img=frame, center=(x,y), radius=2, color=(0,255,0),thickness=-1)
cv2.imshow(winname="Cam",mat=frame)
while True:
node()
if cv2.waitKey(delay=1)== 27:
break
cap.release()
cv2.destroyAllWindows()
exit()