Reputation: 51
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
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();
implementation 'com.google.firebase:firebase-ml-vision:24.0.3'
Upvotes: 0