Skip to main content

Pose Estimation (Active Liveness)

You can access the PoseEstimation module from the base Amani class as shown below.

caution

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.

KeyTypeDescription
faceIsOkStringShows before capturing the selfie
notInAreaStringShows when the user's face isn't aligned with the area
faceTooSmallStringShows when the user's face is too far
faceTooBigStringShows when the user's face is too close
completedStringShows when the process is complete
turnRightStringShows when the random pose is right
turnLeftStringShows when the random pose is left
turnUpStringShows when the random pose is up
turnDownStringShows when the random pose is down
lookStraightStringShows when the user's face isn't straight
errorMessageStringShows when the user has failed all the poses
tryAgainStringShows when the user is prompted to try again
errorTitleStringShows when the user has failed all the poses
nextStringNext pose message
holdPhoneVerticallyStringPrompts the user to hold the phone at the correct angle
wrongPoseStringShows when the user failed a pose
descriptionHeaderStringShows 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]

KeyTypeDescription
appBackgroundColorStringHex code without hash sign (#)
appFontColorStringHex code without hash sign (#)
primaryButtonBackgroundColorStringHex code without hash sign (#)
primaryButtonTextColorStringHex code without hash sign (#)
ovalBorderSuccessColorStringHex code without hash sign (#)
ovalBorderColorStringHex code without hash sign (#)
poseCountStringNumber in string
mainGuideVisibilityStringeither true or "false"
secondaryGuideVisibilityStringeither true or "false"
buttonRadiusStringNumber 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.

note

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")
])