Skip to content

Working with the camera#

Applies to LUNA ID for Android only.

This section describes how to launch the camera, configure its parameters, define Dynamic Liveness interactions, and send commands.

Launching the camera#

Use the showCamera function to start the camera activity:

@JvmOverloads
    fun showCamera(
    context: Context,
    params: ShowCameraParams = ShowCameraParams(),
    interactions: Interactions = Interactions(),
    commands: Commands = Commands()
)
Parameter Description
context: Context Context for launching the camera activity.
params: ShowCameraParams Camera display and behavior parameters.
interactions: Interactions List of user interactions for Dynamic Liveness.
commands: Commands Commands to control the camera programmatically.

Example#

val params = ShowCameraParams(
    recordVideo = false,
    checkSecurity = true,
    minFaceSideToMinScreenSide = 0.3f
)

val interactions = Interactions.Builder() 
    .addInteraction(BlinkInteraction(timeoutMs = 5000)) 
    .addInteraction(YawLeftInteraction(timeoutMs = 5000)) 
    .build()

LunaID.showCamera( 
    context = this, 
    params = params, 
    interactions = interactions
)

ShowCameraParams#

ShowCameraParams lets you configure various camera options, such as video recording, security checks, face detection thresholds, and resolution settings.

Parameter Type Default value Description
disableErrors Boolean true Enables or disables error messages.
logToFile Boolean false Enables or disables saving logs to a file.
recordVideo Boolean false Enables or disables video recording.
recordingTimeMillis Long 0 Limits a video stream's duration in milliseconds. The parameter is mandatory if recordVideo is set to true.
ignoreVideoWithoutFace Boolean true Specifies whether to record a video stream only with the face detected.
borderDistanceStrategy BorderDistancesStrategy Not set Defines the strategy to be used to specify face recognition area borders.
autoFocus Boolean true Enables continuous autofocus.
checkSecurity Boolean false Enables or disables the virtual camera usage check.

| minFaceSideToMinScreenSide | Float | 0.3f | Defines the minimum allowable size of a detected face , expressed as a proportion of the smallest screen dimension. The face size is calculated relative to the preview image dimensions, not the full-resolution frame. Value range: [0.0..1.0]. | | cameraSelector | CameraSelector | Front camera | Specifies which physical camera to use: front (DEFAULT_FRONT_CAMERA) or rear (DEFAULT_BACK_CAMERA). | | previewResolutionSelector | ResolutionSelector | Not set | Sets the resolution of the video stream displayed on the device screen (UI preview). | | analysisResolutionSelector | ResolutionSelector | Not set | Defines the resolution of frames sent to the LUNA ID detector for facial analysis (for example, liveness, attribute estimation). | | videoQualitySelector | QualitySelector | Not set | Determines the quality of the recorded video output. Possible values: SD, HD, FHD, UHD. |

Example#

val params = ShowCameraParams(
    recordVideo = true,
    recordingTimeMillis = 5000,
    checkSecurity = false,
    minFaceSideToMinScreenSide = 0.25f,
    cameraSelector = CameraSelector.DEFAULT_FRONT_CAMERA
)

Interactions#

The Interaction class defines user interactions required for Dynamic Liveness estimation.

Interaction types#

BlinkInteraction#

Interaction type Description Example
BlinkInteraction Enables user interaction via blinking. See also Enable blinking with one eye.
BlinkInteraction(
    timeoutMs: Int = 5000,
    acceptOneEyed: Boolean = false
)
YawLeftInteraction Enables user interaction via rotating the head to the left.
YawLeftInteraction(
    timeoutMs: Int = 5000,
    startAngleDeg: Int = 10,
    endAngleDeg: Int = 30
)
YawRightInteraction Enables user interaction via rotating the head to the right.
YawRightInteraction(
    timeoutMs: Int = 5000,
    startAngleDeg: Int = 10,
    endAngleDeg: Int = 30
)
PitchUpInteraction Enables user interaction via tilting the head upward.
PitchUpInteraction(
    timeoutMs: Int = 5000,
    startAngleDeg: Int = 5,
    endAngleDeg: Int = 20
)
PitchDownInteraction Enables user interaction via tilting the head downward.
PitchDownInteraction(
    timeoutMs: Int = 5000,
    startAngleDeg: Int = 5,
    endAngleDeg: Int = 20
)

Example#

val interactions = Interactions.Builder()
    .addInteraction(BlinkInteraction(timeoutMs = 5000))
    .addInteraction(YawLeftInteraction(timeoutMs = 5000))
    .addInteraction(YawRightInteraction(timeoutMs = 5000))
    .build()

Commands#

Commands allow you to control the camera programmatically. Use Commands.Builder to override or add commands.

The following commands are available:

Command Description
CloseCameraCommand Closes the camera.
StartBestShotSearchCommand Starts the best shot search.

Example#

val commands = Commands.Builder()
    .override(StartBestShotSearchCommand)
    .build()

Sending a command#

LunaID.sendCommand(CloseCameraCommand)