0

I am using Google Firebase's ML Kit to detect facial contours of images captured from the phone camera. However, it doesn't actually detect any faces. I've verified that the image was captured and saved properly from the camera by displaying the image in an ImageView. I also made sure to add

 <meta-data android:name="com.google.android.gms.vision.DEPENDENCIES" android:value="face"/>

to AndroidManifest.xml and

implementation 'com.google.firebase:firebase-ml-vision:24.0.1'
implementation 'com.google.firebase:firebase-ml-vision-face-model:19.0.0'

to the app's build.gradle.

Here's the Firebase code:

        FirebaseApp.initializeApp(context);
        FirebaseVisionFaceDetectorOptions realTimeOpts =
                new FirebaseVisionFaceDetectorOptions.Builder()
                        .setPerformanceMode(FirebaseVisionFaceDetectorOptions.ACCURATE)
                        .setContourMode(FirebaseVisionFaceDetectorOptions.ALL_CONTOURS)
                        .build();

        fbImage = FirebaseVisionImage.fromBitmap(portrait);


        FirebaseVisionFaceDetector detector = FirebaseVision.getInstance()
                .getVisionFaceDetector(realTimeOpts);

        Task<List<FirebaseVisionFace>> result =
                detector.detectInImage(fbImage)
                        .addOnSuccessListener(
                                new OnSuccessListener<List<FirebaseVisionFace>>() {
                                    @Override
                                    public void onSuccess(List<FirebaseVisionFace> faces) {

                                        Log.d(TAG, "No. Faces Detected: " + faces.size());


                                    }
                                })
                        .addOnFailureListener(
                                new OnFailureListener() {
                                    @Override
                                    public void onFailure(@NonNull Exception e) {
                                        Log.d(TAG, e.getMessage());
                                    }
                                });

Does anyone know why this might not be detecting anything?

cyborg48
  • 71
  • 8

2 Answers2

0

I've had this problem in the recent past. My solution was to declare specific faces. Then to use the manifest to declare all faces to be recognized. Here is the link to doing so:
Here's firebase-ml-kit!

Larson Carter
  • 153
  • 2
  • 11
0

It actually wasn't a problem with Firebase but rather a problem with the image. Apparently Samsung rotates the orientation of the captured image and Firebase couldn't detect the face since it was rotated 90 degrees. Fixed it by simply rotating the image back to portrait orientation. Captured Photo orientation is changing in android

cyborg48
  • 71
  • 8