-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrenderFace.py
31 lines (26 loc) · 1.25 KB
/
renderFace.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
import cv2
import numpy as np
def drawPolyline(im, landmarks, start, end, isClosed=False):
points = []
for i in range(start, end+1):
point = [landmarks.part(i).x, landmarks.part(i).y]
points.append(point)
points = np.array(points, dtype=np.int32)
cv2.polylines(im, [points], isClosed, (255, 200, 0), thickness=1, lineType=cv2.LINE_8)
# Use this function for 70-points facial landmark detector model
def renderFace(im, landmarks):
assert(landmarks.num_parts == 68)
drawPolyline(im, landmarks, 0, 16) # Jaw line
drawPolyline(im, landmarks, 17, 21) # Left eyebrow
drawPolyline(im, landmarks, 22, 26) # Right eyebrow
drawPolyline(im, landmarks, 27, 30) # Nose bridge
drawPolyline(im, landmarks, 30, 35, True) # Lower nose
drawPolyline(im, landmarks, 36, 41, True) # Left eye
drawPolyline(im, landmarks, 42, 47, True) # Right Eye
drawPolyline(im, landmarks, 48, 59, True) # Outer lip
drawPolyline(im, landmarks, 60, 67, True) # Inner lip
# Use this function for any model other than
# 70 points facial_landmark detector model
def renderFace2(im, landmarks, color=(0, 0, 255), radius=1):
for p in landmarks.parts():
cv2.circle(im, (p.x, p.y), radius, color, -1)