简体   繁体   中英

Image resolution is changing in some phones

I'm trying to analyze the image so I set 160, 120 inside setTargetResolution() function but when I run the app it is changing the resolution to 320, 240 in my phone but working fine in other phones. My phone is Redmi 6 pro.

   HandlerThread analyzerThread = new HandlerThread("FaceDetection");
        analyzerThread.start();

        ImageAnalysis imageAnalysis =
                new ImageAnalysis.Builder()
                        .setTargetResolution(new Size(160, 120))
                        .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
                        .build();

        imageAnalysis.setAnalyzer(executor, image -> {
            int rotationDegrees = image.getImageInfo().getRotationDegrees();
            if (image == null || image.getImage() == null) {
                return;
            }

The issue should be able to fixed after correcting the target resolution setting from

.setTargetResolution(new Size(160, 120))

to

.setTargetResolution(new Size(120, 160))

To set the target resolution, developers can refer to the following java doc description in https://developer.android.com/reference/androidx/camera/core/ImageAnalysis.Builder#setTargetResolution(android.util.Size) :

The resolution Size should be expressed in the coordinate frame after rotating the supported sizes by the target rotation. For example, a device with portrait natural orientation in natural target rotation requesting a portrait image may specify 480x640, and the same device, rotated 90 degrees and targeting landscape orientation may specify 640x480.

The reason of why the setting Size(160, 120) can't obtain the result size as 160x120 in newer CameraX versions of library:

In older versions, CameraX only compared area size of the target resolution to find the closest size. Therefore, 160x120 was still selected. In newer versions, CameraX try to find a closest supported size that can box the target resolution calibrated by the target rotation. The code doesn't set target rotation. I guess the device is in portrait orientation, so the default target rotation is ROTATION_0. After calibrating the target resolution by ROTATION_0, CameraX will try to select a closest supported size that can box the size of 120x160. Finally, 320x240 is selected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM