def align_face_to_template(img, facial_landmarks, output_dim, landmarkIndices=INNER_EYES_AND_BOTTOM_LIP):
"""
Aligns image by warping it to fit the landmarks on
the image (src) to the landmarks on the template (dst)
Args:
img: src image to be aligned
facial_landmarks: list of 68 landmarks (obtained from dlib)
output_dim: image output dimension
"""
np_landmarks = np.float32(facial_landmarks)
np_landmarks_idx = np.array(landmarkIndices)
H = cv2.getAffineTransform(np_landmarks[np_landmarks_idx],
output_dim * SCALED_LANDMARKS[np_landmarks_idx])
warped = cv2.warpAffine(img, H, (output_dim, output_dim))
return warped
评论列表
文章目录