pegnose
pegnose

Reputation: 51

Java - Android Mobile Vision face detection with contours

I am experimenting with the face detection of the Mobile Vision API. I am trying to get the facial landmarks' contours. But on building the FaceDetector it is giving me this exception:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.camera2tut, PID: 27106
    java.lang.IllegalArgumentException: Invalid build options

And the FaceDetector is telling me that "Contour is not supported for non-SELFIE mode." Here is my code for setting up the FaceDetector:

import com.google.android.gms.vision.face.FaceDetector;
[...]
mFaceDetector = new FaceDetector.Builder(this)
            .setTrackingEnabled(true)
            .setMinFaceSize((float)0.4)
            .setLandmarkType(FaceDetector.CONTOUR_LANDMARKS)
            .setClassificationType(FaceDetector.NO_CLASSIFICATIONS)
            .setProminentFaceOnly(true)
            .setMode(FaceDetector.ACCURATE_MODE)
            .build();

For the FaceDetector.Builder there is no option for setting a "selfie mode": https://developers.google.com/android/reference/com/google/android/gms/vision/face/FaceDetector.Builder

Althouth the FaceDetector has a constant SELFIE_MODE: https://developers.google.com/android/reference/com/google/android/gms/vision/face/FaceDetector

From the description of this constant, it seems that .setProminentFaceOnly(true) comes closest to the selfie mode, but it does not seem to enable it.

If I just detect the landmarks with .setLandmarkType(FaceDetector.ALL_LANDMARKS), the detector can be build. But how do I use this ominous "selfie" mode, how do I get the contours?

Upvotes: 2

Views: 1264

Answers (2)

SATYAJEET RANJAN
SATYAJEET RANJAN

Reputation: 141

Create your Detector like this:

new FaceDetector.Builder(ctx).setTrackingEnabled(true) //can be false too
.setLandmarkType(FaceDetector.CONTOUR_LANDMARKS)
.setMode(FaceDetector.SELFIE_MODE)
.setProminentFaceOnly(true)
.build();

Do let me know if full code is required to capture the contour points.
my gradle:
implementation 'com.google.firebase:firebase-ml-vision:24.0.3'

Upvotes: 0

hsienting
hsienting

Reputation: 71

Have you tried

.setMode(FaceDetector.SELFIE_MODE)

Upvotes: 1

Related Questions