capacitor-community / barcode-scanner

A fast and efficient (QR) barcode scanner for Capacitor
MIT License
437 stars 169 forks source link

Scanner is 'slow' at Android devices #161

Closed died89 closed 1 year ago

died89 commented 1 year ago

I implemented the barcode scanner in my Ionic 6 app. The scanner works very well at iOs devices, but on multiple Android devices it doesn't. Scanning a QR code takes very long because you have to find a certain way to hold the device, despite the QR code is in the middle of the screen. Other QR scan apps from the Play store working very well and fast.. I have added QR_CODE as target format.

I'm stuck in this, do you maybe have a solution? Thanks in advance!

thegnuu commented 1 year ago

Hmm, I never heard about performance issues on QR codes so far... The android version is using zxing as a lot of other projects and at least for 2D codes this usually works well.

Do you have a repo to reproduce this?

died89 commented 1 year ago

Thanks for your fast reply! In the meantime I know what the problem is.

In my design the camera-view is at about 25% from the top. Not vertically aligned in the center. This is the design:

Screenshot 2022-09-29 at 14 40 43

So when I point the camera to the QR code, the QR code is not in the scanning area. Is it possible to move the scanning area upwards?

thegnuu commented 1 year ago

This should technically not be an issue for the scanning itself, the QR code (other than 1D codes) should be readable in the complete viewport (which is by designs, since always the complete viewport is used). The only issue that might occur is that you are currently not able to specify the area for the scan, that means that a code could also be read if it is outside of your rectangle, for example under the "Fill code manually" button. If I rebuild a super simple example of your UI I am able to scan a code.

There is a PR open to achieve custom scan areas, unfortunately only for android at the moment and in my opinion we should only release features that are available on all devices (as far as possible at least). This is why I am trying to move this repo to mlkit which would allow us to use the "same" components and achieve the more or less same results on all devices.

died89 commented 1 year ago

Wow oke.. Strange. I created a new app with the camera in fullscreen view and it does the same behavior. So even in the top of the view the QR code is already visible, but it doesn't scan. When I move the phone to center the QR code in the view, it works..

The devices are a OnePlus 8 Pro and a Samsung A40.

thegnuu commented 1 year ago

Can you share the newly created app with me to have a look?

died89 commented 1 year ago

Sure, here it is.

thegnuu commented 1 year ago

Okay, I can see your issue now... The problem really seems to be related to the scanning area, if you are only working on Android you should be able to work around it with #140 .

As I previously said, this is not merged since the behaviour should be more or less the same on Android and iOS IMHO. It looks like this can be done with rectOfInterest in AVFoundation, but unfortunately I have currently no time to have a detailed look at this one.

died89 commented 1 year ago

You are right, the behaviour should be the same at both platforms. So it's fine by me to have a fullscreen scanning area, because that's already the case on iOS. But how is that possible on Android? Because in my new app the scanning area is a little square in the center of the screen. Or we don't fully understand each other :)

died89 commented 1 year ago

Hi @thegnuu , do you maybe have a solution? Or is it necessary to do a redesign (center the scanning area in the viewport)?

Thanks in advance.

thegnuu commented 1 year ago

@died89 unfortunately I have no working solution at the moment, one solution is only working on android and the other is only working on iOS so far. I have no time to work on either one in the upcoming weeks because of other projects, so the easiest way to get a working solution fast would be to use the center of the area. I am working on it, but unfortunately my Android development know-how is not that great and it might take me a while to get the newest ml-kit version far enough for a beta release...

died89 commented 1 year ago

Allright, I understand it! Thank you for your time and your honest answer. Closing this issue for now.

hueppee commented 1 year ago

Hi, I have the same performance problems on an Android device when I scan QR-codes (2D DATA_MATRIX). Is there any progress on this issue?