diff --git a/facelib/LandmarksProcessor.py b/facelib/LandmarksProcessor.py index 3b8b547..3495403 100644 --- a/facelib/LandmarksProcessor.py +++ b/facelib/LandmarksProcessor.py @@ -9,25 +9,96 @@ from mathlib.umeyama import umeyama from facelib import FaceType import math -mean_face_x = np.array([ -0.000213256, 0.0752622, 0.18113, 0.29077, 0.393397, 0.586856, 0.689483, 0.799124, -0.904991, 0.98004, 0.490127, 0.490127, 0.490127, 0.490127, 0.36688, 0.426036, -0.490127, 0.554217, 0.613373, 0.121737, 0.187122, 0.265825, 0.334606, 0.260918, -0.182743, 0.645647, 0.714428, 0.793132, 0.858516, 0.79751, 0.719335, 0.254149, -0.340985, 0.428858, 0.490127, 0.551395, 0.639268, 0.726104, 0.642159, 0.556721, -0.490127, 0.423532, 0.338094, 0.290379, 0.428096, 0.490127, 0.552157, 0.689874, -0.553364, 0.490127, 0.42689 ]) - -mean_face_y = np.array([ -0.106454, 0.038915, 0.0187482, 0.0344891, 0.0773906, 0.0773906, 0.0344891, -0.0187482, 0.038915, 0.106454, 0.203352, 0.307009, 0.409805, 0.515625, 0.587326, -0.609345, 0.628106, 0.609345, 0.587326, 0.216423, 0.178758, 0.179852, 0.231733, -0.245099, 0.244077, 0.231733, 0.179852, 0.178758, 0.216423, 0.244077, 0.245099, -0.780233, 0.745405, 0.727388, 0.742578, 0.727388, 0.745405, 0.780233, 0.864805, -0.902192, 0.909281, 0.902192, 0.864805, 0.784792, 0.778746, 0.785343, 0.778746, -0.784792, 0.824182, 0.831803, 0.824182 ]) - -landmarks_2D = np.stack( [ mean_face_x, mean_face_y ], axis=1 ) +landmarks_2D = np.array([ +[ 0.000213256, 0.106454 ], #17 +[ 0.0752622, 0.038915 ], #18 +[ 0.18113, 0.0187482 ], #19 +[ 0.29077, 0.0344891 ], #20 +[ 0.393397, 0.0773906 ], #21 +[ 0.586856, 0.0773906 ], #22 +[ 0.689483, 0.0344891 ], #23 +[ 0.799124, 0.0187482 ], #24 +[ 0.904991, 0.038915 ], #25 +[ 0.98004, 0.106454 ], #26 +[ 0.490127, 0.203352 ], #27 +[ 0.490127, 0.307009 ], #28 +[ 0.490127, 0.409805 ], #29 +[ 0.490127, 0.515625 ], #30 +[ 0.36688, 0.587326 ], #31 +[ 0.426036, 0.609345 ], #32 +[ 0.490127, 0.628106 ], #33 +[ 0.554217, 0.609345 ], #34 +[ 0.613373, 0.587326 ], #35 +[ 0.121737, 0.216423 ], #36 +[ 0.187122, 0.178758 ], #37 +[ 0.265825, 0.179852 ], #38 +[ 0.334606, 0.231733 ], #39 +[ 0.260918, 0.245099 ], #40 +[ 0.182743, 0.244077 ], #41 +[ 0.645647, 0.231733 ], #42 +[ 0.714428, 0.179852 ], #43 +[ 0.793132, 0.178758 ], #44 +[ 0.858516, 0.216423 ], #45 +[ 0.79751, 0.244077 ], #46 +[ 0.719335, 0.245099 ], #47 +[ 0.254149, 0.780233 ], #48 +[ 0.340985, 0.745405 ], #49 +[ 0.428858, 0.727388 ], #50 +[ 0.490127, 0.742578 ], #51 +[ 0.551395, 0.727388 ], #52 +[ 0.639268, 0.745405 ], #53 +[ 0.726104, 0.780233 ], #54 +[ 0.642159, 0.864805 ], #55 +[ 0.556721, 0.902192 ], #56 +[ 0.490127, 0.909281 ], #57 +[ 0.423532, 0.902192 ], #58 +[ 0.338094, 0.864805 ], #59 +[ 0.290379, 0.784792 ], #60 +[ 0.428096, 0.778746 ], #61 +[ 0.490127, 0.785343 ], #62 +[ 0.552157, 0.778746 ], #63 +[ 0.689874, 0.784792 ], #64 +[ 0.553364, 0.824182 ], #65 +[ 0.490127, 0.831803 ], #66 +[ 0.42689 , 0.824182 ] #67 +], dtype=np.float32) + + +landmarks_2D_new = np.array([ +[ 0.000213256, 0.106454 ], #17 +[ 0.0752622, 0.038915 ], #18 +[ 0.18113, 0.0187482 ], #19 +[ 0.29077, 0.0344891 ], #20 +[ 0.393397, 0.0773906 ], #21 +[ 0.586856, 0.0773906 ], #22 +[ 0.689483, 0.0344891 ], #23 +[ 0.799124, 0.0187482 ], #24 +[ 0.904991, 0.038915 ], #25 +[ 0.98004, 0.106454 ], #26 +[ 0.490127, 0.203352 ], #27 +[ 0.490127, 0.307009 ], #28 +[ 0.490127, 0.409805 ], #29 +[ 0.490127, 0.515625 ], #30 +[ 0.36688, 0.587326 ], #31 +[ 0.426036, 0.609345 ], #32 +[ 0.490127, 0.628106 ], #33 +[ 0.554217, 0.609345 ], #34 +[ 0.613373, 0.587326 ], #35 +[ 0.121737, 0.216423 ], #36 +[ 0.187122, 0.178758 ], #37 +[ 0.265825, 0.179852 ], #38 +[ 0.334606, 0.231733 ], #39 +[ 0.260918, 0.245099 ], #40 +[ 0.182743, 0.244077 ], #41 +[ 0.645647, 0.231733 ], #42 +[ 0.714428, 0.179852 ], #43 +[ 0.793132, 0.178758 ], #44 +[ 0.858516, 0.216423 ], #45 +[ 0.79751, 0.244077 ], #46 +[ 0.719335, 0.245099 ], #47 +[ 0.254149, 0.780233 ], #48 +[ 0.726104, 0.780233 ], #54 +], dtype=np.float32) # 68 point landmark definitions landmarks_68_pt = { "mouth": (48,68), @@ -155,7 +226,9 @@ def get_transform_mat (image_landmarks, output_size, face_type, scale=1.0): else: raise ValueError ('wrong face_type: ', face_type) - mat = umeyama(image_landmarks[17:], landmarks_2D, True)[0:2] + #mat = umeyama(image_landmarks[17:], landmarks_2D, True)[0:2] + mat = umeyama( np.concatenate ( [ image_landmarks[17:49] , image_landmarks[54:55] ] ) , landmarks_2D_new, True)[0:2] + mat = mat * (output_size - 2 * padding) mat[:,2] += padding mat *= (1 / scale)