10

So basically, i have this code,

        if(mCamera.getParameters().getMaxNumDetectedFaces()==0)
        {
            System.out.println("Face detection not avaliable");
        }
        else
        {
            System.out.println("Max faces: " + Integer.toString(mCamera.getParameters().getMaxNumDetectedFaces()));
        }

        mCamera.setFaceDetectionListener(new FaceDetectionListener() {

            @Override
            public void onFaceDetection(Face[] faces, Camera camera) {
                // TODO Auto-generated method stub
                System.out.println("Face detection callback called." + Integer.toString(faces.length));


            }


        });

After calling mCamera.startFaceDetection();, the callback is called, everything works as normal. However, if I change cameras, the same code results in the callback never being called. The getMaxNumDetectedFaces, returns 35 for both cameras, so I assume its supported on the front camera. I can change the camera back and forth, calling this code each time, and it will work for the back camera but not the front one.

Is there anything else I might be doing wrong?

Kratz
  • 4,280
  • 3
  • 32
  • 55
  • Did you figure this out? I'm seeing the same thing. – Liron Dec 30 '13 at 13:22
  • just checking if you figured this out. I have the same behavior on my Motorola XT910 and I'm wondering if I need to try it on a different device or if it's a problem with my code on all devices. – Liron Jan 20 '14 at 09:56

4 Answers4

1

Is it possible that the quality of the camera that's not working (the front one, right?) Isn't accurate enough for the face detection to work? The camera's image may be too noisy for the face detector to work. There are lot of other variables that could be hindering this.

Also doing a search for front camera, it looks like the front camera's points may be mirrored. This is described in: http://developer.android.com/reference/android/hardware/Camera.Face.html

I hope this helps.

lordoku
  • 908
  • 8
  • 22
0

Is there a way to check if the camera is being read? Java has always had some issues in registering web cams etc.... Perhaps try to make sure you can see images with the webcam.

Btw, if you want any further help, we will need to know more about the code. library etc....

msj121
  • 2,812
  • 3
  • 28
  • 55
  • Yes, the camera is being read, it shows the preview on screen. I think you might be confused. You say webcam, but this is android, the cameras are part of the device. The library is just the standard Android SDK. – Kratz Nov 26 '12 at 02:53
0

This code will return the id of your Front facing camera, for others you can change camera.CameraInfo:

    private int findFrontFacingCamera() {
    int cameraId = -1;
    // Search for the front facing camera
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {

            Log.d("FaceDetector", "Camera found");
            cameraId = i;
            break;
        }
    }
    return cameraId;
}

I had the code which worked on my Gallaxy tablet but it wouldnt call the take foto and as a result wouldnt call face detection in other devices, so after searching for a while I found this solution which worked. I added the following code in the class where takePicture is called :

    camera.startPreview();
yav dat
  • 98
  • 1
  • 10
-3

You can use Webcame for capturing image from webcam. it automatically detects webcam so no need to extra configuration for webcam. it also support more than one webcam at a time.