Skip to content

Performing Dynamic Liveness estimation#

This topic describes how to implement user interactions with a camera in your app to perform the Dynamic Liveness estimation.

In LUNA ID for Android#

To perform the Dynamic Liveness interaction, do the following:

  1. Enable the estimation by creating a list of interactions.
  2. Specify optional parameters, such as:

Enable the estimation#

To enable the estimation, create a list of interactions. To do this, pass the Interactions argument to LunaID.showCamera(). For example:

LunaID.showCamera(
    interactions = Interactions.Builder().build()
)

In cases, when you specify Interactions.Builder().build() or do not specify the interactions parameters at all, an empty list of interactions will be created. This means no interactions will be included.

Interactions is a container for interaction parameters. You can add the following interactions to it:

Parameter Description
YawLeftInteraction Enables user interaction via rotating the head to the left along the Y axis.
YawRightInteraction Enables user interaction via rotating the head to the right along the Y axis.
PitchUpInteraction Enables user interaction via pitching the head up along the X axis.
PitchDownInteraction Enables user interaction via pitching the head down along the X axis.
BlinkInteraction Enables user interaction via blinking. See also Enable blinking with one eye.

Important notes:

  • You can specify each parameter only once.
  • The interaction parameters will be launched in the order you specify them in your code. If you do not specify the order, no interactions will be performed.

The interactions that you add to the list will be performed either in a random order or in a defined sequence.

Perform interactions in a random order#

To perform interactions in a random order, add required interaction types with Interactions.Builder().

Define an interaction sequence#

To define an interaction sequence, use the addInteraction method as shown in the example below:

LunaID.showCamera(
    interactions = Interactions.Builder()
    .addInteraction(YawLeftInteraction)
    .addInteraction(YawRightInteraction)
    .addInteraction(PitchUpInteraction)
    .addInteraction(PitchDownInteraction)
    .addInteraction(BlinkInteraction)
    .build()
)

Set an interaction timeout#

Each interaction has the timeoutMs parameter. It determines the time, in milliseconds, during which this interaction must be completed.

By default, the parameter value is 5 seconds.

Set a timeout between interactions#

You can set a timeout between interactions in milliseconds. This means that a new interaction will start after the preceding one ends after the specified timeout is passed.

To do this, use the LunaConfig.interactionDelayMs parameter.

By default, the parameter value is 0.

View interaction statuses#

LUNA ID for Android has the StateInteractionStarted and StateInteractionEnded statuses. The statuses inform you about an interaction start and successful end, respectively.

Specify head rotation angles#

Head pose interactions have the startAngleDeg and endAngleDeg parameters. If you do not specify them, the default values will be used.

Parameter

Interaction

Default value

Description

startAngleDeg

YawLeftInteraction

10

Specifies the start angle at which the user must rotate their head for the interaction to be considered successful.

YawRightInteraction

10

PitchUpInteraction

5

PitchDownInteraction

5

endAngleDeg

YawLeftInteraction

30

Specifies the end angle at which the user must rotate their head for the interaction to be considered successful.

YawRightInteraction

30

PitchUpInteraction

20

PitchDownInteraction

20

Enable blinking with one eye#

To enable blinking with one eye, set the acceptOneEyed parameter of the BlinkInteraction interaction to true. This allows users to perform blinking with one eye, rather than two.

By default, the acceptOneEyed parameter is set to false.

Important: The acceptOneEyed parameter requires the lunaid-common-x86-X.X.X.aar, lunaid-common-arm-X.X.X.aar dependencies. For details, see Distribution kit.

In LUNA ID for iOS#

To perform the Dynamic Liveness interaction, do the following:

  1. Enable the estimation.
  2. Specify a number of interactions.
  3. Optional. Define an interaction sequence.
  4. Specify optional parameters, such as:

Enable the estimation#

To enable user interactions with a camera, pass appropriate values for the livenessAPI and configuration parameters to the LMCameraBuilder.viewController camera controller instance creation function:

let controller = LMCameraBuilder.viewController(delegate: self,
                                                    configuration: LCLunaConfiguration,
                                                    livenessAPI: livenessAPI)
Parameter Description
configuration The parameter is represented by the LCLunaConfiguration structure. The LCLunaConfiguration → InteractionEnabled = true parameter is responsible for interaction with the camera.
livenessAPI The API should be of type LunaWeb.LivenessAPIv6.

The API accepts the configuration parameter, which contains all the necessary settings for performing Dynamic Liveness.

Specify a number of interactions#

The interaction generator produces a random sequence of interactions from the interaction types list.

You can specify a number of interactions to be performed. To do this, pass the stepsNumber parameter to the following property of the LCLunaConfiguration class:

@property (nonatomic, strong) LCInteractionsConfig *interactionsConfig;

Important:The number of interactions must not exceed 5.

Define an interaction sequence#

To define a user interaction sequence, use the LMCameraViewControllerProtocol::defineInteractionsStep method. For example:

let cameraViewController = LMCameraBuilder.viewController(delegate: self,
                                                          configuration: self.configuration,
                                                          livenessAPI: self.livenessAPI)
cameraViewController.defineInteractionsStep([
    LunaCore.LCBlinkConfig(),
    LunaCore.LCDownHeadTrackConfig(),
    LunaCore.LCUpHeadTrackConfig()
])
cameraViewController.dismissHandler = { [weak self] in
    self?.closeViewController(animated: true)
}
cameraViewController.modalPresentationStyle = .fullScreen
self.present(cameraViewController, animated: true)

You can define an array of LCStepConfigProtocol objects:

Object Description
LCBlinkConfig Enables user interaction via blinking.
LCUpHeadTrackConfig Enables user interaction via pitching the head up along the X axis.
LCDownHeadTrackConfig Enables user interaction via pitching the head down along the X axis.
LCLeftHeadTrackConfig Enables user interaction via rotating the head to the left along the Y axis.
LCRightHeadTrackConfig Enables user interaction via rotating the head to the right along the Y axis.

You can set a timeout for each interaction.

Set an interaction timeout#

You can set a timeout for every interaction to be performed in a random sequence. It determines the time, in seconds, during which an interaction must be completed.

To do this, pass the interactionTimeout parameter to the following property of the LCLunaConfiguration class:

@property (nonatomic, strong) LCInteractionsConfig *interactionsConfig;

By default, the parameter value is 5 seconds.

If an interaction was not completed within the allotted time, the "Interaction timeout" error appears.

Set a timeout between interactions#

You can set a timeout between interactions in seconds. This means that a new interaction will start after the preceding one ends after the specified timeout is passed.

To do this, use the LCLunaConfiguration.interactionsConfig.timeoutBetweenInteractions property.

By default, the property value is set to 0.

View interaction statuses#

You can find current interaction statuses from userInfo[NSStepStateKey] in the NSError object which you will receive in the bestshotError() delegate method. For example:

    func bestShotError(_ error: Error) {
        if ((error as NSError).code == BestShotError.NEED_TO_BLINK.rawValue) {
            print("blink interaction state <\((error as NSError).userInfo[NSStepStateKey] ?? 0)>")
        }
    }

The statuses inform you about an interaction start, being in progress, and successful end.

Specify head rotation angles#

For user interactions via head rotations, you can specify head rotation angles. For the default values, see Head rotation angles.