Skip to main content

Selfie Pose Estimation Capture

Pose Estimation selfie creates a fragment that asks the user for random and certain number of head movements and confirms them with the customer observer pattern.

caution

In order to use this module, the noCompress option for tflite files must be set as shown below. Otherwise you'll get a compile errors.

aaptOptions {
noCompress "tflite"
}

Starting the Capture​

Creating the PoseEstimationObserver​

Before calling the Builder() you must create the PoseEstimationObserver to capture the events emitted from this module.

Add the imports below:

import ai.amani.sdk.modules.selfie.pose_estimation.observable.OnFailurePoseEstimation
import ai.amani.sdk.modules.selfie.pose_estimation.observable.PoseEstimationObserver
import android.graphics.Bitmap

Then create the PoseEstimationObserver as shown below:

  // Creating the observer to observe PoseEstimation events    
private val observer: PoseEstimationObserver = object : PoseEstimationObserver {
override fun onSuccess(bitmap: Bitmap?) {
// If bitmap is not null, selfie is taken successfully.
// The upload function can be called.
}

override fun onFailure(reason: OnFailurePoseEstimation, currentAttempt: Int) {
//Current pose is failed the reason is here
}

override fun onError(error: Error) {
//General exception during the process
}
}

Building the Fragment​

You can configure this module while creating the Fragment by using the included Builder() method.

note

The keepEyesOpenAndFaceStraight text field in userInterfaceTexts() is shown when an eye closure check is triggered during liveness detection. This feature must be enabled via remote configuration — contact the Amani team to activate it for your account.

Add the imports below:

import ai.amani.sdk.Amani

Then build the pose estimation Fragment as shown below:

val fragment = Amani.sharedInstance().SelfiePoseEstimation()
.Builder()
.requestedPoseNumber(1) //The amount of the random poses
.videoRecord(videoRecord = true) //Enables the video record
.ovalViewAnimationDurationMilSec(500)
.observe(observer)
.userInterfaceColors(
R.color.white,
R.color.approve_green,
R.color.error_red,
R.color.color_white,
R.color.white,
R.color.white,
R.color.color_pink,
R.color.white)
.userInterfaceTexts(
"Your face is not inside the area",
"Your face is not straight",
"Your face is too far from camera",
"Please keep straight the phone",
"Verification Failed",
"Failed",
"Try Again",
keepEyesOpenAndFaceStraight = "Please keep your eyes open and look straight at the camera"
)
.build(this)

Starting the Fragment​

You can navigate the fragment as shown below.

fragment?.let {
navigateToFragmentMethod(it)
}

Uploading the Captured Selfie​

caution

The upload method has to be called after the result of the observer is successful. Otherwise you'll encounter an error in the Errors() object as a result.

Add the imports below:

import ai.amani.sdk.Amani
import ai.amani.sdk.interfaces.IUploadCallBack

Then upload the captured selfie as shown below:

Amani.sharedInstance()
.SelfiePoseEstimation()
.upload(
requireContext(),
"type_of_document example: XXX_SE_0",
object : IUploadCallBack{
override fun cb(
isSuccess: Boolean
) {
//isSuccess means the Selfie Data is uploaded
//result is the result of uploaded document it should be equal "OK"
// if the current Selfie has no error
//If Selfie has errors, errors object will not be null anymore
}
}
)
note

A true result means the document reached the server, not that it was approved. Verification runs asynchronously on the backend, so the outcome arrives later through the event listener rather than here.

Alternatively, if you need the ID of the uploaded document, pass the uploadCallBack { ... } helper instead of the callback above. Everything else stays the same:

import ai.amani.sdk.interfaces.uploadCallBack

Amani.sharedInstance()
.SelfiePoseEstimation()
.upload(
requireContext(),
"type_of_document example: XXX_SE_0",
uploadCallBack { isSuccess, documentID ->
// isSuccess is true when the document is uploaded
// documentID is the ID of the uploaded document
}
)