Face recognition
Android
Warning: Android face module has changed its approach in the latest release (5.0.0-RC) and it does not longer use the concept of BiometricView.
The UX (visualization, feedback, etc) of the face recognition has been completely split up from the face recognition itself.
Initialisation
MobbIDFaceAPI
is the class you would use to register and/or verify an user using facial recognition.
Once you've completed the initial configuration, you need to create an instance of the Face API and configure it like this:
MobbIDFaceAPI faceAPI = new MobbIDFaceAPI.Builder()
.targetView(container, this)
.defaultCameraMode(MobbIDCameraMode.FRONT)
.securityRecognitionLevel(MobbIDSDKSecurityRecognitionLevel.SECURE)
.addFeedbackListener(feedbackListener)
.build();
These are the minimum required parameters for configuring the API.
Note:
.targetView(container, this)
: First param is the view where the API will draw the camera output. That view must be a ViewGroup like a FrameLayout for instance. The second param must be Activity's Context.
Additionally you can use other listeners:
.addCaptureSelfieListener(captureSelfieListener)
: This listener will return all images (Bitmap format on Android) used by recognition process to build the face biometric template. Use it by implementing this interface: MobbIDCaptureSelfieListener.addCaptureTemplateListener(captureTemplateListener)
: This listener will return the face biometric template generated by the recognition process. Use it by implementing this interface: MobbIDCaptureTemplateListener
You can check out more use examples in the source code distributed along with the MobbID SDK.
Make a recognition
Once the Face API is configured you can would start the recognition process:
MobbIDBaseAPI.MobbIDAPIRecognitionMode recognitionMode =
MobbIDBaseAPI.MobbIDAPIRecognitionMode.ENROLLMENT;
MobbIDSDKRecognitionParameters parameters = new MobbIDSDKRecognitionParameters();
parameters.setUserId(userId);
parameters.setSecurityKey(securityKey);
faceAPI.start(recognitionMode, parameters, operationListener);
Each mode (ENROLLMENT, VERIFICATION) would have different required parameters. Checkout the javadocs for more information.
You need to implement the specific OperationListener to receive the results of the recognition process. Each mode would have its specific listener:
── OperationListener
├── EnrollmentListener
└── VerificationEnrollmentListener
Enrollment
public class EnrollFaceActivity extends AppCompatActivity implements EnrollmentListener {
@Override
public void enrollmentFinished(final MobbIDAPIEnrollmentResult mobbIDAPIEnrollmentResult,
final MobbIDAPIEnrollmentResultData mobbIDAPIEnrollmentResultData,
final MobbIDAPIError mobbIDAPIError) {
if (mobbIDAPIEnrollmentResult == MobbIDAPIEnrollmentResult.OK) {
faceView.textStatusView.setText("Enrollment finish success!");
} else {
faceView.textStatusView.setText(mobbIDAPIError.getErrorCode().toString());
}
}
// ...
}
Verification
public class VerifyFaceActivity extends AppCompatActivity implements MobbIDVerificationListener {
@Override
public void verificationFinished(VerificationResult result, MobbIDVerificationResultData data,
MobbIDError errorOccurred) {
if (result == VerificationResult.USER_VERIFIED) {
faceView.textStatusView.setText("User verify success!");
} else if (result == VerificationResult.USER_NOT_VERIFIED) {
faceView.textStatusView.setText("User not verify");
} else {
faceView.textStatusView.setText(errorOccurred.getErrorCode().toString());
}
}
}
Liveness detection
You can protect against antispoofing attacks by enabling liveness detection in both enrollment and verification. Do it when instantiating the API.
MobbIDFaceAPI faceAPI = new MobbIDFaceAPI.Builder()
.targetView(container, this)
.defaultCameraMode(MobbIDCameraMode.FRONT)
.securityRecognitionLevel(MobbIDSDKSecurityRecognitionLevel.COMFORT)
.addFeedbackListener(feedbackListener)
.faceLivenessDetectionMode(MobbIDLivenessDetectionMode.HEAD_MOVEMENT)
.addLivenessStatusListener(livenessStatusListener)
.build();
You can currently use head movement detection (MobbIDLivenessDetectionMode.HEAD_MOVEMENT) or smile detection (MobbIDLivenessDetectionMode.SMILE_MOVEMENT).
UX
As previously stated, the visualization part of the face recognition process is completely splitted up from the recognition process itself.
With the latest release a new .aar named MobbIDSDK-Face-UX-Android.aar is also provided. It contains a FaceView
object that provides the default visualization you can see in the demos.
The FaceView
implements all necessary listeners to get all the information (provided by the MobbIDFaceAPI
) required to build a comprehensive UI that guides the user in the face recognition process. LivenessHeadFaceView
and LivenessSmileFaceView
provide the default UI for both liveness approaches.
Configuration
You need add this view in your activity layout:
<com.mobbeel.mobbid.face.ux.FaceView
android:id="@+id/face_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
And set this view like a feedback listener on API builder:
public class EnrollFaceActivity extends AppCompatActivity implements MobbIDEnrollmentListener {
private MobbIDFaceAPI faceAPI;
private FaceView faceView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_face);
faceView = findViewById(R.id.face_view);
configureAndInitAPI();
initMobbIDAPI();
}
private void configureAndInitAPI() {
MobbIDAPI.getInstance().setApiMode(MobbIDAPI.MobbIDAPIMode.ONLINE)
MobbIDAPI.getInstance().initAPI(LICENSE_KEY, this);
MobbIDAPI.getInstance().setBaseUrl(BASE_URL);
}
private void initMobbIDAPI() {
faceAPI = new MobbIDFaceAPI.Builder()
.targetView(container, this)
.defaultCameraMode(MobbIDCameraMode.FRONT)
.securityRecognitionLevel(MobbIDSDKSecurityRecognitionLevel.SECURE)
.addFeedbackListener(faceView)
.build();
}
// ...
}
If you enable liveness you need to use the appropriate view in your activity layout:
<com.mobbeel.mobbid.face.ux.LivenessHeadFaceView
android:id="@+id/face_view_liveness"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Further customisation
Source code of MobbIDSDK-Face-UX-Android.aar
is available if you want or need further customisation of the UI for your project. Request it to the support team.
You can also implement your own view to provide a complitely personlize experience. You only need your view these listener to build your UX:
- FeedbackListener: This listener provides information about the progress of the process, where the face is if you want to perform a tracking of the face, the current status of the process (if there is a problem with the lightning for instance), etc.
- LivenessStatusListener: This listener provides speficic information about the liveness process letting you know what action is required from the user next in order to complete the antispoofing check: turn face to left, to right, smile, etc.
iOS
The facial recognition for iOS still uses the BiometricView concept. You can check how it works here.
Note: Face framework for iOS will adapt the new approach made in Android in a future release.