CameraXMrzScanner
Runs CameraX on Android and streams MrzScanResults from analysed frames.
It binds an ImageAnalysis use case to lifecycleOwner with the keep-only-latest strategy, and closes every frame after analysis. Frames that arrive while one is being analysed are dropped, so results are not one per frame. The scanner creates no preview unless you call enablePreview. The caller must hold the CAMERA permission before start; the scanner reports CameraError.PermissionDenied and never requests it.
A CameraError.PermissionDenied or a critical CameraError.CameraUnavailable ends the session. A CameraError.CameraInUse, and a CameraError.CameraUnavailable reported while CameraX is retrying, leave the session bound; the stream resumes when the camera recovers. A CameraError.OcrFailed covers one frame. Close the scanner to release the analysis executor and the recognizer.
Threads: results and surfaceRequest emit on the main thread. Recognition (the MrzTextRecognizer, the ML Kit band crop, parsing) runs on a background thread (Dispatchers.Default), never on the main thread. CameraX binds and unbinds on the main thread. The main thread must be free to run its queue (an app's UI thread always is).
Since
0.2.0
Parameters
an application Context, used to look up the camera provider. Pass context.applicationContext.
the lifecycle the camera session is bound to. CameraX also starts and stops the camera as this lifecycle moves.
the OCR engine. The default is MlKitMrzTextRecognizer. The scanner closes a recognizer that is AutoCloseable when it is closed.
how tolerant candidate extraction is of OCR formatting noise. The default is ParsingMode.STRICT.
where per-frame CameraFrameEvents go. The default is the registered sink (TelemetrySinkRegistry.current), or NoOpTelemetrySink when none is registered.
which lens to use. The default is the back camera.
Constructors
Properties
Results for analysed frames and capture errors, delivered on the main thread.
The CameraX SurfaceRequest of the live preview, or null when no preview is active.
Functions
Arms the live preview for later start calls.
Turns the torch of the active camera on or off.