PDF417 / pdf417-ios

PDF417 and QR code scanning SDK for iOS
www.pdf417.mobi
Apache License 2.0
127 stars 34 forks source link

Scanning multiple QR code in same region #62

Closed popei69 closed 2 years ago

popei69 commented 2 years ago

Hi there,

I have a question regarding the scanner SDK with multiple codes in the same frame.

I have setup a MBBarcodeRecognizer to scan only QR Code and a scanningRegion to limit the region on the screen to detect those QR Code. However, it can happen in real life that multiple QR Code are close to each other and appear in the same region. The scanner becomes unpredictable and can recognize multiple times the same QR code and ignore the second one in the same frame.

Is there a way to handle this more gracefully?

Thanks

mparadina commented 2 years ago

Hi @popei69

If I correctly understood the inquiry, using our default UI, there is no direct way to reduce the scanning region.

However, if you are using your own custom UI, then you can add your own scanning region, meaning that not all of the screen can be used for barcode recognition.

You can see how the set up the custom UI here, along with the documentation. The scanning region method, along with the explanation of how to use it, can be found here.

Let me know if this helped.

popei69 commented 2 years ago

Hey @mparadina,

Thanks for the quick feedback. Let me clarify a bit more about my use-case.

As of today, I already use a custom layout with MBCustomOverlayViewController and the scanningRegion to limit the region to scan.

However, the problem stays the same, if a user aims to 2 QR code in the same region, there is little information to know which is one is being recognized. It can happens that same QR code is recognized multiple time where the second one is missed.

Is there anything else in the SDK that can help improve multiple codes recognition?

Thanks

mparadina commented 2 years ago

Hi @popei69

Thank you for explaining your use case in more detail.

Unfortunately, it is not possible to 'target' a specific barcode if there are multiple barcodes of the same type in the scanning region. This mostly depends on the barcode quality, or the more exact, which barcode is 'more clear' in order for the SDK to detect and extract information from it first.

There is not a direct way to know which barcode will the SDK extract first. Currently, the only setting you can modify on your side is to reduce the scanningRegion to only be able to fit one QR code, and to limit the MBBBarcodeRecognizer to only scan the barcodes which are needed for the use case.

Another thing that comes to mind is to reset the scanning process if the QR code does not have the specific information that is required on your side:

        if state == .valid {
            recognizerRunnerViewController.pauseScanning();

            DispatchQueue.main.async {
                for recognizer in self.recognizerCollection.recognizerList {
                    if ( recognizer.baseResult?.resultState == .valid ) {
                        let barcodeRecognizer = recognizer as? MBBBarcodeRecognizer
                        let stringData = barcodeRecognizer?.result.stringData

                        if !(stringData!.contains("your-data")) {
                          //present your alert to notify the end user to rescan the correct QR code
                            recognizerRunnerViewController.resumeScanningAndResetState(true)
                        }
                    }
                }
            }
        }

Let me know if there is anything else I can assist you with.

popei69 commented 2 years ago

Hey @mparadina , thanks for those details, I'll try to play around and let you know how it goes.

One last question, do you have performance measurements of the scanner detection? It feels sometimes the feed is a bit slow than other scanning camera apps.

Thanks

mparadina commented 2 years ago

Hi @popei69,

If I correctly understood the questions, then, unfortunately, there is not a direct way to check the status of the last recognition process with the SDK to check its scanning metrics. In the scanned results, you can check the uncertain method, which gives you information on whether the SDK detected that you are scanning uncertain data, for instance, when you're scanning a damaged barcode.

If the 'speed' of the recognition process is something that is causing issues on your end, you can turn off the slowerThoroughScan and scanUncertain methods, which are by default set to true. The first method gives you better image processing, but the scanning is slower and the second one lets you scan barcodes which are not standard compliant (incorrectly coded PDF417 barcodes).

Let me know if you have any additional questions.

popei69 commented 2 years ago

Hey @mparadina thanks for the details. I'll have a try and see if it resolves our use-case, thanks!