【问题标题】:getIsLeftEyeOpenProbability from mobile vision API gives a vlaue of -1来自移动视觉 API 的 getIsLeftEyeOpen Probability 的值为 -1
【发布时间】:2016-07-20 04:37:27
【问题描述】:

我正在使用来自mobile vision APIgetIsLeftEyeOpenProbability 来了解眼睛是否睁开。但是,发生了一些奇怪的事情,即使睁开眼睛,我总是得到-1 的概率。

代码如下:

FaceDetector faceDetector = new FaceDetector.Builder(getApplicationContext())
                                            .setTrackingEnabled(false)
                                            .setLandmarkType(FaceDetector.ALL_LANDMARKS)
                                            .build();

Frame frame = new Frame.Builder().setBitmap(obtainedBitmap).build();
SparseArray < Face > facesForLandmarks = faceDetector.detect(frame);
faceDetector.release();
Thread homeSwipeThread;

for (int a = 0; a < facesForLandmarks.size(); a++) {
    Face thisFace = facesForLandmarks.valueAt(a);
    List < Landmark > landmarks = thisFace.getLandmarks();

    for (int b = 0; b < landmarks.size(); b++) {
        if (landmarks.get(b).getType() == landmarks.get(b).LEFT_EYE) {
            leftEye = new Point(landmarks.get(b).getPosition().x, landmarks.get(b).getPosition().y - 3);
        } else if (landmarks.get(b).getType() == landmarks.get(b).RIGHT_EYE) {
            rightEye = new Point(landmarks.get(b).getPosition().x, landmarks.get(b).getPosition().y - 3);
        } //end else if.
    } //end inner
    //for every detected face check eyes probability:

    if (thisFace.getIsLeftEyeOpenProbability() <= 0.1) {
        //some code
    }
 }

为什么会发生这种情况,我该如何解决?

【问题讨论】:

    标签: android computer-vision android-camera android-vision eye-detection


    【解决方案1】:

    您缺少通过“setClassificationType”对睁眼/闭眼进行分类的检测器选项。 faceDetector 应该这样创建:

    FaceDetector faceDetector =
        new FaceDetector.Builder(getApplicationContext())
            .setTrackingEnabled(false)
            .setLandmarkType(FaceDetector.ALL_LANDMARKS)
            .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
            .build();
    

    在这种情况下,您可以省略“setLandmarkType”,因为它是“setClassificationType”的隐含依赖项。

    此外,即使设置了此选项,也可以获得 -1,即文档中提到的“UNCOMPUTED_PROBABILITY”值:

    https://developers.google.com/android/reference/com/google/android/gms/vision/face/Face.html#public-methods

    返回 UNCOMPUTED_PROBABILITY 通常意味着没有检测到眼睛,因此无法确定眼睛是睁着还是闭着。所以我认为你想要这个:

    float leftOpen = thisFace.getIsLeftEyeOpenProbability();
    if ((leftOpen != Face.UNCOMPUTED_PROBABILITY) && (leftOpen <= 0.1)) {
        //some code
    }
    

    【讨论】:

    • 感谢您的精彩解释。但是这一行 boolean isLeftOpen = thisFace.getIsLeftEyeOpenProbability();给我错误,因为浮点数不能转换为布尔值,你能澄清一下这行是什么意思吗?或者,你的意思是 isLeftOpen 是浮动的?
    • 那是一个错字。我修好了。
    猜你喜欢
    • 2017-10-23
    • 2021-10-21
    • 2019-10-09
    • 1970-01-01
    • 2023-03-23
    • 2016-11-10
    • 1970-01-01
    • 2017-03-20
    • 2017-09-29
    相关资源
    最近更新 更多