Pose Estimation (Active Liveness)
You can access the PoseEstimation
module from the base Amani
class as shown below.
Before using this module please make sure you've initialized the SDK correctly.
let amaniPoseEstimation = Amani.sharedInstance.poseEstimation()
Configuration
Configuring the messages
These are the messages that you can configure. You can use this table with a
dictionary in [poseState: String]
type.
Key | Type | Description |
---|---|---|
faceIsOk | String | Shows before capturing the selfie |
notInArea | String | Shows when the user's face isn't aligned with the area |
faceTooSmall | String | Shows when the user's face is too far |
faceTooBig | String | Shows when the user's face is too close |
completed | String | Shows when the process is complete |
turnRight | String | Shows when the random pose is right |
turnLeft | String | Shows when the random pose is left |
turnUp | String | Shows when the random pose is up |
turnDown | String | Shows when the random pose is down |
lookStraight | String | Shows when the user's face isn't straight |
errorMessage | String | Shows when the user has failed all the poses |
tryAgain | String | Shows when the user is prompted to try again |
errorTitle | String | Shows when the user has failed all the poses |
next | String | Next pose message |
holdPhoneVertically | String | Prompts the user to hold the phone at the correct angle |
wrongPose | String | Shows when the user failed a pose |
descriptionHeader | String | Shows when the screen has started |
var infoMessages: [poseState: String] = [
.faceIsOk: "Please hold stable",
.notInArea: "Please align your face with the area",
.faceTooSmall:"Your face is too far",
.faceTooBig: "Your face is too close",
.completed: "All done!",
.turnRight: "→",
.turnLeft: "←",
.turnUp: "↑",
.turnDown: "↓",
.lookStraight: "Look straight",
.errorMessage : "Please complete the steps without leaving your face outside the area",
.tryAgain: "Try again",
.errorTitle : "Failed",
.next: "Next",
.holdPhoneVertically: "Please hold your phone at correct angle",
.wrongPose: "Your face should match up with the pose",
.descriptionHeader: "Please align your face with the area and do the poses that will be showed on screen",
]
After creating the dictionary, you can call the setInfoMessages
function with it.
amaniPoseEstimation.setInfoMessages(infoMessages: infoMessages)
Configuring the screen
As much as you can change the info messages, you can also change the on screen and also the count timer. These are the keys that we have for configuration.
With the keys below you can create a dictionary with type of [poseConfigState: String]
Key | Type | Description |
---|---|---|
appBackgroundColor | String | Hex code without hash sign (#) |
appFontColor | String | Hex code without hash sign (#) |
primaryButtonBackgroundColor | String | Hex code without hash sign (#) |
primaryButtonTextColor | String | Hex code without hash sign (#) |
ovalBorderSuccessColor | String | Hex code without hash sign (#) |
ovalBorderColor | String | Hex code without hash sign (#) |
poseCount | String | Number in string |
mainGuideVisibility | String | either true or "false" |
secondaryGuideVisibility | String | either true or "false" |
buttonRadius | String | Number in string |
var screenConfig: [poseConfigState: String] = [
.appBackgroundColor: "000000",
.appFontColor: "ffffff",
.primaryButtonBackgroundColor: "ffffff",
.primaryButtonTextColor:"",
.ovalBorderSuccessColor: "00ff00",
.ovalBorderColor: "ffffff",
.poseCount: "2",
.mainGuideVisibility: "true",
.secondaryGuideVisibility: "true",
.buttonRadius:"10"
]
After creating the dictionary you can call setScreenConfig
with it.
amaniPoseEstimation.setScreenConfig(screenConfig: screenConfig)
Starting the Auto Selfie Capture
The start
method will return an instance of UIView
self.poseEstimationSelfieView = amaniPoseEstimation.start() {[weak self] previewImage in
// after the process ends you can safely remove the autoSelfieView from your view controller
DispatchQueue.main.async {
self?.poseEstimationSelfieView.removeFromSuperView()
}
// TODO: upload or show a confirm screen
}
// don't forget to add the pose estimation selfie view to your view controller
DispatchQueue.main.async {
self.view.addSubView(self.poseEstimationSelfieView)
}
Upload
After completing the capture process you can call the upload as shown below.
amaniPoseEstimation.upload(location: nil) {[weak self] uploadSuccess in
if (uploadSuccess != nil) {
// uploadSuccess is a boolean variable
// TODO: handle the upload state
}
}
Changing the guide images
There are two seperate guide images that you can show up in the screen. To change these images, you can use the setMainGuideImages
and setSecondaryGuideImages
functions.
Main guide images shows up in the center, while the secondary guide images shows up at bottom.
To change the visibility of the guide images, you can set mainGuideVisibility
and secondaryGuideVisibility
keys with "true"
or "false"
.
Setting the main guide images
amaniPoseEstimation.setMainGuideImages(guideImages: [
.mainGuideUp: UIImage(named: "face_up"),
.mainGuideDown: UIImage(named: "face_down"),
.mainGuideLeft: UIImage(named: "face_left"),
.mainGuideRight: UIImage(named: "face_right"),
.mainGuideStraight: UIImage(named: "face_straight")
])
Setting the secondary guide images
poseEstimation.setSecondaryGuideImages(guideImages: [
.secondaryGuideUp: UIImage(named: "arrow_up"),
.secondaryGuideDown: UIImage(named: "arrow_down"),
.secondaryGuideRight: UIImage(named: "arrow_right"),
.secondaryGuideLeft: UIImage(named: "arrow_left")
])