Skip to content

Image analyzer

Lucas Yuji Yoshimine edited this page Dec 14, 2023 · 4 revisions

Image Analyzer

Requirements

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 

How to use

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
)

Properties

imageAnalysisBackpressureStrategy

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.

imageAnalysisTargetSize

Intermediate of CameraController.OutputSize, is used to target a resolution/size to image analysis. The constructors accept AspectoRatio and Size.

imageAnalysisImageQueueDepth

Sets the number of images available to the camera pipeline for ImageAnalysisBackpressureStrategy.BlockProducer mode.

analyze

Callback from image analysis, there's an example using QRCode reader on Sample Project.