CameraX ImageAnalysis picking wrong resolution on Samsung SM-P355 tablet

1,974 views
Skip to first unread message

Vikram Mittal

unread,
Jan 25, 2021, 12:02:45 AM1/25/21
to Android CameraX Discussion Group
Hi,

I have observed that on my Samsung tablet the frame I received in Image Analysis is always 800X480 although I have set the targetResolution as 1080X1920. Even if I set the targetResolution to 1920X1080, the frame size is still 800X480. I have checked the supported camera resolutions of the device, and it do supports the resolution I have passed, but it is not picking that up. The frame size I have received is too low resolution to process in my Image Analyser, so I need a bigger frame size.

Can it be due to the aspect ratio? But the device aspect ratio is 1.33*(1024/768), and the native camera captures images in resolution 2592X1944 (1.33), so I would expect the resolution from CameraX in ImageAnalysis to be 1600X1200 (1.33), but it isn't. It is picking the aspect ratio of 5:3 (1.67).

But then how can I get required frame size in CameraX, like in camera2 I can resize the TextureView as per the resolution I need.

I have initialised the fullscreen camera using the below code, which is working fine in the mobile phone.

...
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()))
}


My Device Configuration on which I am facing issue is

Model: SM-P355 (gt5note8ltexx)
Manufacturer: samsung
Dimension: 208.3 x 137.9 x 7.4 mm
Weight: 313 g
Baseband Version: P355XXU1CQI4
RIL Version: Samsung RIL v3.0
Build Number: NMF26X.P355XXS1CTJ1
Build Fingerprint: samsung/gt5note8ltexx/gt5note8lte:7.1.1/NMF26X/P355XXS1CTJ1:user/release-keys
Bootloader: P355XXS1CTJ1
Java VM: ART 2.1.0
OS Version: N MR1 (7.1.1)
SDK: 25

DISPLAY
Size: 8.0 inches
Resolution: 768x1024 pixels
Pixel Density: 160 ppi
Software Density: 210 dpi
Refresh Rate: 60 Hz

PROCESSOR
CPU Architecture: ARMv7 Processor rev 0 (v7l)
Board: MSM8916
Chipset: Qualcomm Technologies, Inc MSM8916
Cores: 4
Clock Speed: 1094 MHz - 1190 MHz
Instruction Sets: armeabi-v7a, armeabi
CPU Features: swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 evtstrm
CPU Governor: interactive
Kernel Version: 3.10.49-12366605
Kernel Architecture: armv7l

GRAPHICS
Renderer: Adreno (TM) 306
Vendor: Qualcomm
OpenGL Version: OpenGL ES 3.0

RAM
Total: 1890 MB
Java Heap: 128 MB

STORAGE
Internal: 11 GB
EXTERNAL: Not Detected

PRIMARY CAMERA
Resolution: 5 MP
Flash: No
Video Resolution: HD, 1280x720
Supported Resolutions:
    Image:
    2592x1944
    2576x1932
    2560x1920
    2560x1536
    2592x1458
    1920x1920
    2560x1440
    2048x1536
    2048x1152
    1920x1080
    1600x1200
    1280x720
    960x720
    800x480
    640x480
    320x240

    Video:
    1280x720 (HD)
    720x480
    640x480 (VGA)
    352x288
    320x240
    176x144

SECONDARY CAMERA
Resolution: 1.9 MP
Video Resolution: VGA, 640x480
Supported Resolutions:
    Image:
    1600x1200
    1280x960
    1280x720
    960x720
    720x480
    640x480
    320x240
    176x144

    Video:
    640x480 (VGA)
    320x240
    176x144

The cameraX library versions I am using are
def cameraX = '1.0.0-rc01'
def cameraView = '1.0.0-alpha20'
"androidx.camera:camera-core:${cameraX}"
"androidx.camera:camera-camera2:${cameraX}"
"androidx.camera:camera-view:$cameraView"
"androidx.camera:camera-lifecycle:${cameraX}"

Please help on this, understanding this issue, if something needs to be done at my side.

Thanks
Vikram Mittal

Charcoal Chen

unread,
Jan 25, 2021, 5:21:12 AM1/25/21
to Android CameraX Discussion Group, v.mi...@uqu.do
Hi,

Thanks for using CameraX and reporting the question.

I tried to use robolectric test to reproduce the issue and could reproduce it when the device's hardware level is INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY and the supported sizes are as the following:
    1920x1080
    1600x1200
    1280x720
    960x720
    800x480
    640x480
    320x240

What size can be selected depends on the camera device capability. A LEGACY level device can only support PRIV/PREVIEW + YUV/PREVIEW surface combination when binding Preview and ImageAnalysis (Please refer to LEGACY-level guaranteed configurations table in link).

The PREVIEW size is defined as the following (in link):
PREVIEW refers to the best size match to the device's screen resolution, or to 1080p (1920x1080), whichever is smaller.

According to the provided device information, the display size is 768x1024. The PREVIEW size was determined as 1024x768. Therefore, the resolution selected for ImageAnalysis would be limited under 1024x768. Finally, size 800x480 was selected for the ImageAnalysis.

Please help to confirm whether the device is a LEGACY level device and please query the supported sizes for YUV_420_888 from StreamConfigurationMap#getOutputSizes() such that we can know the root cause is the same as what I analyzed.

Vikram Mittal

unread,
Jan 25, 2021, 7:08:21 AM1/25/21
to Android CameraX Discussion Group, charco...@google.com, Vikram Mittal
Hi,

Got the details from the devices as

Supported Hardware Level : 2
Is LEGACY: true

Image capturing YUV_420_888 available output size: 1280x960
Image capturing YUV_420_888 available output size: 1280x720
Image capturing YUV_420_888 available output size: 720x720
Image capturing YUV_420_888 available output size: 800x480
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: 176x144

Preview available output size: 1280x960
Preview available output size: 1280x720
Preview available output size: 720x720
Preview available output size: 800x480
Preview available output size: 720x480
Preview available output size: 640x480
Preview available output size: 352x288
Preview available output size: 320x240
Preview available output size: 176x144

Chosen Preview resolution: 800x480
Chosen Image Analyser resolution: 800x480

Using the following code
val cameraId = Camera2CameraInfo.from(camera!!.cameraInfo).cameraId
val cameraManager = ContextCompat.getSystemService(requireContext(), CameraManager::class.java) as CameraManager
val characteristics = cameraManager.getCameraCharacteristics(cameraId)
val configs : StreamConfigurationMap? = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)

val imageAnalysisSizes = configs?.getOutputSizes(ImageFormat.YUV_420_888)
imageAnalysisSizes?.forEach {
println("Image capturing YUV_420_888 available output size: $it")
}

val previewSizes = configs?.getOutputSizes(SurfaceTexture::class.java)
previewSizes?.forEach {
println("Preview available output size: $it")
}
println("Chosen Preview resolution: ${preview?.attachedSurfaceResolution}")


Thanks
Vikram Mittal

Charcoal Chen

unread,
Jan 25, 2021, 8:59:35 PM1/25/21
to Vikram Mittal, Android CameraX Discussion Group
Hi,

Thanks for providing the detailed information for clarification. It matches my previous analysis result. The camera device hardware level and PREVIEW size restrict the app from selecting the 1920x1080 size. The selected size 800x480 is already the largest size that is under 1024x768 and the aspect ratio is closest 16:9 (1920x1080).

If there are still other questions, please kindly let us know. Thanks.
Reply all
Reply to author
Forward
0 new messages