getIsLeftEyeOpen 来自移动视觉的概率 API 给出的值为 -1
getIsLeftEyeOpenProbability from mobile vision API gives a vlaue of -1
我正在使用 mobile vision API
中的 getIsLeftEyeOpenProbability
来了解眼睛是否睁开。然而,奇怪的事情发生了,即使睁开眼睛,我总是得到-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
}
}
为什么会出现这种情况,我该如何解决?
您缺少用于对眼睛进行分类的检测器选项 open/closed,通过 "setClassificationType"。 faceDetector 应该像这样创建:
FaceDetector faceDetector =
new FaceDetector.Builder(getApplicationContext())
.setTrackingEnabled(false)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.build();
在这种情况下,您可以省略 "setLandmarkType",因为它是 "setClassificationType" 的隐含依赖项。
此外,即使设置了这个选项,也有可能得到 -1,这是文档中提到的 "UNCOMPUTED_PROBABILITY" 值:
返回 UNCOMPUTED_PROBABILITY 通常意味着未检测到眼睛,因此无法确定眼睛是睁着还是闭着。所以我想你想要这个:
float leftOpen = thisFace.getIsLeftEyeOpenProbability();
if ((leftOpen != Face.UNCOMPUTED_PROBABILITY) && (leftOpen <= 0.1)) {
//some code
}
我正在使用 mobile vision API
中的 getIsLeftEyeOpenProbability
来了解眼睛是否睁开。然而,奇怪的事情发生了,即使睁开眼睛,我总是得到-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
}
}
为什么会出现这种情况,我该如何解决?
您缺少用于对眼睛进行分类的检测器选项 open/closed,通过 "setClassificationType"。 faceDetector 应该像这样创建:
FaceDetector faceDetector =
new FaceDetector.Builder(getApplicationContext())
.setTrackingEnabled(false)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.build();
在这种情况下,您可以省略 "setLandmarkType",因为它是 "setClassificationType" 的隐含依赖项。
此外,即使设置了这个选项,也有可能得到 -1,这是文档中提到的 "UNCOMPUTED_PROBABILITY" 值:
返回 UNCOMPUTED_PROBABILITY 通常意味着未检测到眼睛,因此无法确定眼睛是睁着还是闭着。所以我想你想要这个:
float leftOpen = thisFace.getIsLeftEyeOpenProbability();
if ((leftOpen != Face.UNCOMPUTED_PROBABILITY) && (leftOpen <= 0.1)) {
//some code
}