0

预览开始后,我已将 FaceDetection 侦听器添加到我的相机。因此,当人脸检测时,我会收到回调,并在此基础上计算人脸区域和预览屏幕的比例。如果百分比较低,我会根据某个值缩放相机。

但问题是,缩放后人脸检测不起作用,在 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);

    }
}

}

缩放代码 -

 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 : ");

    }

}
4

0 回答 0