zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.
https://zxing-js.github.io/library/
Apache License 2.0
2.47k stars 546 forks source link

Unable to decode some QR code #92

Closed dodomui closed 5 years ago

dodomui commented 6 years ago

Hi,

I'm facing some QR code unable to decode by using this library. Those QR code can be decode by using camera scanner and this zxing online decoder at https://zxing.org/w/decode.jspx

Uploaded one of the QR code that unable to scan. whatsapp image 2018-09-17 at 12 36 31 pm

Error as per below: checksum or format error, trying again... Error at t.correctErrors (lib.js:1) at t.decodeBitMatrixParser (lib.js:1) at t.decodeBitMatrix (lib.js:1) at t.decode (lib.js:1) at e.t.readerDecode (lib.js:1) at e.t.decodeOnce (lib.js:1) at lib.js:1 at new Promise () at e.t.decodeFromImage (lib.js:1) at HTMLAnchorElement.document.getElementById.addEventListener ((index):69)

odahcam commented 6 years ago

Please provide Library and Browser version. I could decode without problems, just a little waiting of 2s.

Live working demo: https://zxing-ngx-scanner.stackblitz.io/

dodomui commented 6 years ago

Yes, if scan it can work properly. But I'm using library/docs/examples/qr-image/index.html this method.

Is to read and decode the qrcode image directly. I'm using Chrome and point lib to https://unpkg.com/@zxing/library@dev.

It showing the error infinitely. screen shot 2018-09-18 at 1 37 00 am

dodomui commented 6 years ago

test0 This qrcode image unable to read also.

Actually I'm facing the same problem while using another library (LazarSoft/jsqrcode) wrap from zxing. Unable to decode image but can scan.

Wonder what is the problem...

odahcam commented 6 years ago

Please try with https://unpkg.com/@zxing/library@latest.

The scanner uses some predefined rules, you can take a look at it to see how it works. Also, I'm using the BrowserCodeReader implementation inside the https://github.com/zxing-js/ngx-scanner component, there's also some rules applied on the decode function call. The error you pasted looks like an error inside some loop, please provide the entire error output and as text so I can do a better job on helping you.

dodomui commented 6 years ago

There's no error while using https://unpkg.com/@zxing/library@latest. But the decode result was empty. I'm using this example https://zxing-js.github.io/library/examples/qr-image/

Will try to build a codepen later on.

Below is the previous error code, but doesn't appear anymore on 0.8.3

ZXing code reader initialized
BrowserCodeReader.ts:257 true Error
    at t.readVersion (BitMatrixParser.ts:140)
    at t.decodeBitMatrixParser (Decoder.ts:130)
    at t.decodeBitMatrix (Decoder.ts:84)
    at t.decode (QRCodeReader.ts:76)
    at e.t.readerDecode (BrowserCodeReader.ts:278)
    at e.t.decodeOnce (BrowserCodeReader.ts:254)
    at BrowserCodeReader.ts:201
    at new Promise (<anonymous>)
    at e.t.decodeFromImage (BrowserCodeReader.ts:192)
    at HTMLAnchorElement.document.getElementById.addEventListener ((index):70)
BrowserCodeReader.ts:262 checksum or format error, trying again... Error
    at t.readVersion (BitMatrixParser.ts:140)
    at t.decodeBitMatrixParser (Decoder.ts:130)
    at t.decodeBitMatrix (Decoder.ts:84)
    at t.decode (QRCodeReader.ts:76)
    at e.t.readerDecode (BrowserCodeReader.ts:278)
    at e.t.decodeOnce (BrowserCodeReader.ts:254)
    at BrowserCodeReader.ts:201
    at new Promise (<anonymous>)
    at e.t.decodeFromImage (BrowserCodeReader.ts:192)
    at HTMLAnchorElement.document.getElementById.addEventListener ((index):70)
(index):77 Started decode for image from http://localhost:8888/qr-image/test0.jpg
BrowserCodeReader.ts:257 true Error
    at t.readVersion (BitMatrixParser.ts:140)
    at t.decodeBitMatrixParser (Decoder.ts:130)
    at t.decodeBitMatrix (Decoder.ts:84)
    at t.decode (QRCodeReader.ts:76)
    at e.t.readerDecode (BrowserCodeReader.ts:278)
    at e.t.decodeOnce (BrowserCodeReader.ts:254)
BrowserCodeReader.ts:262 checksum or format error, trying again... Error
    at t.readVersion (BitMatrixParser.ts:140)
    at t.decodeBitMatrixParser (Decoder.ts:130)
    at t.decodeBitMatrix (Decoder.ts:84)
    at t.decode (QRCodeReader.ts:76)
    at e.t.readerDecode (BrowserCodeReader.ts:278)
    at e.t.decodeOnce (BrowserCodeReader.ts:254)
odahcam commented 6 years ago

Ok, I'll wait for the CodePen example then. I think there's a high chance you're just using the wrong decoder.

dodomui commented 6 years ago

https://codepen.io/anon/pen/BOqGRg Erm... I tried to create a CodePen but receiving cross origin error. Any idea how could I solve it? SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.

For my case, is not all QR code cannot decode, just some of the QR code unable to decode... And I'm using exactly the same from example... wonder is I do anything wrong...

odahcam commented 6 years ago

I couldn't decode it as well, it returns a Promise that never gets resolved. 😠

Could it be related to #76?

dodomui commented 6 years ago

Something different is, not all QR code image cannot be decoded. I can decode most of the QR code successfully, just some of QR code format cannot be decode properly. Cannot find out what's wrong...

JasonHK commented 5 years ago

Hello, I have the same problem using the library. The below images are the same QR code but taken differently. Both of them are able to be decoded by ZXing Decoder Online, but failed on this library. I thought this was a direct port of the original ZXing Java library...

Here's the error that the library threw:

FormatException
    at Function.DecodedBitStreamParser.decode (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/@zxing/library/esm5/core/qrcode/decoder/DecodedBitStreamParser.js:123:19)
    at Decoder.decodeBitMatrixParser (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/@zxing/library/esm5/core/qrcode/decoder/Decoder.js:131:49)
    at Decoder.decodeBitMatrix (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/@zxing/library/esm5/core/qrcode/decoder/Decoder.js:70:25)
    at QRCodeReader.decode (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/@zxing/library/esm5/core/qrcode/QRCodeReader.js:65:42)
    at /home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/lib/load.js:18:35
    at Generator.next (<anonymous>)
    at fulfilled (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/tslib/tslib.js:107:62)
ChecksumException
    at Decoder.correctErrors (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/@zxing/library/esm5/core/qrcode/decoder/Decoder.js:154:19)
    at Decoder.decodeBitMatrixParser (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/@zxing/library/esm5/core/qrcode/decoder/Decoder.js:125:18)
    at Decoder.decodeBitMatrix (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/@zxing/library/esm5/core/qrcode/decoder/Decoder.js:70:25)
    at QRCodeReader.decode (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/@zxing/library/esm5/core/qrcode/QRCodeReader.js:65:42)
    at /home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/lib/load.js:18:35
    at Generator.next (<anonymous>)
    at fulfilled (/home/jasonhk/Programming/NodeJS/Games/Pokemon/Super Secret Base/node_modules/tslib/tslib.js:107:62)


20190725_173833 20190725_173854

odahcam commented 5 years ago

This is a direct port, but you can't expect two completely different engines to produce the same result. Also, I was able to decode both images with the demo application. Checksum and Format errors are very common, once they can be generated by any external influences like movement and ilumination. Have you tried to decode these images using the Node APIs as you are doing with the Java version?

As this issue is too broad and lived too much, I'm closing this now because it's not an error with the library itself.

Feel free to contact-me for help or open a new issue if you think you found an error.

Krammig commented 6 months ago

The first QR code displayed above is missng the "data:image/png;base64," designation at the front of the string thus making it difficult if not impossible for most readers to identify as it will just appeaer as a strinf of data.