Liveness detection¶
There are two selfie alive modes, Selfie Alive and Selfie Alive Pro. The goal of both is to verify the user identity and detect if you are alive with an active challenge.
The selfie alive PRO process will not work without a token provided by the Veridas endpoint /challenges/generation. If the token is not passed to the configuration it will fall back to Selfie Alive.
Selfie Alive¶
If the live photo is activated, and the device is capable of it, there will be two possible images to send to server from two delegated methods.
To activate the Selfie Alive process is necessary to configure "livephoto" key to "YES".
The image received by the VDPhotoSelfieAndFaceCapturedWithLiveDetection method is appropriate for biometric verification. The image received by the VDPhotoSelfieAndFaceCaptured method is appropriate for authenticity verification.
Recognition | Selfie Alive |
---|---|
Selfie Alive Pro¶
Selfie Alive Pro process consists in doing a challenge with several movements in different directions. It is stronger than Selfie Alive process because of the challenge.
To activate the Selfie Alive Pro process it is necessary configure "livephoto" key to "YES" and "jwstoken" with a challenge token. This token must be retrieved from the backend (the call /challenges/generation gets a string with the "jwstoken" configuration) and introduced to the SDK before it is started.
The delegated methods of Selfie Alive Pro are:
- VDPhotoSelfieAndChallengeVideoCaptured This method delegates the challenge video in mp4 format, resolution of 1280x720 and with an approximate size of 0.7MB for a 10 seconds video. The file is in WebVtt format and describes the completed process and has to be sent to the backend too.
- VDPhotoSelfieAndFaceCaptured As Photo Selfie process.
- VDPhotoSelfieChallengeFinishedWithError This method is delegated when the process fails. In this case it is posible to update the required challenge with the public method VDPhotoSelfieCapture.updateChallenge("other challenge");, otherwise case the users second attempt will be done with the same challenge.
Recognition | Selfie Alive Pro |
---|---|
Integration¶
- Inside app's build.gradle file add the following extra dependencies:
implementation 'com.google.mlkit:face-detection:16.1.1' implementation 'com.google.code.gson:gson:2.8.6'
Devices with or without Google Play Services¶
Most Android devices come with support for the Google Play Services but there are some which do not, such as some devices from Huawei which uses Harmony OS.
By default Veridas has included the dependency which includes the models otherwise downloaded from the Google Play Services. However, this increases the size of the final app bundle.
In order to save space, Google offers another version of the MLKit without these models included, these will be downloaded when the SDK starts.
To use the version without the models, the line
implementation 'com.google.mlkit:face-detection:16.1.1'
Must be substituted with
implementation 'com.google.android.gms:play-services-mlkit-face-detection:16.2.0'
in the apps build.gradle
file.
Example of use¶
// Add interface implementation
public class SomeClass implements VDPhotoSelfieCapture.IVDPhotoSelfieCapture {
...
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
// Start SDK.
if (!VDPhotoSelfieCapture.isStarted()) {
// Selfie Alive smile
Map<String, String> configuration = new HashMap<>();
configuration.put("livephoto", "YES");
VDPhotoSelfieCapture.start(this, getApplicationContext(), configuration);
// Selfie Alive Pro
Map<String, String> configuration = new HashMap<>();
configuration.put("livephoto", "YES");
configuration.put("jwstoken", "token retrieved from the backend...");
VDPhotoSelfieCapture.start(this, getApplicationContext(), configuration);
}
}
...
// In another place you can stop the process (not recommended).
private boolean someMethod() {
// Stop it whenever you want.
VDPhotoSelfieCapture.stop(someContext);
}
...
// Interface method
@Override
public void VDPhotoSelfieFinished() {
// SELFIE ALIVE PRO
// Send the data to: /challenges/video-photo with the following parameters in the body:
// token: the token provided by the server,
// video: the video data retrieved in vdPhotoChallengeVideoCaptured,
// annotations: the file data retrieved in vdPhotoChallengeVideoCaptured,
// selfie: the face data retrieved in vdPhotoSelfieCaptured.
}
...
@Override
public void VDPhotoSelfieAndFaceCaptured(ByteArrayInputStream selfie, ByteArrayInputStream face) {
// Do with ByteArrayInputStream as needed.
// If the levelquality is set to "high" the byteArray is compressed at 85% and if it is set to "medium" is compressed at 70%.
}
...
@Override
public void VDPhotoSelfieAndFaceCapturedWithLiveDetection(ByteArrayInputStream selfieByteArray, ByteArrayInputStream faceByteArray) {
// In case the configuration for "livephoto" is "YES", this is a picture of the person with a more natural pose but with lower quality.
}
// (Selfie Alive Pro) In case the configuration for "livephoto" is "YES" and the "jwstoken" is configured correcty.
@Override
public void VDPhotoSelfieAndChallengeVideoCaptured(ByteArrayInputStream challengeVideo, String challengeWebVTT) {
}
// (Selfie Alive Pro) In case of Selfie Alive Pro error.
@Override
public void VDPhotoSelfieChallengeFinishedWithError() {
// Proceed as needed, example ask for a new challenge and update it in the sdk with VDPhotoSelfieCapture.setChallenge("other challenge")
}
}
Workflow¶
The next diagram represents de current Alive workflow of the framework. Some method's names may de shortened due to legibility issues.
Alive Pro Workflow¶
The next diagram represents de current Alive Pro workflow of the framework. Some method's names may de shortened due to legibility issues.