Reputation: 21
I can't find information about face detection on preview in android.hardware.Camera2, would anybody help me with a complete example?
I saw some questions with camera2 examples in github but I can't understand them.
I used Camera2 sample from Google: https://github.com/googlesamples/android-Camera2Basic.
I set face recognition mode to FULL.
mPreviewRequestBuilder.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE, CameraMetadata.STATISTICS_FACE_DETECT_MODE_FULL);
Also I checked STATISTICS_INFO_MAX_FACE_COUNT
and STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES
:
int max_count = characteristics.get(
CameraCharacteristics.STATISTICS_INFO_MAX_FACE_COUNT);
int modes [] = characteristics.get(
CameraCharacteristics.STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES);
Output: maxCount : 5 , modes : [0, 2]
My CaptureCallback:
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 );
}
@Override
public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request,
CaptureResult partialResult) {
process(partialResult);
}
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
TotalCaptureResult result) {
process(result);
} `
Output: faces : 0 , mode : 2
public static final int STATISTICS_FACE_DETECT_MODE_FULL = 2;
Faces length is constantly 0. Looks like it doesn't recognise a face properly or I missed something.
I know approach with FaceDetector. I just wanted to check how it works with new camera2 Face.
I need to detect face on preview of camera2!
Upvotes: 2
Views: 673
Reputation: 35
I think that you can't use CameraMetadata.STATISTICS_FACE_DETECT_MODE_FULL, because some devices do not support this type of face detection. Please, can you verify if your device support STATISTICS_FACE_DETECT_MODE_FULL?
If the answer is "NO", please try to use STATISTICS_FACE_DETECT_MODE_SIMPLE
Look at this Samsung Example https://developer.samsung.com/galaxy/camera#techdocs
There is a sample explaining how to use face detection with camera2 API
Upvotes: 0