Image from Image Analysis is corrupted on Moto G9

336 views
Skip to first unread message
Assigned to trevor...@google.com by wuj...@google.com

Vikram Mittal

unread,
Mar 8, 2021, 2:56:33 AM3/8/21
to Android CameraX Discussion Group
Hi,

I have initialised the fullscreen camera using the below code, which is working fine in the other mobile phones except Moto G9.

...
private val targetResolution = Size(1080, 1920)
...
cameraExecutor = Executors.newSingleThreadExecutor()
binding.previewView.post startCamera() }
...

private fun startCamera() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(requireContext())
val cameraSelector =
CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build()
cameraProviderFuture.addListener({
val cameraProvider = cameraProviderFuture.get()

imagePreview = Preview.Builder().apply {
setTargetResolution(targetResolution)
setTargetRotation(binding.previewView.display.rotation)
}.build()

imageAnalysis = ImageAnalysis.Builder().apply {
setTargetResolution(targetResolution)
setTargetRotation(binding.previewView.display.rotation)
setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
}.build().also {
scannerAnalyzer = ScannerAnalyzer(args, this)
it.setAnalyzer(
cameraExecutor, scannerAnalyzer
)
}

cameraProvider.unbindAll()
camera = cameraProvider.bindToLifecycle(
this,
cameraSelector,
imagePreview,
imageAnalysis
)
cameraControl = camera.cameraControl
cameraInfo = camera.cameraInfo
imagePreview.setSurfaceProvider(binding.previewView.surfaceProvider)
setTorchStateObserver()
}, ContextCompat.getMainExecutor(requireContext()))
}

The device camera and preview resolutions are

Supported Hardware Level : 3
Image capturing YUV_420_888 available output size: 4000x2250
Image capturing YUV_420_888 available output size: 4000x1800
Image capturing YUV_420_888 available output size: 3264x2448
Image capturing YUV_420_888 available output size: 3264x1836
Image capturing YUV_420_888 available output size: 3264x1468
Image capturing YUV_420_888 available output size: 1920x1080
Image capturing YUV_420_888 available output size: 1920x864
Image capturing YUV_420_888 available output size: 1600x1200
Image capturing YUV_420_888 available output size: 1440x1080
Image capturing YUV_420_888 available output size: 1600x900
Image capturing YUV_420_888 available output size: 1600x720
Image capturing YUV_420_888 available output size: 1504x720
Image capturing YUV_420_888 available output size: 1280x720
Image capturing YUV_420_888 available output size: 1280x576
Image capturing YUV_420_888 available output size: 1200x540
Image capturing YUV_420_888 available output size: 1024x768
Image capturing YUV_420_888 available output size: 1120x504
Image capturing YUV_420_888 available output size: 960x720
Image capturing YUV_420_888 available output size: 960x540
Image capturing YUV_420_888 available output size: 720x1280
Image capturing YUV_420_888 available output size: 720x540
Image capturing YUV_420_888 available output size: 720x480
Image capturing YUV_420_888 available output size: 640x480
Image capturing YUV_420_888 available output size: 352x288
Image capturing YUV_420_888 available output size: 320x240
Image capturing YUV_420_888 available output size: 256x192
Image capturing YUV_420_888 available output size: 240x320
Image capturing YUV_420_888 available output size: 176x144
Preview available output size: 4000x2250
Preview available output size: 4000x1800
Preview available output size: 3264x2448
Preview available output size: 3264x1836
Preview available output size: 3264x1468
Preview available output size: 1920x1080
Preview available output size: 1920x864
Preview available output size: 1600x1200
Preview available output size: 1440x1080
Preview available output size: 1600x900
Preview available output size: 1600x720
Preview available output size: 1504x720
Preview available output size: 1280x720
Preview available output size: 1280x576
Preview available output size: 1200x540
Preview available output size: 1024x768
Preview available output size: 1120x504
Preview available output size: 960x720
Preview available output size: 960x540
Preview available output size: 720x1280
Preview available output size: 720x540
Preview available output size: 720x480
Preview available output size: 640x480
Preview available output size: 352x288
Preview available output size: 320x240
Preview available output size: 256x192
Preview available output size: 240x320
Preview available output size: 176x144

Chosen Preview resolution: 720x1280
Chosen Image Analyser resolution: 720x1280 

Device: Motorola Moto G9
Display Resolution: 1600x720
Android Version: 10
Software Version: QPXS30.30-Q3-38-59-2

I am using the given below dependencies for CameraX.
  • Gradle: androidx.camera:camera-camera2:1.0.0-rc03@aar
  • Gradle: androidx.camera:camera-core:1.0.0-rc03@aar
  • Gradle: androidx.camera:camera-lifecycle:1.0.0-rc03@aar
  • Gradle: androidx.camera:camera-view:1.0.0-alpha22@aar

I am always getting similar frame in the ImageAnalysis's analyze method. Please let me know if I am missing something or is it a bug in cameraX for this device?

Thanks
Vikram Mittal
frame.jpg

Vikram Mittal

unread,
Mar 8, 2021, 4:21:29 AM3/8/21
to Android CameraX Discussion Group, Vikram Mittal
Hi,

I just found out that the issue is due to the conversion of YUV to JPEG which works on some devices and on some not. I tried with the YuvToRgbConverter from the camera-samples, which work on Moto G9. But it is mentioned that it is not Production Ready. 

So want to make sure what is safest way to convert the YUV to JPEG/bitmap.

Thanks
Vikram Mittal

Vikram Mittal

unread,
Mar 8, 2021, 7:37:57 AM3/8/21
to Android CameraX Discussion Group, Vikram Mittal
Hi,

I found that androidx.camera.core.internal.utils.ImageUtil provide methods to convert the ImageProxy to ByteArray(imageToJpegByteArray) which works well in our devices including Moto G9, but this class is restricted to be used. Please let us know if there is any concern/issue to use this class or if there is any other better solution we can use to get the Bitmap or ByteArray from the ImageProxy object.

Thanks
Vikram Mittal

Trevor McGuire

unread,
Mar 9, 2021, 1:32:25 PM3/9/21
to Android CameraX Discussion Group, v.mi...@uqu.do
Hi Vikram,

You can depend on that class either directly or by copying the source. However, because it is an internal class, and not a public API, the method signatures may change or be removed between versions. So if you decide to depend on it directly, upgrading CameraX may require you to change your code in order to compile. If you would like to avoid that, I would recommend copying the source to a class within your app so it won't change with library upgrades.

Trevor

matty

unread,
Jul 1, 2021, 3:10:40 AM7/1/21
to Android CameraX Discussion Group, trevor...@google.com, v.mi...@uqu.do
hi there, I also saw that ImageUtil class 
and i was wondering if a converter like this will be available as public API in the future?

Also I'd be curious to know if i for example in ImageAnalysis i can always expect yuv_420_888 as image format?
Or is it possible that on some devices i might receive images in a different format like from this list of formats:
?

Kind regards
Matty

Scott Nien

unread,
Jul 1, 2021, 3:24:42 AM7/1/21
to matty, Android CameraX Discussion Group, trevor...@google.com, v.mi...@uqu.do
Hi Matty, 

Yes, we are planning to have some public image converter in the future release but no schedule confirmed. 

And yes, you can always expect yuv_420_888 format in ImageAnalysis. 


--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/e5e3db19-1beb-43a0-8ad9-71d7559d096fn%40android.com.

matty

unread,
Jul 1, 2021, 3:44:50 AM7/1/21
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, trevor...@google.com, v.mi...@uqu.do, matty
Hi Scott,
thanks a lot for the quick answer ;)
Reply all
Reply to author
Forward
0 new messages