[英]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.