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.
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"
}
Flow overviewFlowchart of this module's usage within the SDK flow. Expand to view it, click the chart to enlarge.
- P1: configure in
Application.onCreatewithDynamicFeature.SELFIE_POSE_ESTIMATION. - P2, P3: set the event listener with
AmaniEvent().setListener(...), then start the session. - P4: build the fragment with
SelfiePoseEstimation().Builder()and aPoseEstimationObserver; show it (null means: checkonError). Upload only afteronSuccess; ononFailure/onErrorstart the module again. - P5: upload the selfie. A successful upload goes on, the verdict arrives later. If the upload fails or the step is REJECTED, do not call
upload()again: the data is cleared after it. Open the selfie again (a new fragment, or the old one with your own fragment handling, e.g.popBackStack), capture, then upload, up to your own max attempt. - P6, P7: follow the verdicts in
stepsResult/profileStatus, and callfinishSession()at the end. - Other modules may come before or after the selfie, in the order your flow needs; the chart shows the selfie alone to keep it simple.
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.
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
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
}
}
)
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
}
)