Skip to content
This repository was archived by the owner on Jul 11, 2022. It is now read-only.
Open
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 @@ -96,6 +96,22 @@ class FaceDetectionProcessor(res: Resources) : VisionProcessorBase<List<Firebase
graphicOverlay.postInvalidate()
}

fun closestFace(faces : List<FaceGraphic>): FaceGraphic {
if (faces.isEmpty()) {

}
var closest = 1000.0
var name : FaceGraphic = faces[0]
for (face in faces) {
val dis = face.getFaceDistanceFromCenter()
if(dis < closest) {
closest = dis
name = face
}
}
return name
}

fun calculateErrorAndSend(){
if(firstFace != null) {
val panAngle = panProcessor.update(firstFace!!.getPanError())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ class FaceGraphic(
strokeWidth = BOX_STROKE_WIDTH
}

fun getFaceDistanceFromCenter() : Double {
val face = firebaseVisionFace ?: return 0.0
val faceCenterX = translateX(face.boundingBox.centerX().toFloat()).toDouble()
val faceCenterY = translateY(face.boundingBox.centerY().toFloat()).toDouble()
return calculateDistanceBetweenPoints(faceCenterX, faceCenterY, overlayCenterX.toDouble(), overlayCenterY.toDouble())
}

private fun calculateDistanceBetweenPoints(
x1: Double,
y1: Double,
x2: Double,
y2: Double
): Double {
return Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1))
}

fun getPanError() : Float {
if (firebaseVisionFace == null) {
return 0f
Expand Down