From c8c8e8dadcaabf848c2bffd390a2d56005c4ba66 Mon Sep 17 00:00:00 2001 From: Christopher Throwaway Date: Wed, 27 Jun 2018 17:55:27 -0500 Subject: [PATCH] Manual preview now draws 68-pt face landmarks It could be difficult to tell if the point cloud was 'correct' or not when manually fixing a face detection. For 68-point face landmarks, the facial landmarks are now drawn to make it easier to tell if the face is correctly detected. --- facelib/LandmarksProcessor.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/facelib/LandmarksProcessor.py b/facelib/LandmarksProcessor.py index 3f8975e..bcb55bc 100644 --- a/facelib/LandmarksProcessor.py +++ b/facelib/LandmarksProcessor.py @@ -27,6 +27,15 @@ mean_face_y = np.array([ landmarks_2D = np.stack( [ mean_face_x, mean_face_y ], axis=1 ) +# 68 point landmark definitions +landmarks_68_pt = { "mouth": (48,68), + "right_eyebrow": (17,22), + "left_eyebrow": (22,27), + "right_eye": (36,42), + "left_eye": (42,48), + "nose": (27,35), + "jaw": (0,17) } + def get_transform_mat (image_landmarks, output_size, face_type): if not isinstance(image_landmarks, np.ndarray): image_landmarks = np.array (image_landmarks) @@ -169,6 +178,13 @@ def draw_landmarks (image, image_landmarks, color): cv2.circle(image, (x, y), 2, color, -1) #text_color = colorsys.hsv_to_rgb ( (i%4) * (0.25), 1.0, 1.0 ) #cv2.putText(image, str(i), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.1,text_color,1) + if len(image_landmarks) == 68: + for feat,idx_range in landmarks_68_pt.items(): + for idx in range( idx_range[0], idx_range[1] - 1 ): + pt1 = tuple(image_landmarks[idx]) + pt2 = tuple(image_landmarks[idx + 1]) + cv2.line( image, pt1, pt2, color ) + def draw_rect_landmarks (image, rect, image_landmarks, face_size, face_type): image_utils.draw_rect (image, rect, (255,0,0), 2 )