html5-qrcode
html5-qrcode copied to clipboard
Can't Read EAN-13 barcodes with Leading Zero
Examples:
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:
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.
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.
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.
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?
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
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).
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
},
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?
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.
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