Can't Increase CameraX ImageAnalysis Resolution Past 1024x768, Level 3 Device

1,636 views
Skip to first unread message
Assigned to charco...@google.com by wuj...@google.com

Jeff

unread,
Mar 4, 2021, 7:07:43 PM3/4/21
to Android CameraX Discussion Group

I cannot seem to get my CameraX camera to give me an ImageAnalysis resolution of anything larger than 1024x768

Here is my set up

def cameraXVersion = "1.0.0-rc02" 
implementation "androidx.camera:camera-camera2:$cameraXVersion" 
implementation "androidx.camera:camera-lifecycle:$cameraXVersion" 
implementation "androidx.camera:camera-view:1.0.0-alpha21" 


val imageAnalyzer = ImageAnalysis.Builder() 
 .setTargetResolution(Size(1080, 1440)) // also tried Size(1440, 1080), no change .     .setMaxResolution(Size(1440, 1440)) .setTargetRotation(cameraXStartOrientation ?: cameraPreviewOrientation) .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) .build().apply { setAnalyzer(cameraExecutor, GenericAnalyzer(analyzer)) } } ... 
  // commented out all other use cases to make sure they're not interfering cameraProvider.bindToLifecycle( lifecycleOwner, cameraSelector, /*preview, imageCapture,*/ imageAnalyzer )

I also later will alter the rotation on the imageAnalysis use case if the device orientation changes, not sure if that could mess things up somehow. Commenting it out has no effect

override fun updateRotation(orientation: DeviceRotationHelper.Orientation) {         super.updateRotation(orientation) 
 val cameraXRotation = orientation.toCameraXOrientation() imageCapture?.targetRotation = cameraXRotation imageAnalysis?.targetRotation = cameraXRotation 
}

According to this code 1440x1080 is in the list of output sizes (and nowhere near the largest), and it is less than the 1080p maximum set for CameraX:

val characteristics = Camera2CameraInfo.extractCameraCharacteristics(camera!!.cameraInfo) 
val streamConfigurationMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) 
val outputSizes = streamConfigurationMap!!.getOutputSizes(ImageFormat.YUV_420_888) println(outputSizes)

According to the characteristics, my device is a LEVEL_3

characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3 // true

According to this documentation, this is the highest level listed https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL

So what am I doing wrong here?


Sorry about the terrible code formatting. Sure would be nice to have markdown supported. Here's a link to my StackOverflow post with all my info in a much more readable format https://stackoverflow.com/questions/66481571/cant-increase-camerax-imageanalysis-resolution-past-1024x768

Charcoal Chen

unread,
Mar 4, 2021, 9:26:31 PM3/4/21
to Android CameraX Discussion Group, Jeff
Hi,

Thanks for reporting the issue.

I tried to use robolectric test to reproduce the issue, but failed to reproduce it. Could you help to provide the following information?

1. What is the device that you encountered the issue?
2. Could you help to try some other different library versions (for example 1.0.0-rc01 and 1.0.0-beta12 with matching view module version)? So that we can know whether this issue is related to recent changes.
3. Could you explicitly specify the target Rotation by Surface.ROTATION_0 and Surface.ROTATION_90 to see whether the issue still occur or it will happen on which rotation value?
4. Could you help to provide the outputSizes list so that I might be able to find some clue from the list?
5. What is the display size of the device?

Thanks.

Jeff J

unread,
Mar 4, 2021, 9:54:17 PM3/4/21
to Charcoal Chen, Android CameraX Discussion Group
1. What is the device that you encountered the issue? Moto G7 Play
2. Could you help to try some other different library versions (for example 1.0.0-rc01 and 1.0.0-beta12 with matching view module version)? So that we can know whether this issue is related to recent changes. rc01 changes nothing, beta12 fails at init with error java.lang.AbstractMethodError: abstract method "androidx.camera.core.impl.CameraFactory androidx.camera.core.impl.CameraFactory$Provider.newInstance(android.content.Context, androidx.camera.core.impl.CameraThreadConfig, androidx.camera.core.CameraSelector)"
3. Could you explicitly specify the target Rotation by Surface.ROTATION_0 and Surface.ROTATION_90 to see whether the issue still occur or it will happen on which rotation value? I tried all four permutations of the rotations above, and ordering of Size dimensions, no change
4. Could you help to provide the outputSizes list so that I might be able to find some clue from the list? [4160x3120, 4160x2340, 4160x1980, 4000x3000, 3840x2160, 3264x2448, 3264x1836, 3264x1546, 2592x1944, 2592x1458, 2688x1512, 1920x1080, 1800x1600, 1440x1080, 1280x960, 1280x720, 1520x720, 960x720, 1024x768, 1216x576, 800x600, 720x480, 640x480, 640x360, 352x288, 320x240, 320x180, 176x144]
5. What is the display size of the device? 720x1344

Charcoal Chen

unread,
Mar 5, 2021, 2:57:13 AM3/5/21
to Android CameraX Discussion Group, Jeff, Android CameraX Discussion Group, Charcoal Chen
Hi,

Thanks for providing the information. I try to run some tests on our sharing pool Moto G7 device. My test results are the following:
- When binding Preview + ImageCapture + ImageAnalysis at the same time, the resolution selected for the ImageAnalysis will be 1024x768.
- When only binding ImageAnalysis, the resolution selected for the ImageAnalysis will be 1440x1080.

The results are correct for the resolution selection logic in CameraX.

When three use cases are bound at the same time, the following configuration (listed in the guaranteed configurations tables here) will be used to select the resolution :
PRIV PREVIEW YUV PREVIEW JPEG MAXIMUM Still capture plus in-app processing.
The PREVIEW size  refers to the best size match to the device's screen resolution, or to 1080p (1920x1080), whichever is smaller. The device display size is 720x1522 (obtained by Display#getRealSize()). And 1024x768 is the largest size that belongs to PREVIEW size and its aspect ratio matches the target resolution setting. Therefore, 1024x768 is selected for ImageAnalysis in this combination.

When only binding ImageAnalysis, the MAXIMUM size can be selected for it. Because there was max resolution setting, therefore, the selected resolution will be 1440x1080.

In your provided information in the beginning, you ever tried to only bind  imageAnalyzer and the selected resolution was still 1024x768. Could you double check it again? This is different from my test result.

BTW, CameraX always try to select the maximum resolution for ImageCapture when binding multiple use cases in one call. This will also cause the resolution for ImageAnalysis will be limited in PREVIEW size. A workaround that might fulfill your requirements is, please try to call bindToLifecycle() to bind PREVIEW + ImageAnalysis first and then call bindToLifecycle() again to bind ImageCapture. Under such binding sequence, the following configuration will be used to select the resolutions. 1440x1080 will be selected for ImageAnalysis, but the ImageCapture will be limited in RECORD size. After checking, the device's RECORD size is 1920x1080. Therefore, the captured image of ImageCapture will become only 1440x1080.
PRIV PREVIEW YUV RECORD JPEG RECORD High-resolution in-app processing with video snapshot.

Jeff J

unread,
Mar 5, 2021, 10:45:11 AM3/5/21
to Charcoal Chen, Android CameraX Discussion Group
Sorry, as dumb as this sounds when I tried removing ImageCapture from the list of use cases, I must've just checked the size of the input via Android Studio's debug tool bitmap viewer, which gets downsampled. On closer inspection, removing ImageCapture does boost my ImageAnalysis input to the requested dimensions.

I will say, that is a bit of a bummer for my use case, as I need high resolution images for both frames and captured images to run CV algorithms on. I understand there are hardware limitations though. I suppose I will look into removing image analysis once I am ready to capture
Reply all
Reply to author
Forward
0 new messages