Reputation: 3
Using mlkit I can able detect the face and also store the face. Now I want to verify the stored face with current face. How to implement in mlkit. I google but I cant. Please suggest how to implement. I prefer only mlkit not any other like opencv,..
Upvotes: 0
Views: 398
Reputation: 1
You can compare two detected faces by comparing the distance between their facial landmarks, the distance between their facial contours, and the difference in their facial attributes. The threshold values are arbitrary and may need to be adjusted depending on your use case.
import com.google.mlkit.vision.face.Face
import com.google.mlkit.vision.face.FaceContour
fun compareFaces(face1: Face, face2: Face) {
// Compare the facial landmarks
val landmarks1 = face1.landmarks
val landmarks2 = face2.landmarks
// Compare the facial contours
val contours1 = face1.contours
val contours2 = face2.contours
// Compare the facial attributes
val attributes1 = face1.attributes
val attributes2 = face2.attributes
// Compare the facial landmarks
val leftEye1 = landmarks1.get(FaceLandmark.LEFT_EYE)
val leftEye2 = landmarks2.get(FaceLandmark.LEFT_EYE)
val leftEyeDistance = leftEye1.position.distanceTo(leftEye2.position)
// Compare the facial contours
val upperLipBottom1 = contours1.get(FaceContour.UPPER_LIP_BOTTOM)
val upperLipBottom2 = contours2.get(FaceContour.UPPER_LIP_BOTTOM)
val upperLipBottomDistance = upperLipBottom1.points.distanceTo(upperLipBottom2.points)
// Compare the facial attributes
val smilingProbability1 = attributes1.smilingProbability
val smilingProbability2 = attributes2.smilingProbability
val smilingProbabilityDiff = Math.abs(smilingProbability1 - smilingProbability2)
// Compare all the values and decide if the faces are similar or not
if (leftEyeDistance < 0.1 && upperLipBottomDistance < 0.1 && smilingProbabilityDiff < 0.1) {
Log.d(TAG, "The two faces are similar.")
} else {
Log.d(TAG, "The two faces are not similar.")
}
}
Upvotes: 0
Reputation: 882
MLKit only supports face detection, not face recognition or authentication.
Upvotes: 2