@@ -18,6 +18,7 @@ package com.amplifyframework.ui.liveness.ml
1818import android.content.Context
1919import android.graphics.RectF
2020import androidx.annotation.VisibleForTesting
21+ import com.amplifyframework.predictions.aws.models.FaceTargetChallenge
2122import com.amplifyframework.predictions.aws.models.FaceTargetMatchingParameters
2223import com.amplifyframework.ui.liveness.R
2324import com.amplifyframework.ui.liveness.camera.LivenessCoordinator.Companion.TARGET_HEIGHT
@@ -42,10 +43,12 @@ internal class FaceDetector(private val livenessState: LivenessState) {
4243 outputScores : Array <Array <FloatArray >>
4344 ): List <Detection > {
4445 val detections = mutableListOf<Detection >()
46+ val faceTargetChallenge = livenessState.faceTargetChallenge ? : return emptyList()
4547 for (i in 0 until NUM_BOXES ) {
4648 var score = outputScores[0 ][i][0 ]
4749 score = computeSigmoid(score)
48- if (score < MIN_SCORE_THRESHOLD ) {
50+
51+ if (score < faceTargetChallenge.faceTargetMatching.faceDetectionThreshold) {
4952 continue
5053 }
5154
@@ -159,6 +162,7 @@ internal class FaceDetector(private val livenessState: LivenessState) {
159162 scaledMouth,
160163 scaledLeftEar,
161164 scaledRightEar,
165+ faceTargetChallenge.faceTargetMatching.targetHeightWidthRatio
162166 )
163167 renormalizedDetections.add(
164168 Detection (
@@ -183,13 +187,14 @@ internal class FaceDetector(private val livenessState: LivenessState) {
183187 nose : Landmark ,
184188 mouth : Landmark ,
185189 leftEar : Landmark ,
186- rightEar : Landmark
190+ rightEar : Landmark ,
191+ heightWidthRatio : Float
187192 ): RectF {
188193 val pupilDistance = calculatePupilDistance(leftEye, rightEye)
189194 val faceHeight = calculateFaceHeight(leftEye, rightEye, mouth)
190195
191196 val ow = (ALPHA * pupilDistance + GAMMA * faceHeight) / 2
192- val oh = GOLDEN_RATIO * ow
197+ val oh = heightWidthRatio * ow
193198
194199 val eyeCenterX = (leftEye.x + rightEye.x) / 2
195200 val eyeCenterY = (leftEye.y + rightEye.y) / 2
@@ -450,7 +455,6 @@ internal class FaceDetector(private val livenessState: LivenessState) {
450455
451456 companion object {
452457 private const val MIN_SUPPRESSION_THRESHOLD = 0.3f
453- private const val MIN_SCORE_THRESHOLD = 0.7f
454458 private val strides = listOf (8 , 16 , 16 , 16 )
455459 private const val ASPECT_RATIOS_SIZE = 1
456460 private const val MIN_SCALE = 0.1484375f
@@ -459,7 +463,6 @@ internal class FaceDetector(private val livenessState: LivenessState) {
459463 private const val ANCHOR_OFFSET_Y = 0.5f
460464 private const val INPUT_SIZE_HEIGHT = 128
461465 private const val INPUT_SIZE_WIDTH = 128
462- private const val GOLDEN_RATIO = 1.618f
463466 private const val ALPHA = 2.0f
464467 private const val GAMMA = 1.8f
465468 const val X_SCALE = 128f
@@ -479,7 +482,6 @@ internal class FaceDetector(private val livenessState: LivenessState) {
479482 * 14, 15 - right eye tragion
480483 */
481484 const val NUM_COORDS = 16
482- const val INITIAL_FACE_DISTANCE_THRESHOLD = 0.32f
483485
484486 fun loadModel (context : Context ): Interpreter {
485487 val modelFileDescriptor =
0 commit comments