Attempting to use Android 4 API 14 face recognition found in Camera.Face class.
I'm having difficulty getting values for face coordinates [Left/Right eye, mouth].
Device im using is Samsung Galaxy Tab 2 [GT-P5100] with Android 4.0.4
I'm initialising face detection something like below code snippet and the value of camera.getParameters().getMaxNumDetectedFaces() is returned as 3 when running on the above mentioned device.
Now when face is introduced to the surface frame and detected in face detection listener, it returns back the values in faces[0].rect.flattenToString() identifying position of the face on surface. However the rest of the values i.e. face id, left/right eye and mouth are returned as -1 and Null respectively.
This behaviour is described in documentation as
This is an optional field, may not be supported on all devices. If not supported, the value will always be set to null. The optional fields are supported as a set. Either they are all valid, or none of them are.
So the question is am I missing something or is it simply that my device can not support Android api face recognition as found in Camera.Face?
It is worth to mention that same device offeres face log in to the device, which is configured trough user settings.
FaceDetectionListener faceDetectionListener = new FaceDetectionListener(){
@Override
public void onFaceDetection(Face[] faces, Camera camera) {
if (faces.length == 0){
prompt.setText(" No Face Detected! ");
}else{
prompt.setText(String.valueOf(faces.length) + " Face Detected :) [ "
+ faces[0].rect.flattenToString()
+ "Coordinates : Left Eye - " + faces[0].leftEye + "]"
) ;
Log.i("TEST", "face coordinates = Rect :" + faces[0].rect.flattenToString());
Log.i("TEST", "face coordinates = Left eye : " + String.valueOf(faces[0].leftEye));
Log.i("TEST", "face coordinates = Right eye - " + String.valueOf(faces[0].rightEye));
Log.i("TEST", "face coordinates = Mouth - " + String.valueOf(faces[0].mouth));
}
.....
if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
prompt.setText(String.valueOf(
"Max Face: " + camera.getParameters().getMaxNumDetectedFaces()));
camera.startFaceDetection();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
In your initialization code, you need to set the face detection listener for the camera.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With