1

https://developers.google.com/android/reference/com/google/android/gms/vision/face/FaceDetector.Builder

I'm using the above google service in my app for face detection. I made sure my phone has the minimum google play service version, which on my phone is 8.3, but still I can't get the face detection to work! I imported the library by importing the google play library in my eclipse project.... Here's the code:

           @Override
        protected void onPreExecute() 
        {
            detector = new FaceDetector.Builder(MainContext)
            .setTrackingEnabled(false)
            //.setProminentFaceOnly(true)
            .setLandmarkType(FaceDetector.ALL_LANDMARKS) //required
            .build();   
        }

private void detectTheFace(Bitmap converted) 
            {

                Frame frame = new Frame.Builder().setBitmap(converted).build();
                faces = detector.detect(frame);
             }   

I don't know if it's necessary to convert the bitmap you use to detect the faces has to be RGB_565 configuration but I did it anyways. I tried with and without changing the RGB configuration and it yields the same results. Basically the faces sparse array is of size 0 meaning it doesnt detect a face.... ever. Btw just to give some context on the above code, I'm executing the face detection in a async task because I want to run it on the background.

  • I'd suggest checking if the detector dependencies are ready and for the low storage condition. See the checks in the example code here: https://github.com/googlesamples/android-vision/blob/master/visionSamples/photo-demo/app/src/main/java/com/google/android/gms/samples/vision/face/photo/PhotoViewerActivity.java#L75 – pm0733464 Dec 07 '15 at 15:36
  • No that's not the problem but thanks for the suggestion. I checked it and the native libraries are downloaded and it still shows zero faces detected – Jonathan Vukadinovic Dec 08 '15 at 00:37
  • Are there any errors in the logs? You might check out the speed vs. accuracy discussion here: http://stackoverflow.com/questions/34132444/google-mobile-vision-poor-facedetector-performance-without-camerasource/34160783#34160783 – pm0733464 Dec 08 '15 at 16:21
  • There are no errors at all. I thought maybe the bitmap it was using to detect from wasn't correct but it's not I checked that too. So I'm snapshotting the camera preview and thought maybe it's coming out completely black but its not.... I see my face when I open the image – Jonathan Vukadinovic Dec 08 '15 at 17:01
  • Try displaying the image on your monitor and use the demo face tracker app (https://github.com/googlesamples/android-vision/tree/master/visionSamples/FaceTracker) on your phone to see if it can detect the face displayed. If it can, something's probably wrong with the image format, rotation, or settings used by your app. – pm0733464 Dec 09 '15 at 15:57
  • I tried another source code that is proven to work....I tried it and still 0 faces detected. Here's the interesting part, I tried it on my friend's phone and he has a nexus 6 (very new) and it works! It detects faces....He has a higher resolution so I'm thinking maybe it has to do with the size of image possibly.... – Jonathan Vukadinovic Dec 09 '15 at 17:08

2 Answers2

3

I have the same problem ,i.e. it was working fine on nexus but not in galaxy. I resolved the problem by rotating the bitmap to 90 degree in case detector.detect() method gives faces of zero size. so maximum retry is 3 times after calling detector.detect() because 4th rotation gives you the same bitmap.

Bitmap rotateBitmap(Bitmap bitmapToRotate) {

        Matrix matrix = new Matrix();

        matrix.postRotate(90);

        Bitmap rotatedBitmap = Bitmap.createBitmap(bitmapToRotate, 0, 0,
                bitmapToRotate.getWidth(), bitmapToRotate.getHeight(), matrix,
                true);
        return rotatedBitmap;

    } 

check if the face return by detector.detect() has zero size then below code should run.

if(!faces.size()>0){
if (rotationCounter < 3) {
                    rotationCounter++;
                   bitmap= rotateBitmap(bitmapToRotate);
//again call detector.detect() here
                                    }

}

you can check for the need of rotating bitmap without writing above code. From your original, code try to capture the image in landscape mode of phone or just rotate the image to 90 degree ans capture it.

Baqir
  • 717
  • 1
  • 7
  • 20
-1

To solve this problem, use the orientation specification from the EXIF of the photo.

pvdyck
  • 1
  • 1