Skip to content

Commit

Permalink
fixing issue where eyeCenter cannot find absolute center using non in…
Browse files Browse the repository at this point in the history
…teger-based measurements
  • Loading branch information
joecodecreations committed Jan 18, 2023
1 parent 0272a0e commit 0ba086b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions facealigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,10 @@ def align(self, image, gray, rect, shape, scale=None):

# compute center (x, y)-coordinates (i.e., the median point)
# between the two eyes in the input image
#eyesCenter = ((leftEyeCenter[0] + rightEyeCenter[0]) // 2,
eyesCenter = (int((leftEyeCenter[0] + rightEyeCenter[0]) // 2),# lrpAdd int, so now it is working
int((leftEyeCenter[1] + rightEyeCenter[1]) // 2))
#print(eyesCenter) # lrpAdd
#return
eyesCenter = (round((leftEyeCenter[0] + rightEyeCenter[0]) // 2), round((leftEyeCenter[1] + rightEyeCenter[1]) // 2))

# grab the rotation matrix for rotating and scaling the face
#print('eyesCenter:'+str(type(eyesCenter)))#tuple
#print('angle:'+str(type(angle)))
#print('scale'+str(type(scale)))
M = cv2.getRotationMatrix2D(eyesCenter, angle, scale)#lrpAdd int to all
M = cv2.getRotationMatrix2D(eyesCenter, angle, scale)

# update the translation component of the matrix
tX = self.desiredFaceWidth * 0.5
Expand All @@ -121,6 +114,9 @@ def get_tform(self, image, shape, mean_shape, scale=None):
rightEyeCenter = mean_shape[right_eye, :].mean(axis=0)
noseCenter = mean_shape[nose, :].mean(axis=0)

# print(leftEyeCenter)
# exit()

template_points = np.float32([leftEyeCenter, rightEyeCenter, noseCenter])

leftEyeCenter = shape[left_eye, :].mean(axis=0)
Expand All @@ -140,6 +136,12 @@ def apply_tform(self, image):
return output, None

def align_three_points(self, image, shape, mean_shape, scale=None):
# shape = shape_to_np(shape)

# (lStart, lEnd) = FACIAL_LANDMARKS_68_IDXS["left_eye"]
# (rStart, rEnd) = FACIAL_LANDMARKS_68_IDXS["right_eye"]
# (nStart, nEnd) = FACIAL_LANDMARKS_68_IDXS["nose"]

left_eye = [40, 39]
right_eye = [42, 47]
nose = [30, 31, 32, 33, 34, 35]
Expand All @@ -148,6 +150,9 @@ def align_three_points(self, image, shape, mean_shape, scale=None):
rightEyeCenter = mean_shape[right_eye, :].mean(axis=0)
noseCenter = mean_shape[nose, :].mean(axis=0)

# print(leftEyeCenter)
# exit()

template_points = np.float32([leftEyeCenter, rightEyeCenter, noseCenter])

leftEyeCenter = shape[left_eye, :].mean(axis=0)
Expand Down

0 comments on commit 0ba086b

Please sign in to comment.