Camerax image analysis not giving proper image in wide angle cameras

178 views Asked by At

I am trying to analyse the image using CameraX. Some devices with a wide-angle camera do not provide proper images. The image in the analyser is entirely different from the image in the preview. I am using an aspect ratio of 4:3 in both the preview and image analyser. I am cropping the image based on the cropRect coming from the image proxy.

Please see the code snippet for the image analyser below. This issue can be reproduced on Samsung A23 devices.


val myPreview = Preview.Builder().setTargetAspectRatio(AspectRatio.RATIO_4_3)
                .build().also {
                    it.setSurfaceProvider(myPreviewView.surfaceProvider)
                }


val myImageAnalyzer = ImageAnalysis.Builder()
  .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
  .setTargetAspectRatio(AspectRatio.RATIO_4_3)
  .build()
                .also {
                    it.setAnalyzer(executer, MyImageAnalyser() { result ->
                    })
                }


Preview Image

Image shown in the preview

Image from analyser

Image in the analyser after remove cropRect

This issue can be reproducible in google sample as well with wide angle camera devices. eg:- Samsung A23

When I replace aspect ratio with resolution it is start working. Not sure what is root cause with aspect ratio.

val myPreview = Preview.Builder().setTargetResolution(Size(1280, 720))
                .build().also {
                    it.setSurfaceProvider(myPreviewView.surfaceProvider)
                }


val myImageAnalyzer = ImageAnalysis.Builder()
  .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
  .setTargetResolution(Size(1280, 720))
  .build()
                .also {
                    it.setAnalyzer(executer, MyImageAnalyser() { result ->
                    })
                }


0

There are 0 answers