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

问题描述:

我正在准备一个需要检测眼睛运动的android应用程序。不知何故,我能够在图像上实现上述目标,但我希望通过现场观看。Android:实时使用传感器检测眼睛的运动

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

请建议实施相同的想法。

+0

你不会使用接近了,你会用你的凸轮...我希望这有助于 –

+0

感谢@OmarElDon的建议。所以前台摄像头不会出现在屏幕上,它会检测到眼睛。请确认我的理解是否正确。 – PuneetGupta

+0

不完全是这样,它只是作为一个移动探测器,至少对于远处物体来说不起作用 –

我们可以使用前置摄像头检测到的眼睛和眼睛眨。使用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(); 
} 

不,您不能使用接近传感器进行眼睛检测或跟踪。给OpenCV一个镜头。
链接:OpenCv github上:OpenCv github

+0

我们可以使用前置摄像头进行眼睛探测吗?意味着前面的凸轮可以在背景中运行,并能够感知眼睛。 – PuneetGupta

+0

是的,这是可能的。 –

+0

你有没有任何运行的例子在android上没有openCv(不知道任何关于openCv)。 – PuneetGupta