There is not enough info about camera2 face detection mechanism. I used Camera2 sample from Google: https://github.com/android/camera-samples
I set face detection mo
I found that only in case STATE_PREVIEW, you can process the result to show faces lenth. Change from
private CameraCaptureSession.CaptureCallback mCaptureCallback
= new CameraCaptureSession.CaptureCallback() {
private void process(CaptureResult result) {
Integer mode = result.get(CaptureResult.STATISTICS_FACE_DETECT_MODE);
Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
if(faces != null && mode != null) {
Log.e("tag", "faces : " + faces.length + " , mode : " + mode);
}
switch (mState) {
case STATE_PREVIEW: {
// We have nothing to do when the camera preview is working normally.
break;
}
...
to
private CameraCaptureSession.CaptureCallback mCaptureCallback
= new CameraCaptureSession.CaptureCallback() {
private void process(CaptureResult result) {
switch (mState) {
case STATE_PREVIEW: {
Face[] faces = result.get(CaptureResult.STATISTICS_FACES);
if (faces != null && faces.length > 0) {
Log.e("tag", "faces : " + faces.length);
}
break;
}
Please try this to see if it works.