hjam40 / Camera.MAUI

A CameraView Control for preview, take photos and control the camera options
MIT License
461 stars 77 forks source link

Slow QR code processing on Android due to multiple QR decoding tasks running simultaneously #27

Closed arekzimny closed 1 year ago

arekzimny commented 1 year ago

I've noticed that the decoding of QR codes appears to run on ThreadPool tasks based on a timer without any consideration for existing tasks. I can sometimes see upwards of 10 threads running simultaneously depending on how I set the frame rate. This leads to a couple of issues for me:

  1. The app slows to a crawl and the camera begins to stutter as more tasks are started. This is especially noticeable on older smartphones.
  2. Once a barcode is detected the user is directed to a page that asks for more information. However, they can hit the back button and go back to the QR scanning page. Sometimes, one of the still-running threads will finish and cause the BarcodeDetected event to fire even though there is no QR code in front of the camera.
luis95gr commented 1 year ago

Hi, I have the same issue even with recent smartphones (S23 and Pixel 7), I can't use this plugin due to the lagging.

hjam40 commented 1 year ago

Hi, In the next version, only one thread will be running at the same time. If the device is slow, some processing frames will be lost but the preview will work fine.

scriptBoris commented 1 year ago

I can confirm the problem, it takes a very long time to recognize QR codes and poor performance

hjam40 commented 1 year ago

Hi, The new version is available. Right now, you could control better the barcode detection mode with this properties: BarCodeDetectionFrameRate BarCodeDetectionMaxThreads BarCodeOptions ControlBarcodeResultDuplicate

The performance should be better depending the parameter configuration (specially BarCodeDetectionMaxThreads)

scriptBoris commented 1 year ago

Hi, The new version is available. Right now, you could control better the barcode detection mode with this properties: BarCodeDetectionFrameRate BarCodeDetectionMaxThreads BarCodeOptions ControlBarcodeResultDuplicate

The performance should be better depending the parameter configuration (specially BarCodeDetectionMaxThreads)

2023-05-12 20-18-14.zip I record screen video that 1D barcodes not recognized (ZIP). But QR codes is read by 1-3 seconds.

How fix problem with 1D barcodes?

scriptBoris commented 1 year ago

On real android device, Camera.MAUI no read QR codes too 😒

hjam40 commented 1 year ago

Hi Boris,

I have tested it in 3 Android devices and it works fine for QR detection.... Make sure to initialize correctly the parameters: CameraView.BarcodeDecodeOptions.PossibleFormats = new List { BarcodeFormat.QR_CODE }; ...

By the way, it is not this plugging that detects the codes, this pluggin uses ZXing for that. The plugging only pass a camera capture to the ZXing decoder.

scriptBoris commented 1 year ago

Привет, Борис,

Я протестировал его на 3 устройствах Android, и он отлично работает для обнаружения QR.... Убедитесь, что правильно инициализированы параметры: CameraView.BarcodeDecodeOptions.PossibleFormats = new List { BarcodeFormat.QR_CODE }; ...

Кстати, не этот плагин обнаруживает коды, этот плагин использует для этого ZXing. Подключение передает только захват камеры на декодер ZXing.

image No throw break point...

hjam40 commented 1 year ago

Hi,

Sorry, but I don't understand your message. With this configuration I have read your code from an Android device in less of 1 second:

        cameraView.BarCodeOptions = new ZXingHelper.BarcodeDecodeOptions
        {
            AutoRotate = true,
            PossibleFormats = { BarcodeFormat.EAN_13 },
            ReadMultipleCodes = false,
            TryHarder = false,
            TryInverted = true
        };