我正在使用视觉API进行人脸检测,现在我想实现眨眼,但是当一只眼睛熄灭时,仍然可以通过视觉api检测眼睛.
请帮我看看如何实现眨眼功能.
来自面部的"眼睛开放概率"值是检测眨眼的关键.此外,您可以使用跟踪器跟踪眼睛状态随时间的变化,以检测指示闪烁的事件序列:
双眼睁开 - >双眼闭上 - >双眼睁开
这是一个示例跟踪器:
public class BlinkTracker extends Tracker{ private final float OPEN_THRESHOLD = 0.85; private final float CLOSE_THRESHOLD = 0.15; private int state = 0; public void onUpdate(Detector.Detections detections, Face face) { float left = face.getIsLeftEyeOpenProbability(); float right = face.getIsRightEyeOpenProbability(); if ((left == Face.UNCOMPUTED_PROBABILITY) || (right == Face.UNCOMPUTED_PROBABILITY)) { // At least one of the eyes was not detected. return; } switch (state) { case 0: if ((left > OPEN_THRESHOLD) && (right > OPEN_THRESHOLD)) { // Both eyes are initially open state = 1; } break; case 1: if ((left < CLOSE_THRESHOLD) && (right < CLOSE_THRESHOLD)) { // Both eyes become closed state = 2; } break; case 2: if ((left > OPEN_THRESHOLD) && (right > OPEN_THRESHOLD)) { // Both eyes are open again Log.i("BlinkTracker", "blink occurred!"); state = 0; } break; } } }
请注意,您还需要启用"分类"以使探测器指示眼睛是否打开/关闭:
FaceDetector detector = new FaceDetector.Builder(context) .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS) .build();
然后将跟踪器添加为处理器,用于随时间从检测器接收面部更新.例如,此配置将用于跟踪视图中最大的面是否闪烁:
detector.setProcessor( new LargestFaceFocusingProcessor(detector, new BlinkTracker()));
或者,如果您有兴趣检测所有面(不仅是最大面)的闪烁,则可以使用MultiProcessor而不是LargestFaceFocusingProcessor.