1

我正在使用getIsLeftEyeOpenProbabilityfrommobile vision API来知道眼睛是否睁开。然而,奇怪的事情发生了,我总是得到概率,-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
    }
 }

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

4

1 回答 1

3

您缺少通过“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
}
于 2016-04-01T13:59:02.727 回答