Getting the best shot#
With LUNA ID, you can capture video stream and get the best shot on which the face is fixed in the optimal angle for further processing.
Tip: In LUNA ID for Android you can specify a face recognition area for best shot selection.
In LUNA ID for Android#
1․ Initialize the camera.
Call the LunaID.showCamera()
method to start the camera session. This method initiates face detection and analysis within the video stream.
2․ Get the list of best shots.
This step is optional. Implement it, if you want to get multiple best shots during a session. You can then send the list of acquired best shot to the backend for estimation aggregation. For details, see Sending multiple frames for estimation aggregation to the backend.
2.1. Set the LunaConfig.multipartBestShotsEnabled
parameter to true
to get multiple frames.
2.2. Specify the number of best shots to be returned by setting the LunaConfig.bestShotsCount
parameter. The valid range of values for bestShotsCount
is from 1 to 10.
When multipartBestShotsEnabled
is active, the list of best shots will be returned in the BestShotsFound
event. Use the bestShots
Flow to collect this list.
Structure of BestShotsFound
:
data class BestShotsFound(
val bestShots: List<BestShot>?
) : Event()
Usage example:
LunaID.bestShots.filterNotNull().onEach { bestShotsList ->
Log.e(TAG, "bestShots: ${bestShotsList.bestShots}")
}.launchIn(viewModelScope)
This Flow continuously gets a list of best shots as they are detected during the session.
3․ Subscribe to the final best shot result.
To retrieve the final best shot result (including metadata such as videoPath
and interactionFrames
), subscribe to the LunaID.bestShot
Flow.
Structure of BestShotFound
:
data class BestShotFound(
val bestShot: BestShot, // The selected best shot
val videoPath: String?, // Path to the recorded video (if enabled)
val interactionFrames: List<InteractionFrame>? // Frames with Dynamic Liveness interactions (optional)
) : Event()
Usage example:
val bestShotFlow = MutableStateFlow<Event.BestShotFound?>(null)
LunaID.bestShot.filterNotNull().onEach { bestShotFound ->
Log.e("BestShotFound", bestShotFound.toString())
// Process the best shot or its associated metadata here
}.launchIn(viewModelScope)
4․ Handle best shot events.
The system gets events for both individual best shots (BestShotFound
) and lists of best shots (BestShotsFound
). Depending on your use case, handle these events accordingly:
BestShotFound
-
Contains the final best shot and optional metadata.
Use this for single-best-shot scenarios. BestShotsFound
-
Contains a list of all best shots detected during the session.
Use this for multi-best-shot scenarios.