I have been trying to launch face detection on Google Glass. It is supposed to run realtime as I want to trigger a custom method if there are faces on camera sight. Unfortunately it always detects zero faces. I want to start the detection as soon as my application starts, therefore I start face recognition on surface creation:
@Override
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
this.setCameraParameters(camera);
try {
camera.setPreviewDisplay(this.getHolder());
} catch (IOException e1) {
Log.e("surface created", e1.getMessage());
}
camera.startPreview();
try {
camera.setPreviewDisplay(holder);
CameraManager manager = new CameraManager(this, camera);
manager.startFaceRecognition();
} catch (Exception e) {
this.releaseCamera();
}
}
The implementation of manager.startFaceRecognition:
public void startFaceRecognition() {
...
camera.setFaceDetectionListener(new FaceDetectionTriggeringListener());
}
It is the same camera object as I pass it to constructor. The implementation of face detection listener:
public class FaceDetectionTriggeringListener implements FaceDetectionListener {
@Override
public void onFaceDetection(Face[] faces, Camera camera) {
if (faces.length > 0) {
Log.d("onFaceDetection", Integer.toString(faces.length));
}
for (Face face : faces) {
Log.d("onFaceDetection", Integer.toString(face.score));
}
}
}
In the last code part faces.length
is always zero and nothing is logged. I have tried logging faces.length
, it really outputs zero. I have tried different faces including my project manager and pictures from google searches.
Please note that I want to do this in realtime and I do not need ultimate accuracy. I have tried methods that include picture transcoding, but they are too slow and uses too much CPU and, as a consequence, this gets Glass hot and drains battery heavily. The goal is to write something like this:
if (faces.length > 0){
Foo.bar();
}
Is there any solution to this problem? Alternative solutions are accepted in case they can work in realtime.