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 from analyser
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 ->
})
}