Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import kotlin.math.abs
internal data class FaceTarget(
val yawTarget: Target,
val rollTarget: Target,
val areaRange: ClosedRange<Float>,
val minFacePixelArea: Float,
val maxRelativeArea: Float,
) {
operator fun contains(face: Face): Boolean = face.roll in rollTarget && face.yaw in yawTarget
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ internal class LiveFeedbackFragmentViewModel @Inject constructor(
private val faceTarget = FaceTarget(
SymmetricTarget(VALID_YAW_DELTA),
SymmetricTarget(VALID_ROLL_DELTA),
0.20f..0.5f,
minFacePixelArea = 10000f, // Todo to be visited latter
maxRelativeArea = 0.5f,
)
private val fallbackCaptureEventStartTime = timeHelper.now()
private var shouldSendFallbackCaptureEvent: AtomicBoolean = AtomicBoolean(true)
Expand Down Expand Up @@ -229,9 +230,18 @@ internal class LiveFeedbackFragmentViewModel @Inject constructor(
potentialFace: Face,
): FaceDetection {
val areaOccupied = potentialFace.relativeBoundingBox.area()

// 2. Calculate the absolute pixel area the face occupies in the current bitmap
val totalImageArea = bitmap.width * bitmap.height
val absoluteFaceArea = areaOccupied * totalImageArea

val status = when {
areaOccupied < faceTarget.areaRange.start -> FaceDetection.Status.TOOFAR
areaOccupied > faceTarget.areaRange.endInclusive -> FaceDetection.Status.TOOCLOSE
// Check if the face lacks enough pixel density (TOOFAR)
absoluteFaceArea < faceTarget.minFacePixelArea -> FaceDetection.Status.TOOFAR

// Check if the face is overflowing the camera frame (TOOCLOSE)
areaOccupied > faceTarget.maxRelativeArea -> FaceDetection.Status.TOOCLOSE

potentialFace.yaw !in faceTarget.yawTarget -> FaceDetection.Status.OFFYAW
potentialFace.roll !in faceTarget.rollTarget -> FaceDetection.Status.OFFROLL
shouldCheckQuality() && potentialFace.quality < qualityThreshold -> FaceDetection.Status.BAD_QUALITY
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.simprints.core.tools.extentions

import android.graphics.RectF
import kotlin.math.abs

fun RectF.area() = height() * width()
fun RectF.area() = abs(height() * width())
Loading