松开相机时“停止面部检测失败”异常

时间:2012-07-31 18:31:11

标签: android face-detection

我在Galaxy Nexus上使用新的API 14+ FaceDetectionListener来检测相机预览中的脸部。一切正常,我可以拿起面孔,但是当我在SurfaceHolder被破坏时尝试关闭相机时,我得到一个RuntimeException,表示“停止面部检测失败”。我用来设置和停止面部检测的代码如下所示:

public void surfaceChanged( SurfaceHolder holder, int format, int w, int h ) {
    if( isPreviewRunning ) {
        camera.stopPreview();
    }
    initPreview( w, h );
    camera.startPreview();
    if( enableFaceRecognition ) {
        camera.startFaceDetection();
    }
    isPreviewRunning = true;
}

public void surfaceDestroyed( SurfaceHolder holder ) {
    if( camera != null ) {
        if( enableFaceRecognition ) {
            try {
                camera.stopFaceDetection();
            } catch( Exception e ) {
                Log.e( TAG, "Huh?", e );
            }
        }
        cameraConfigured = false;
        camera.stopPreview();
        camera.release();
        camera = null;
    }
}

哦,并且:

enableFaceRecognition = camera.getParameters().getMaxNumDetectedFaces() > 0

修改

这是logcat输出:

07-31 18:59:47.809: E/Preview(9410): Huh?
07-31 18:59:47.809: E/Preview(9410): java.lang.RuntimeException: stop face detection failed
07-31 18:59:47.809: E/Preview(9410):    at android.hardware.Camera._stopFaceDetection(Native Method)
07-31 18:59:47.809: E/Preview(9410):    at android.hardware.Camera.stopFaceDetection(Camera.java:1138)
07-31 18:59:47.809: E/Preview(9410):    at app.face.Preview.surfaceDestroyed(Preview.java:126)
07-31 18:59:47.809: E/Preview(9410):    at android.view.SurfaceView.updateWindow(SurfaceView.java:517)
07-31 18:59:47.809: E/Preview(9410):    at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:226)
07-31 18:59:47.809: E/Preview(9410):    at android.view.View.dispatchWindowVisibilityChanged(View.java:5839)
07-31 18:59:47.809: E/Preview(9410):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:945)
07-31 18:59:47.809: E/Preview(9410):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:945)
07-31 18:59:47.809: E/Preview(9410):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:945)
07-31 18:59:47.809: E/Preview(9410):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:945)
07-31 18:59:47.809: E/Preview(9410):    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:945)
07-31 18:59:47.809: E/Preview(9410):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:965)
07-31 18:59:47.809: E/Preview(9410):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
07-31 18:59:47.809: E/Preview(9410):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 18:59:47.809: E/Preview(9410):    at android.os.Looper.loop(Looper.java:137)
07-31 18:59:47.809: E/Preview(9410):    at android.app.ActivityThread.main(ActivityThread.java:4424)
07-31 18:59:47.809: E/Preview(9410):    at java.lang.reflect.Method.invokeNative(Native Method)
07-31 18:59:47.809: E/Preview(9410):    at java.lang.reflect.Method.invoke(Method.java:511)
07-31 18:59:47.809: E/Preview(9410):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-31 18:59:47.809: E/Preview(9410):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-31 18:59:47.809: E/Preview(9410):    at dalvik.system.NativeStart.main(Native Method)

任何想法导致此异常的原因是什么?

0 个答案:

没有答案