简体   繁体   中英

Firebase ML Kit does not detect faces

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?

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 !

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM