html5-qrcode icon indicating copy to clipboard operation
html5-qrcode copied to clipboard

Can't Read EAN-13 barcodes with Leading Zero

Open Bhanuka-BizSmarTech opened this issue 2 years ago • 9 comments

Examples: barcode (4) barcode (5)

Bhanuka-BizSmarTech avatar Dec 09 '21 05:12 Bhanuka-BizSmarTech

I tried with some other online barcode readers as well and all of them seem to ignore the leading 0.

I generated one online and it seemed to show the same behavior:

image

Based on some reading online it looks like an EAN-13 code with leading "0" is a UPC-A code and it maybe ok to ignore the leading 0. If your business logic really requires the accurate full value, you could add a logic to prepend a 0 if the length of the decodedText < 13.

One hack could be to prepend a "0" in cases where 12 digits are not observed for EAN13 code.

mebjas avatar Dec 12 '21 12:12 mebjas

Maybe related to https://github.com/zxing-js/library/issues/457? According to a comment in the unmerged PR, it should be fixed by now. Maybe just need to update the zxing dependency.

jp06 avatar Dec 13 '21 15:12 jp06

This now needs to be back-ported to https://github.com/mebjas/html5-qrcode/blob/master/third_party/zxing-js.umd.js considering zxing-js is no longer well maintained and html5-qrcode has modified internal version further.

A better refactor would be if we maintain a separate version (fork) of original zxing-js library so it's easier to port.

mebjas avatar Dec 20 '21 09:12 mebjas

Out of curiosity I tried to scan the three EAN-13-barcodes above. All were correctly recognized using version 2.1.6.

I am writing the value to a string input and the leading zero is shown there. Maybe the leading zero got lost when converting to a number?

dalito avatar Dec 27 '21 16:12 dalito

Out of curiosity I tried to scan the three EAN-13-barcodes above. All were correctly recognized using version 2.1.6.

I am writing the value to a string input and the leading zero is shown there. Maybe the leading zero got lost when converting to a number?

Hello, i would like to know what type of phone are you using ? Because for me the three example above still doesn't work on 2.1.6

Modjo69 avatar Jan 10 '22 10:01 Modjo69

When I try to read above barcodes with https://scanapp.org I also cannot see the leading zeros.

However, in my code that uses version 2.1.6 and reads decodedText the leading zeros are present. So I do not believe that it has much to do with the phone. I used a Huawei P30 Pro with the current version of Chrome (96.0.4664.104).

dalito avatar Jan 10 '22 19:01 dalito

Scanapp uses experimental support of using BarcodeDetector API which uses the hardware supported detectors first before zxing - so it could be because of that.


	let html5QrcodeScanner = new Html5QrcodeScanner(
        "reader", 
        { 
            fps: 10,
            qrbox: qrboxFunction,
            // Important notice: this is experimental feature, use it at your
            // own risk. See documentation in
            // mebjas@/html5-qrcode/src/experimental-features.ts
            experimentalFeatures: {
                useBarCodeDetectorIfSupported: true
            },
            rememberLastUsedCamera: true,
            aspectRatio: 1.7777778
        });

Can you try adding this info

    experimentalFeatures: {
       useBarCodeDetectorIfSupported: true
    },

mebjas avatar Feb 19 '22 11:02 mebjas

I am not sure I understand what to try: Do you mean to

experimentalFeatures: {
       useBarCodeDetectorIfSupported: true
    },

to my app/code and see if it "looses" the leading zero?

dalito avatar Feb 19 '22 11:02 dalito

With useBarCodeDetectorIfSupported: true the barcodes above are not read/detected but with useBarCodeDetectorIfSupported: flase they are correctly read. I used version 2.1.6 and 2.2.0 for this test.

dalito avatar Feb 21 '22 20:02 dalito

Similar example by @sam-the-programmer in https://github.com/mebjas/html5-qrcode/issues/522

Try scan a barcode with the scanner, e.g. this one

mebjas avatar Nov 16 '22 15:11 mebjas