Camera Face detection listener not working when camera is zoomed

258 views Asked by At

I have added FaceDetection listener to my camera after preview is started. So when face is detecting, I am getting callback and and upon which, i calculate ratio of the area of face and the preview screen. Upon some value if the percentage is lower I zoom the camera.

But the problem is, after zooming the face detection is not working, not getting callback on FaceDetectionListener.

public class FaceDetectionListener implements Camera.FaceDetectionListener {

@Override
public void onFaceDetection( final Camera.Face[] faces, Camera camera ) {
    Log.i(TAG, "onFaceDetection " + faces.length);
    if ( faces.length > 0 ) {

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {

                Rect uRect = null;
                //Do something after 100ms
                for ( int i = 0; i < faces.length; i++ ) {
                    int left = faces[i].rect.left;
                    int right = faces[i].rect.right;
                    int top = faces[i].rect.top;
                    int bottom = faces[i].rect.bottom;
                    uRect = new Rect(left, top, right, bottom);

                    Log.d("FaceDetection", "face detected: " + faces.length +
                            " Face 1 Location Left: " + left +
                            " Right: " + right + " Top: " + top + " Bottom: " + bottom + " Area: " + (uRect.height() * uRect.width()));

                }

                FaceDetect faceDetect = new FaceDetect();
                faceDetect.setArea(uRect.height() * uRect.width());

                EventBus.getDefault().post(faceDetect);
            }
        }, 500);

    }
}

}

Zooming codes -

 private synchronized void zoomCamera( int zoomValue ) {
    Log.i(TAG, "Camera Zoomed : " + zoomValue);
    if ( mCamera.getParameters().isZoomSupported() ) {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.setRecordingHint(true);
        parameters.setZoom(zoomValue);
        mCamera.setParameters(parameters);

        Log.i(TAG, "Camera ZOOMED : ");

    }

}
0

There are 0 answers