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.39k stars 536 forks source link

Cannot read property 'getCodewords' of null #318

Open hristijankiko opened 4 years ago

hristijankiko commented 4 years ago

Describe the bug PDF417 reader throws the error below sometimes (I would say 50% chance) when barcode gets presented to the camera.

To Reproduce Steps to reproduce the behavior:

  1. Launch reader
  2. Present barcode

Expected behavior It should not throw a TypeError exception when barcode is presented.

Screenshots Code used: image

Error: image

Desktop (please complete the following information):

odahcam commented 4 years ago

Thanks for the very well wirtten issue. This is related to #295 and #280.

iojancode commented 4 years ago

Similar issue here, not sure its the same:

PDF417 reader throws always the following error: null is not an object (evaluating 'this.detectionResultColumns[t-1].getCodewords') when barcode is presented, it happens 100% of the time

zacharytyhacz commented 3 years ago

Getting same issue too on Chrome and latest @zxing/library version.

Cannot read property 'getCodewords' of null

@odahcam I see there's recent commits, any progress on this particular issue?

image

zacharytyhacz commented 3 years ago

Can also confirm for:

Device: Iphone7 IOS 13.3.1 Browser: Safari

image

odahcam commented 3 years ago

I see there's recent commits, any progress on this particular issue?

No, I was finishing the text-encoding project, so no progress in here. My next goal is to implement E2E tests for the browser layer, so we should be able to spot and fix these kind of issues.

I'm a little rusty and really do not have time to debug PDF417 now, so unless there isn't possible, I would suggest some workaround. Sorry guys.

Also, just to give some context, it doesn't happen with every PDF417 type, but it seems just in one. There's in fact a piece of decoding that is not implemented in the codebase because we couldn't port the entire code at the time the module was ported from Java. Now I believe it should be a lot easier (as contributors and I fixed a lot of stuff, created similar code in other parts of the project), so if anyone wants to take a shot, just open a PR and ping me.

zacharytyhacz commented 3 years ago

I see there's recent commits, any progress on this particular issue?

No, I was finishing the text-encoding project, so no progress in here. My next goal is to implement E2E tests for the browser layer, so we should be able to spot and fix these kind of issues.

I'm a little rusty and really do not have time to debug PDF417 now, so unless there isn't possible, I would suggest some workaround. Sorry guys.

Also, just to give some context, it doesn't happen with every PDF417 type, but it seems just in one. There's in fact a piece of decoding that is not implemented in the codebase because we couldn't port the entire code at the time the module was ported from Java. Now I believe it should be a lot easier (as contributors and I fixed a lot of stuff, created similar code in other parts of the project), so if anyone wants to take a shot, just open a PR and ping me.

All good, E2E tests would point everything in the right direction and help a ton.

I'll create a mininal reproduced project very soon and provide some sample PDF 417 barcodes ( sample ID cards ) that work consistently and ones that throw this error ( I have a sample barcode that throws the error, both on the video scanning method and decodeFromImage method ) so we can narrow down whats going and go from there.

zacharytyhacz commented 3 years ago

@odahcam Hey yall, i recreated a simple project that recreates the issue here: https://github.com/zacharytyhacz/zxing-pdf417-bug

Also here's some sample codes that are in my test repo that we all can use to test things:

This one consistently fails on an image upload to scan decodeFromImage() and decodeOnceFromVideoDevice() image

This one is 50/50 if it fails or successfully scans decodeFromImage() and decodeOnceFromVideoDevice() ( this one is slightly blurry/low quality ) image

And no data get's found in this one, from both decodeFromImage() and decodeOnceFromVideoDevice() image

boxidilshan commented 3 years ago

I am also getting the same issue. Any workarounds to resolve this?

bradens commented 3 years ago

Also running into the same issue, getting noCodeWords and ChecksumException popping up a lot. Digging into the detector code that's throwing it's in the detector when trying to find the left/right alignment.

bradens commented 3 years ago

@zacharytyhacz did you end up solving the issue with those cards?

boxidilshan commented 3 years ago

It is a simple fix in DetectionResult.ts in core/pdf417/decoder. You have to add null checks in 2-3 places. Tried to merge that but I have lot of changes from the day I changed. Not sure whether this is fixed already. I could get it to work after fixing that.

zacharytyhacz commented 3 years ago

@bradens Hey there, no I do not have a work around at the moment.

@boxidilshan You are correct about that "fix", but if you test adding a null check, the scanning gets stuck in an endless loop for some images, not good.

bradens commented 3 years ago

I did a little bit more digging and it seemed to be problems with the error correction algorithm, testing against the zxing jarfile though, it seemed like it was having problems with the same images. I was able to fix my case by getting higher quality images, which I know isn't a great fix. :|

odahcam commented 3 years ago

@boxidilshan do you still have the code with the fixes you made?

DarrenWainwright commented 3 years ago

@boxidilshan - would it be possible to post where these 'fixes' can be applied?

Trying to get a POC together and this is killing me.. cheers

jakubsuszynski commented 3 years ago

Hello, any progress on this one? @odahcam

zacharytyhacz commented 3 years ago

I would like a progress update as well @odahcam

I may look back into the code myself and see if I could make a PR fix, but I am just not familiar with the codebase and adjusting the OCR or whatever it uses to image-parse the data could be complicated ( I've never dealt with stuff like this, thats why Im using this library )

odahcam commented 3 years ago

I injured my right arm and i am unable to contribute on the library for the past 4 weeks plus next 4 weeks. sorry guys, I'm doing everything I can so I heal faster.

outprove commented 2 years ago

@odahcam Hope your arm healed up!

I'm hitting this same issue as well. I'm not familiar with the code base, so if anyone has any pointers as to where/what the "fixes" are, I'd appreciate it.

zacharytyhacz commented 2 years ago

hello @outprove , I am planning on taking a look this weekend to hopefully find a fix and create a PR. the code is actually pretty organized and there are tests. If you have a reproduce-able issue project, that will help a lot