Skip to content

Commit

Permalink
Merge pull request #8 from Yoonit-Labs/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Goulartvic authored Mar 3, 2021
2 parents 73ed196 + 4bd82fc commit 1448a6c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ open class Facefy {
fun detect(
image: InputImage,
onFaceDetected: (FaceDetected) -> Unit,
onMessage: (String) -> Unit
onMessage: (String) -> Unit,
onComplete: () -> Unit
) {
this.facefyController.detect(image, onFaceDetected, onMessage)
this.facefyController.detect(image, onFaceDetected, onMessage, onComplete)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,54 @@ internal class FacefyController {
.setContourMode(FaceDetectorOptions.CONTOUR_MODE_ALL)
.build()

private val detector = FaceDetection.getClient(faceDetectorOptions)

fun detect(
inputImage: InputImage,
onFaceDetected: (FaceDetected) -> Unit,
onMessage: (String) -> Unit
onMessage: (String) -> Unit,
onComplete: () -> Unit
) {
this.detector
.process(inputImage)
.addOnSuccessListener { faces ->

// Get closest face.
// Can be null if no face found.
// Used to crop the face image.
val closestFace: Face? = this.faceCoordinatesController.getClosestFace(faces)
val detector = FaceDetection.getClient(faceDetectorOptions)

closestFace?.let { face ->
detector
.process(inputImage)
.addOnSuccessListener { faces ->

val faceContours = mutableListOf<PointF>()
face.allContours.forEach {faceContour ->
faceContour.points.forEach { pointF ->
faceContours.add(pointF)
}
}
// Get closest face.
// Can be null if no face found.
// Used to crop the face image.
val closestFace: Face? = this.faceCoordinatesController.getClosestFace(faces)

onFaceDetected(
FaceDetected(
face.leftEyeOpenProbability,
face.rightEyeOpenProbability,
face.smilingProbability,
face.headEulerAngleX,
face.headEulerAngleY,
face.headEulerAngleZ,
faceContours,
face.boundingBox
)
)
closestFace?.let { face ->

return@addOnSuccessListener
val faceContours = mutableListOf<PointF>()
face.allContours.forEach {faceContour ->
faceContour.points.forEach { pointF ->
faceContours.add(pointF)
}
}

onMessage("FACE_UNDETECTED")
onFaceDetected(
FaceDetected(
face.leftEyeOpenProbability,
face.rightEyeOpenProbability,
face.smilingProbability,
face.headEulerAngleX,
face.headEulerAngleY,
face.headEulerAngleZ,
faceContours,
face.boundingBox
)
)
return@addOnSuccessListener
}
onMessage("FACE_UNDETECTED")
}
.addOnFailureListener { e ->
e.message?.let { message -> onMessage(message) }
}
.addOnCompleteListener { detector.close() }
.addOnCompleteListener {
detector.close()
onComplete()
}
}
}

0 comments on commit 1448a6c

Please sign in to comment.