Android : 使用传感器实时检测眼睛的运动

Android : Detect movement of eyes using sensor at real time

我正在准备一个 android 应用程序,我必须在其中检测眼睛的移动。不知何故,我能够在图像上实现上述目标,但我希望在真实的眼睛上实现。

如果我们可以使用接近传感器来检测眼睛,我无法理解。就像 smartStay 功能一样。

请提出实施相同的想法。

不可以,您不能使用接近传感器进行眼睛检测或跟踪。试试 OpenCV 吧。
Link : OpenCv github : OpenCv github

我们可以使用前置摄像头检测眼睛和眨眼。使用 Vision api 检测眼睛。

眼动追踪代码:

public class FaceTracker extends Tracker<Face> {

private static final float PROB_THRESHOLD = 0.7f;
private static final String TAG = FaceTracker.class.getSimpleName();
private boolean leftClosed;
private boolean rightClosed;

@Override
public void onUpdate(Detector.Detections<Face> detections, Face face) {
    if (leftClosed && face.getIsLeftEyeOpenProbability() > PROB_THRESHOLD) {
        leftClosed = false;
    } else if (!leftClosed &&  face.getIsLeftEyeOpenProbability() < PROB_THRESHOLD){
        leftClosed = true;
    }
    if (rightClosed && face.getIsRightEyeOpenProbability() > PROB_THRESHOLD) {
        rightClosed = false;
    } else if (!rightClosed && face.getIsRightEyeOpenProbability() < PROB_THRESHOLD) {
        rightClosed = true;
    }

    if (leftClosed && !rightClosed) {
        EventBus.getDefault().post(new LeftEyeClosedEvent());
    } else if (rightClosed && !leftClosed) {
        EventBus.getDefault().post(new RightEyeClosedEvent());
    } else if (!leftClosed && !rightClosed) {
        EventBus.getDefault().post(new NeutralFaceEvent());
    }
}
}


//method to call the FaceTracker 
 private void createCameraResources() {
    Context context = getApplicationContext();

    // create and setup the face detector
    mFaceDetector = new FaceDetector.Builder(context)
            .setProminentFaceOnly(true) // optimize for single, relatively large face
            .setTrackingEnabled(true) // enable face tracking
            .setClassificationType(/* eyes open and smile */ FaceDetector.ALL_CLASSIFICATIONS)
            .setMode(FaceDetector.FAST_MODE) // for one face this is OK
            .build();

    // now that we've got a detector, create a processor pipeline to receive the detection
    // results
    mFaceDetector.setProcessor(new LargestFaceFocusingProcessor(mFaceDetector, new FaceTracker()));

    // operational...?
    if (!mFaceDetector.isOperational()) {
        Log.w(TAG, "createCameraResources: detector NOT operational");
    } else {
        Log.d(TAG, "createCameraResources: detector operational");
    }

    // Create camera source that will capture video frames
    // Use the front camera
    mCameraSource = new CameraSource.Builder(this, mFaceDetector)
            .setRequestedPreviewSize(640, 480)
            .setFacing(CameraSource.CAMERA_FACING_FRONT)
            .setRequestedFps(30f)
            .build();
}