【发布时间】:2017-08-13 22:38:31
【问题描述】:
在将我的脸输入神经网络之前,我正在尝试编写一个人脸对齐器作为预处理步骤。我通过dlib 的Vahid Kazemi and Josephine Sullivan's 回归树集合的实现找到了(使用Python)人脸的地标,以预测人脸地标估计。我尝试了多种不同类型的转换,但均无济于事。这是我的基本管道:
-
在图像中查找人脸并将图像裁剪为只有人脸:
image = <some_image_with_one_face> face_detector = dlib.get_frontal_face_detector() detected_face = face_detector(image) w,h = 160 # so that facenet can use it for face_rect in detected_face: # First crop the face left = face_rect.left() top = face_rect.top() right = face_rect.right() bottom = face_rect.bottom() new_face_rect = dlib.rectangle(0, 0, right-left, bottom-top) cropped_image = image[top:bottom, left:right, :].copy() # Get the the face's pose pose_landmarks = face_pose_predictor(cropped_image, new_face_rect)` -
查找地标(
get_landmark_points返回一个68x2数组landmarks = get_landmark_points(pose_landmarks, N_LANDMARKS, dlib_point=False) -
定义一些
src和dst点:top_of_nose = landmarks[27] left_eye = landmarks[36] right_eye = landmarks[45] bottom_lip = landmarks[57] src = [top_of_nose, left_eye, right_eye, bottom_lip] dst = [[np.int(0.5 * w), np.int(h/3)],\ [np.int(0.3 * w), np.int(h / 3)],\ [np.int(0.7 * w), np.int(h / 3)],\ [np.int(0.5 * w), np.int(h * (2.0/3))]] -
估计变换并变换其余的地标
transformed_crop = cv2.warpAffine(cropped_image, transform, (w, h)) # Get the transformed landmarks transformed_landmarks = np.reshape(cv2.transform(np.expand_dims(landmarks, 1),\ transform), (N_LANDMARKS, 2)).astype(np.float32) # Add the boundary points transformed_landmarks = np.append(transformed_landmarks, boundary_points, axis = 0)
虽然它有点工作,但它并不完美,因为虽然两个图像中的眼睛和嘴唇高度相同,但它们的x 位置不同。我想知道是否有某种方法可以改进它,还是我使用了错误的技术?如果有人指出我正确的方向会很有帮助,谢谢!
【问题讨论】:
-
也许你想看看cv2.warpPerspective。