Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update face bounding box landmark calculations #77

Merged
merged 3 commits into from
Nov 29, 2023

Conversation

phantumcode
Copy link
Contributor

@phantumcode phantumcode commented Nov 15, 2023

Issue #, if available:

Description of changes:

  • update the bounding box from landmark calculation based on new algorithm provided by the Rekognition science team.

See similar PR from Liveness JS: aws-amplify/amplify-ui#4685
For reference, documented algorithm in JS

function generateFaceLandamrks(faces, oval_box)
  const keypoints = faces[0].keypoints;
  const face_box_bottom = faces[0].box.yMax;
  const leftEye  =  keypoints[1];
  const rightEye =  keypoints[0];
  const nose    =  keypoints[2];
  const leftEar =  keypoints[5];
  const rightEar =  keypoints[4];

  const ovalHeight = oval_box.yMax- oval_box.yMin;
  const ovalTop = oval_box.yMin;

  const eyeCenter = [];
  eyeCenter[0] = (leftEye[0] + rightEye[0]) / 2;
  eyeCenter[1] = (leftEye[1] + rightEye[1]) / 2;

  const { pupilDistance: pd, faceHeight: fh } =
    getPupilDistanceAndFaceHeight(faces);

  const alpha = 2.0,
    gamma = 1.8;
  const ow = (alpha * pd + gamma * fh) / 2;

  let cx;
  if (eyeCenter[1] <= (ovalTop + ovalHeight) / 2) {
    cx = (eyeCenter[0] + nose[0]) / 2;
  } else {  // when face tilts down
    cx = eyeCenter[0];
  }

  let face_width = ow;
  let face_height = 1.68* face_width;
  let face_box_top = face_box_bottom - face_height;
  let face_box_left = Math.min(cx- ow / 2, rightEar[0]);
  let face_box_right = Math.max(cx+ ow / 2, leftEar[0]);
  
  return {'xMin':face_box_left, 'yMin':face_box_top,  'xMax':face_box_right, 'yMax':face_box_bottom};
}

Check points: (check or cross out if not relevant)

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • If breaking change, documentation/changelog update with migration instructions

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@phantumcode phantumcode requested review from a team as code owners November 15, 2023 20:41
@phantumcode phantumcode merged commit ba5e1ae into main Nov 29, 2023
6 checks passed
@phantumcode phantumcode deleted the chore/update_face_bounding_box branch November 29, 2023 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants