def alignment(self, img, landmark): tfm = get_similarity_transform_for_PIL(landmark, self.refLandmark.copy()) img = img.transform(self.cropSize, Image.AFFINE, tfm.reshape(6), resample=Image.BILINEAR) img = np.asarray(img) if len(img.shape) == 2: img = img[:, :, np.newaxis] img = np.concatenate([img, img, img], axis=2) else: img = img[:, :, ::-1] img = np.transpose(img, [2, 0, 1]) return img
def alignment(src_img, src_pts): ref_pts = [ [30.2946, 51.6963],[65.5318, 51.5014], [48.0252, 71.7366],[33.5493, 92.3655],[62.7299, 92.2041] ] crop_size = (96, 112) src_pts = np.array(src_pts).reshape(5,2) s = np.array(src_pts).astype(np.float32) r = np.array(ref_pts).astype(np.float32) tfm = get_similarity_transform_for_PIL(s, r) face_img = src_img.transform(crop_size, Image.AFFINE, tfm.reshape(6), resample=Image.BILINEAR) face_img = np.asarray(face_img )[:, :, ::-1] return face_img