Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QR codes not detecting on Samsung Galaxy A23, bitmapOrg Bitmap captures wrong area of camera feed (with proposed fix) #8

Open
cameronharvey92 opened this issue Mar 16, 2024 · 2 comments

Comments

@cameronharvey92
Copy link

Hello there!

Using either version 1.2.0 or 1.4.0 of your library, QR codes are not detectable within the "detection area" on a Samsung Galaxy A23, running Android 14.

As per the Android quirks in the readme, this devices does not produce a distorted result, but instead actually captures a different area of the camera feed.

So it can actually detect QR codes when the debugPreviewView is eventually pointed at it, but it is well outside of the detection area.

This seems to be an isolated device-specific issue, as similar things have been reported here and here, but I thought I would report this bug in case it wasn't. One of these links also indicates the Android version is irrelevant.

Incorrect result in portrait mode - captures an area to the top-right:
QR code not scanned - Portrait

Incorrect result in landscape mode - captures an area to the top-left:
QR code not scanned - Landscape

Proposed fix
I was originally going to say that it seems the result of BitmapUtils.getBitmap() is incorrect, and that this device may not be supported.

But for some strange reason, I was able to fix the issue simply by explicitly calling setTargetResolution() on the ImageAnalysis.Builder. Even random sizes seemed to work, e.g.

import android.util.Size;

ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
        .setTargetResolution(new Size(300, 300))  // <-- This line
        .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
         .build();
imageAnalysis.setAnalyzer(executor, analyzer);

I understand using previewView's resolution would make more sense, and that device rotation issues / performance issues come to mind. So this also worked:

import android.util.Size;

int previewViewMinSize = Math.min(previewView.getWidth(), previewView.getHeight());  // <-- This line
ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
        .setTargetResolution(new Size(previewViewMinSize / 2, previewViewMinSize / 2))  // <-- This line
        .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
         .build();
imageAnalysis.setAnalyzer(executor, analyzer);

The results below look the same with either code snippet.

Either way, hopefully this issue is resolvable!

Cheers,
Cameron Harvey

Correct result - Portrait:
QR code scanned - Portrait

Correct result - Landscape:
QR code scanned - Landscape

@asialfujiwara
Copy link
Contributor

Dear cameronharvey92,

Thank you for the valuable information.
setTargetResolution should be set to the default value of (640, 480),
but in the case of the Galaxy A23, it might be set to a different value, causing this issue.

We are currently considering applying a fix that involves calling setTargetResolution(640, 480),
but we are concerned that calling setTargetResolution slightly reduces the detection area.
This behavior occurs on other devices as well, even when the default value of (640, 480) is specified.

Now we are considering the appropriate method, including the following ways.

1: Call setTargetResolution only when specified as an option.
2: Solve the problem of the detection area being reduced when setTargetResolution is called.

Regards,

@asialfujiwara
Copy link
Contributor

Hello Cameron,

We may have found the cause.
Could you please try the following and would you tell me the result?

        // Call setTargetAspectRatio() instead of setTargetResolution()
        ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
                .setTargetAspectRatio(AspectRatio.RATIO_4_3)         // <-- This line
                .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
                .build();

We do not own a Galaxy A23, but we assume that the issue caused by following process:

  • Camera devices has a list of selectable resolutions (available via CameraManager.getCameraCharacteristics())
  • Calling setTargetResolution() sets the selectable resolution from the list
  • In the Galaxy A23 case, camera default aspect ratio may be set to square (1:1)
    • Compared to 4:3 and 16:9, square ratio resolution is limited, so it is set to a higher resolution.
  • Galaxy A23 seems to be set to higher resolution and causes this issue.
  • Our cropping detection area process seems not working correctly with 1:1 ratio

I have no problem with my device Sony Xperia 10V.
I hope it is the same with your device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants