简体   繁体   English

onFaceDetection在运行时只调用一次或两次,但在使用断点进行调试时效果很好

[英]onFaceDetection called only once or twice while running but works perfectly when debugging with breakpoints

This is the code I am using for face detection, the problem is when I debug this code with android studio the onFaceDetection method is called multiple times and face is detected perfectly(When i put a break point inside the method). 这是我用于人脸检测的代码,问题是当我用android studio调试这个代码时,onFaceDetection方法被多次调用并且face被完美地检测到(当我在方法中放置一个断点时)。 But when I run it without any break points the method is called only 2-3 times and face detection doesn't take place. 但是当我在没有任何断点的情况下运行它时,该方法仅被调用2-3次并且不会发生面部检测。 Any help regarding this would be much appreciated, as you can see from the code I've tried stopping and starting face detection. 任何有关这方面的帮助将非常感激,因为从我尝试停止并开始面部检测的代码中可以看出。

void setFaceDetectionListener() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        mFaceDetectionListener = new Camera.FaceDetectionListener() {
            Handler faceDetectionHandler;
            @Override
            public void onFaceDetection(final Camera.Face[] faces, final Camera camera) {
                if(faceDetectionHandler == null){//Initialize
                    faceDetectionHandler = new Handler();
                    Toast.makeText(HWTestActivity.this,
                            UiMessages.MSG_SHOW_YOUR_FACE.toString(),
                            Toast.LENGTH_SHORT).show();
                }
                faceDetectionHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        Log.e("faceDetect", "No of faces = " + faces.length);
                        if (!is_face_detected) {
                            Toast.makeText(HWTestActivity.this,
                                    UiMessages.MSG_DETECTING_YOUR_FACE.toString(),
                                    Toast.LENGTH_SHORT).show();
                            is_face_detected = faces.length > 0;
                        }
                        if (faces.length > 0) {
                            Toast.makeText(HWTestActivity.this,
                                    UiMessages.MSG_FACE_DETECTED.toString(),
                                    Toast.LENGTH_SHORT).show();
                            camera.stopFaceDetection();
                        } else {
                            camera.stopFaceDetection();
                            camera.startFaceDetection();
                        }
                    }
                });
            }
        };
    }
}

This was ignorance on my part, apparently you can't have face detection running while the media recorder is running, So guys don't try to run face detection while you are recording with the camera simultaneously. 这是我的无知,显然你不能在媒体录音机运行时进行面部检测,所以当你用相机同时录制时,你不会尝试运行人脸检测。

If you really wanted to detect faces while recording then you should use the 如果您真的想在录制时检测面部,那么您应该使用

onPreviewFrame(byte[] pixelData, Camera camera)

method in 方法

Camera.PreviewCallback()

convert the pixelData to RGB_565 bitmap and supply it to the FaceDetector.findfaces method. 将pixelData转换为RGB_565位图并将其提供给FaceDetector.findfaces方法。 But in my experience I find this method to be very unreliable. 但根据我的经验,我发现这种方法非常不可靠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我只调用一次时,我的方法运行两次 - My method is running twice when it is only called once Netbeans插件在调试时可以完美地工作,但是在将插件安装到IDE时不能工作 - Netbeans plugin works perfectly while debugging, but not working when the plugin is installed to the IDE Android键盘仅显示一次,但在删除ListView时可以完美运行 - Android keyboard only shows up once, but works perfectly when I remove the ListView 比较语句是否应该被调用两次,但在比较 Integer 时只调用一次 - comparison if statment should be called twice but it is only called once when comparing an Integer 构造函数仅在调用 static 方法两次返回 static object 时调用一次? - Constructor was only called once when calling static method twice that returns the static object? 仅在while循环中调用函数时,才将文件发送到blob - Sending file to blob only works when function is called in while loop 增量运算符在运行和调试时的工作方式有所不同 - Increment operator works different while running and debugging 从JAR运行时编码错误,从Eclipse运行完美 - Wrong encoding when running from JAR, from Eclipse works perfectly Selenium IE WebDriver 仅在调试时有效 - Selenium IE WebDriver only works while debugging 异常处理在运行程序中只能运行一次 - Exception Handling works only once in running program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM