Detecting Liveness - 使用 ML KIT Android 的眨眼和微笑概率

问题描述 投票:0回答:0

在我的 android 应用程序中使用 Google ml-kit 进行人脸检测。

我还必须检测眨眼和微笑的活跃度。

下面是函数:

fun detectLiveness(image: Bitmap, face: Face): Float? {
    val aligned = this.faceSquaredAligner.computeImagePatch(face, image, 224)
    val token = this.faceSquaredAligner.computeImagePatch(face, image, 448)

    val squareData = prepareImage(aligned, 1)
    val tokenData = prepareImage(token, 1)

    var score: Float? = null
    if (face.rightEyeOpenProbability != null) {
        Toast.makeText(context,"got it", Toast.LENGTH_SHORT).show()
    }else{
        Toast.makeText(context,"Right Eye null", Toast.LENGTH_SHORT).show()
    }
    this.env.use {
        var squareTensor = OnnxTensor.createTensor(
            this.env, squareData,
            this.getTensorShape(aligned)
        )
        val tokenTensor = OnnxTensor.createTensor(
            this.env, tokenData,
            this.getTensorShape(token)
        )
        squareTensor.use {
            tokenTensor.use {
                var inputs = mutableMapOf("input.1" to tokenTensor, "input.207" to squareTensor)
                var outputs = mutableSetOf("718")
                val output = this.session.run(inputs, outputs, OrtSession.RunOptions())
                output.use {
                    @Suppress("UNCHECKED_CAST")
                    val rawOutput = ((output?.get(0)?.value) as Array<FloatArray>)[0]
                    score = softMax(rawOutput)[0]
                }
            }
        }
    }
    return score
}

我在其中检查了 rightEyeOpenProbability,但结果为空。

我们有“OnnxruntimeLivenessDetector”类,它有名为“detectLiveness()”的方法,它返回分数(浮点值) 这个“detectLiveness()”方法是从“FaceDetector”类中名为“processDetection()”的方法调用的。

在这两个地方,我都尝试检查右眼、左眼和微笑概率,但没有得到任何价值。

我在这里做错了什么?或者是否有任何不同的方法来检测活跃度,即用户的眨眼和微笑值? 提前致谢。

android kotlin face-detection firebase-mlkit google-mlkit
© www.soinside.com 2019 - 2024. All rights reserved.