-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface_decor.py
executable file
·38 lines (34 loc) · 1.33 KB
/
face_decor.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
#!/usr/bin/env python3
import cv2
import numpy as np
import face_recognition as fr
webcam=cv2.VideoCapture(0)
k=2
def do_decor(frame):
small_frame=cv2.resize(frame,(0,0),fx=1/k,fy=1/k)
frame_rgb=small_frame[:,:,::-1]
all_face_landmarks=fr.face_landmarks(frame_rgb)
for face_landmarks in all_face_landmarks:
eyebrow_l=np.array(face_landmarks["left_eyebrow"],np.int32)
eyebrow_r=np.array(face_landmarks["right_eyebrow"],np.int32)
nose_tip=np.array(face_landmarks["nose_tip"],np.int32)
nose_bridge=np.array(face_landmarks["nose_bridge"],np.int32)
nose=np.array([nose_bridge[0],nose_tip[0],nose_tip[-1]])
top_lip=np.array(face_landmarks["top_lip"],np.int32)
bottom_lip=np.array(face_landmarks["bottom_lip"],np.int32)
frame=cv2.fillPoly(frame,[k*eyebrow_l,k*eyebrow_r],(0xFF,0xFF,0xFF))
#frame=cv2.fillPoly(frame,[k*nose],(0,0x80,0xFF))
mouth_color=(0x3E,0x51,0xFC)
#frame=cv2.fillPoly(frame,[k*bottom_lip],mouth_color)
#frame=cv2.fillPoly(frame,[k*top_lip],mouth_color)
return frame
while webcam.isOpened():
ret,frame=webcam.read()
if ret==False:
break
frame=cv2.flip(frame,1)
frame=do_decor(frame)
cv2.imshow("Yourself with decorations",frame)
if cv2.waitKey(1) & 0xFF==ord('q'):
break
webcam.release()