-
Notifications
You must be signed in to change notification settings - Fork 14
Image analyzer
Lucas Yuji Yoshimine edited this page Dec 14, 2023
·
4 revisions
To use image analyzer, your hardware must be level 3, you can check using this:
val cameraState = rememberCameraState()
// returns if image analysis is supported or not
cameraState.isImageAnalysisSupported
To initialize imageAnalyzer, add CameraState
to use a image analyzer remember:
val cameraState = rememberCameraState()
val imageAnalyzer = cameraState.rememberImageAnalyzer(
imageAnalysisBackpressureStrategy = ImageAnalysisBackpressureStrategy.BlockProducer, // optioanl, default is ImageAnalysisBackpressureStrategy.KeepOnlyLatest
imageAnalysisTargetSize = ImageAnalysisTargetSize(AspectoRatio.RATIO_16_9), // optional, default it's from cameraX's library
imageAnalysisImageQueueDepth = 4, // optional, default is 6, from cameraX's library,
analyze = { imageProxy -> /* code... */ } // image analyze callback
)
CameraPreview(
cameraState = cameraState,
imageAnalyzer = imageAnalyzer
)
Use this with you want to handle with camera operation Mode, the default is KeepOnlyLatest.
- BlockProducer: add multiple images to the internal image queue and begin dropping frames only when the queue is full, used for blocking operation.
- KeepOnlyLatest: always caches the latest image, used for non-blocking operation.
addition: to more information, see CameraX docs.
Intermediate of CameraController.OutputSize, is used to target a resolution/size to image analysis. The constructors accept AspectoRatio and Size.
Sets the number of images available to the camera pipeline for ImageAnalysisBackpressureStrategy.BlockProducer mode.
Callback from image analysis, there's an example using QRCode reader on Sample Project.