使用MLKITAndroid Studio 进行面部认证

aemubtdh  于 2023-01-26  发布在  Android
关注(0)|答案(2)|浏览(208)

使用mlkit我可以检测脸,也可以存储脸。现在我想验证存储的脸与当前的脸。如何在mlkit中实现。我谷歌,但我不能。请建议如何实现。我只喜欢mlkit不是任何其他像opencv,...

z8dt9xmd

z8dt9xmd1#

MLKit只支持人脸检测,不支持人脸识别或身份验证。

1aaf6o9v

1aaf6o9v2#

您可以通过比较面部标志之间的距离、面部轮廓之间的距离以及面部属性的差异来比较两个检测到的面部。阈值是任意的,可能需要根据您的使用情况进行调整。

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.")
}}

相关问题