Search code examples
javaandroidcameraface-detection

Nexus 5 Camera.Face object is null?


Here is my code on gist

This camera app is follow Android Official Guide

My device is Nexus 5 with kikat 4.4.2

    @Override
    public void onFaceDetection(Camera.Face[] faces, Camera camera) {
      if (faces.length > 0){
        Camera.Face f = faces[0];
        Log.v(TAG, ("Detected" + faces.length + "faces,the ID of first face is:" + f.id ));

        Log.v(TAG, "leftEye : " + f.leftEye);
        Log.v(TAG, "mouth   : " + f.mouth);
        Log.v(TAG, "rect    : " + f.rect);
        Log.v(TAG, "rightEye: " + f.rightEye);

        mCamera.stopFaceDetection();
    }
}

The output above code when detect a human face is:

Detected 1 faces,the ID of first face is:-1
FaceActivity﹕ leftEye : null
FaceActivity﹕ mouth   : null
FaceActivity﹕ rect    : Rect(-393, 356 - -213, 676)
FaceActivity﹕ rightEye: null

So, I want to know whether my Nexus 5 support FaceDetect?If not, how could it implement Screen Lock with Face Unlock?


Solution

  • I found out the reason for this problem. It's all about RGB_564. Android has an API to recognize the human face, but only RGB_564 bitmaps are supported. Face detection is a very cost intensive action. So by default, the camera's FaceDetect feature only recognizes basic face information, and that was the reason why face.leftEye is null.