VDPhotoSelfieCapture¶
Presentation¶
Today, the current solutions that exist in the market do not provide a safe alternative when capturing a person's face. Either because they are unable to know if the person is really alive, or simply because its functionality is too basic. VDPhotoSelfieCapture arises due to the necessity of a more advanced and safer selfie capture technique. The SDK captures a selfie image once a face has been recognized within the image. The capture is made automatically due to its face detection techniques. The images are done by the front camera of the device.
Some permissions are needed to use the framework:
- Camera
The SDK is localised in English and Spanish. By default English language is selected and the language is automatically switched to Spanish if the device locale is Spanish.
The SDK can be configured using a dictionary. All possible keys and values can be checked in Configuration.
Notes¶
If the live photo is activated, and the device is capable of it, check Liveness Check.
Specifications¶
- Android minimum SDK version: API Level 21 (Android 5) (mobile devices only).
- SDK compatible with Harmony OS.
- Supported platforms: 'arm64-v8a', 'armeabi-v7a', 'x86_64', 'x86'.
- SDK size: 2.4 MB (approx.).
-
Additionally, some dependencies will be needed. These are:
Artifact Size common-core-X.Y.Z.aar 232 KB common-core-jvm-X.Y.Z.jar 106 KB common-logger-X.Y.Z.aar 19 KB common-logger-firebase-X.Y.Z.aar (optional library) 15 KB common-image-processing.aar is available for different architectures so its final size is the result of adding the size of each of the supported architectures.
Architecture Size x86 8.8 MB x86_64 9.3 MB armeabi-v7a 7.1 MB arm64-v8a 8.0 MB (All sizes have been calculated with the Android Studio .aar analyzer)
- The image captured is the nearest resolution with a preferred aspect ratio of 16:9 and a pixel count of ~2.5Mp. This is an approached size which differs per mobile device. The size of the image on disk is around ~100KB. The capture format is JPEG.
Each mobile device on the market uses a unique software architecture. Thus, each mobile device does NOT install the full weight of the image processing library, but installs the part of the weight associated with its architecture. In fact, this process of dividing the weight according to the architecture also takes place when the APP is uploaded to the Play Store.
The integrator should not include anything in the app because Google Play will manage the complete APK (including all architectures) which size is bigger than individual ones. To separate that APK and show the user which is going to download the app it's real size based on the architecture the device is accessing to Google Play.
This is explained here (abis) and here (APK splits).
In case the integrator wants to check the different APK sizes, or just build for one architecture only. The following code can be added to the app gradle (as stated in the links provided):
splits {
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
universalApk true
}
}
Integration¶
- Create a new Android project.
- Import the framework (photo-selfie-capture.aar) as a module (New... > Module > Import .JAR/.AAR Package) into your app.
- Add the following dependency:
implementation project (":photo-selfie-capture")
(same name as aar) to the app gradle file. - Implement the Interface named
IVDPhotoSelfieCapture
. - Import the rest of .aar/jar the same way (only steps 2 and 3).
- Add the following dependencies to the app gradle file:
implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0" implementation 'androidx.exifinterface:exifinterface:1.3.7' implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23' implementation "org.jetbrains.kotlin:kotlin-reflect:1.9.23" implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3"
Disabling allowBackup¶
By default the SDK allows the application to participate in the backup infrastructure, this behaviour can be altered by
adding android:allowBackup="false"
to the application tag in the manifest file from the created application.
When this directive has been overridden tools:replace="android:allowBackup"
must be added to the application tag as
well, including adding the tools namespace xmlns:tools="http://schemas.android.com/tools"
to the manifest tag.
See this page for more details.
Example of use¶
// Add implementation of interface
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()) {
Map<String, String> configuration = new HashMap<>();
configuration.put("smartselfie", "NO");
////////////// Veridas' recommended configuration //////////////
configuration.put("backgroundcolor", "#80000D44");
configuration.put("continuebuttonbackgroundcolor", "#000D44");
configuration.put("selfiealive_arrow_color", "#000D44");
configuration.put("facedetectednotcenteredcolor", "#EB8D00");
configuration.put("facedetectedokcolor", "#53A335");
configuration.put("popupvalidationbackgroundcolor", "#000D44");
configuration.put("informativetextcolor", "#000D44");
configuration.put("selfiengaserroralerttitlecolor", "#000D44");
configuration.put("repeatbuttonbackgroundcolor", "#FFFFFF");
configuration.put("repeatbuttontextcolor", "#000D44");
configuration.put("tickcirclecolor", "#DCEFD4");
configuration.put("tickcolor", "#53A335");
configuration.put("selfietutorialbackgroundcolor", "#FFFFFF");
configuration.put("selfietutorialdescriptioncolor", "#000D44");
configuration.put("selfietutorialstepbuttonnexttextcolor", "#000D44");
configuration.put("selfietutorialcurrentpointcolor", "#000D44");
configuration.put("selfietutorialstepbuttonprevioustextcolor", "#000D44");
configuration.put("selfietutorialcontinuebuttonfirstgradientcolor", "#000D44");
configuration.put("selfietutorialcontinuebuttonsecondgradientcolor", "#000D44");
configuration.put("selfietutorialsteptitlecolor", "#000D44");
configuration.put("orientationbackgroundcolor", "#80000D44");
configuration.put("checkselfiebackgroundcolor", "#FFFFFF")
configuration.put("checkselfietextcolor", "#000D44")
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() {
// Do whatever you want when SDK is finished.
}
...
@Override
public void VDPhotoSelfieAndFaceCaptured(ByteArrayInputStream selfie, ByteArrayInputStream face) {
// (DEPRECATED) Do with ByteArrayInputStream as needed.
}
@Override
public void VDPhotoSelfieAndFaceCaptured(byte[] selfie, byte[] face) {
// Do with bytes as needed.
}
...
@Override
public void VDPhotoSelfieAndFaceCapturedWithLiveDetection(ByteArrayInputStream selfieByteArray, ByteArrayInputStream faceByteArray) {
// (DEPRECATED) Do with ByteArrayInputStream as needed.
}
@Override
public void VDPhotoSelfieAndFaceCapturedWithLiveDetection(byte[] selfieByteArray, byte[] faceByteArray) {
// Do with bytes as needed.
}
}
Workflow¶
The next diagram represents de current workflow of the framework. Some method's names may be shortened due to legibility issues.
Logging events¶
The SDK logs various events, please refer to Logging Events to learn more about this subject.
Third party libraries¶
- OpenCV 4.1.0 (main page. documentation). Library used for image manipulation.
- Firebase: storage 20.0.0 (main page). Used for logging purposes. Only needed when using the VDLoggerFirebase library.
- Google Vision 20.1.0 (main page). Used for smile detection.