monaca-plugins / monaca-plugin-barcode-scanner

Monaca Barcode Scanner Plugin
Other
0 stars 3 forks source link

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

Open cameronharvey92 opened 5 months ago

cameronharvey92 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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:

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