question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decoding not consistent

See original GitHub issue

Hi, I have a problem with the decoding of a Qr code image, that i’m passing as a base64 string to the decodeFromImage function, as following

 const codeReader = new BrowserQRCodeReader();
    codeReader.decodeFromImage(undefined, this.state.qrImage)
      .then(
        (result) => { this.showSuccessMessage('The QR is valid!'); console.log(result.getResultMetadata()); }
      )
      .catch(
        () => this.showErrorMessage('The QR is unreadable.')
      );

When I execute this code multiple times on the same image, the result is not consistent. Sometimes the decoding works and it return the correct result, but other times it throws an exception, and prints in the console the following errors

checksum or format error, trying again... Error
    at Decoder.correctErrors (Decoder.js?958e:154)
    at Decoder.decodeBitMatrixParser (Decoder.js?958e:125)
    at Decoder.decodeBitMatrix (Decoder.js?958e:70)
    at QRCodeReader.decode (QRCodeReader.js?680d:64)
    at BrowserQRCodeReader.BrowserCodeReader.readerDecode (BrowserCodeReader.js?0615:254)
    at BrowserQRCodeReader.BrowserCodeReader.decodeOnce (BrowserCodeReader.js?0615:229)

BrowserCodeReader.js?0615:233 true Error
    at Decoder.correctErrors (Decoder.js?958e:154)
    at Decoder.decodeBitMatrixParser (Decoder.js?958e:125)
    at Decoder.decodeBitMatrix (Decoder.js?958e:70)
    at QRCodeReader.decode (QRCodeReader.js?680d:64)
    at BrowserQRCodeReader.BrowserCodeReader.readerDecode (BrowserCodeReader.js?0615:254)
    at BrowserQRCodeReader.BrowserCodeReader.decodeOnce (BrowserCodeReader.js?0615:229)

I wait for an answer. Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
odahcamcommented, Aug 14, 2018

I couldn’t find any very obvious errors, but I’m a little busy at the moment. I can offeryou an working example you can find in the docs:

const img = document.getElementById('img')

codeReader.decodeFromImage(img).then((result) => {
    console.log(result)
    document.getElementById('result').textContent = result.text
}).catch((err) => {
    console.error(err)
    document.getElementById('result').textContent = err
})

source: https://github.com/zxing-js/library/blob/af16fdb2a72b331394dfe22b549703bdfefcae90/docs/examples/qr-image/index.html#L1

(The demo just don’t work online, locally it works fine andyou can use it)

I see you’re using Base64 encoded images and I think that there’s really a bug in the code, that’s not that good yet. You can create your own image element and trigger the decodeOnce on image’s onload event. E.g.:

const imageElement = document.createElement('img');
imageElement.width = 200;
imageElement.height = 200;

imageElement.addEventListener('load', () => scanner.decodeFromImage(imageElement));
imageElement.src = imageUrl;

I hope that it helps.

1reaction
werthdavidcommented, Aug 6, 2018

I’m not exactly sure what kind of answer you’re expecting. The Decoder goes through a lot of steps to detect if a given image contains a valid QR-code, it seems that your code fails in the error-correction step. If you want a qualified answer it would help if you could provide the image that causes the actual problem along with information about which version of the library you used, the platform (node, browser, ionic), browser etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Encoding/Decoding not working on Dictionary Objects
I'm trying to Encode/Decode an object in order to store it in UserDefaults. My object contains a Dictionary object contining a key, with...
Read more >
iphone - NSDateFormatter encoding vs decoding is not consistent ...
When I use this date formatter, it's not giving me back the same date I start with if I got from date ->...
Read more >
Consistency of a Recurrent Language Model With Respect to ...
We prove that commonly used incomplete decoding algorithms - greedy search, beam search, top-k sampling, and nucleus sampling - are inconsistent ...
Read more >
Decoding not working - main@WSJTX.groups.io
I upgraded my computer to windows 10 and now I can't decode any FT8 signals. The receive status bar is green and at...
Read more >
SOLVED: JSON decoding not working - Hacking with Swift
SOLVED: JSON decoding not working ... The issue is that I am running a JSON decoder that is the same as Paul's tutorials...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found