I am working on an Android app that does face and eye detection using the FaceDetection API for Android. I am able to detect and draw rectangles around faces but however I cannot figure out why all my eye coordinates are getting set to (0,0).
Reading this documentation, I see that the eye detection is not supported on all devices but it says that the Point objects are set to null, not (0,0) so I don't understand what is going on here.
Here is my FaceDetectionListener:
private List<Rect> faceRects;
private Point leftEye;
private Point rightEye;
@Override
public void onFaceDetection(Camera.Face[] faces, Camera camera) {
if (faces.length > 0) {
faceRects = new ArrayList<Rect>();
for (int i = 0; i < faces.length; i++) {
int left = faces[i].rect.left;
int right = faces[i].rect.right;
int top = faces[i].rect.top;
int bottom = faces[i].rect.bottom;
Rect uRect = new Rect(left, top, right, bottom);
faceRects.add(uRect);
leftEye = faces[i].leftEye; //***THIS IS (0,0) EVEN WHEN FACE IS DETECTED
rightEye = faces[i].rightEye;
}
}
}
Why are my Points for eye coordinates getting set to (0,0). I am testing on a Galaxy S7 and I find it hard to believe that it doesn't support eye detection. I am open to a solution to this problem using OpenCV as well but I'd rather stick with the Android SDK since I can already detect the faces (if possible). Thank you for the assistance.
Not all devices support all the face features.
As the documentation states for leftEye and most of the other fields:
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.
Only the Face.rect and Face.score fields are guaranteed to be included if face detection is supported by the device.