Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to scan PDF_417 codes... #527

Open
rlyle opened this issue Jul 13, 2022 · 17 comments
Open

Unable to scan PDF_417 codes... #527

rlyle opened this issue Jul 13, 2022 · 17 comments

Comments

@rlyle
Copy link

rlyle commented Jul 13, 2022

Hi, trying to scan the back of a drivers license, the picture is certainly clear and large enough, but it does nothing but dump this error into the logs...

index.js:1 deocdeFromVideoDevice error: ChecksumException
at ChecksumException.getChecksumInstance (http://localhost:3000/static/js/vendors~main.chunk.js:91679:12)
at PDF417ScanningDecoder.createDecoderResultFromAmbiguousValues (http://localhost:3000/static/js/vendors~main.chunk.js:116280:70)
at PDF417ScanningDecoder.createDecoderResult (http://localhost:3000/static/js/vendors~main.chunk.js:116219:34)
at PDF417ScanningDecoder.decode (http://localhost:3000/static/js/vendors~main.chunk.js:115963:34)
at PDF417Reader.decode (http://localhost:3000/static/js/vendors~main.chunk.js:112829:100)
at PDF417Reader.decode (http://localhost:3000/static/js/vendors~main.chunk.js:112776:31)
at BrowserCodeReader.decodeBitmap (http://localhost:3000/static/js/vendors~main.chunk.js:86999:24)
at BrowserCodeReader.decodeFromCanvas (http://localhost:3000/static/js/vendors~main.chunk.js:87008:17)
at loop (http://localhost:3000/static/js/vendors~main.chunk.js:87775:28)

I've been trying for hours to scan a PDF_417 off the back of my license, I don't think it's a blurry image or anything like that, just simply think something is wrong with the checksum calculations for this bar code format.

Can anyone else scan a PDF_417 with this library?

@rlyle
Copy link
Author

rlyle commented Jul 13, 2022

P.S. none of the sample PDF_417 in the live demo are working either..

image

@rlyle
Copy link
Author

rlyle commented Jul 13, 2022

P.S. I did see this other type of error pop up as well, while trying to scan..

index.js:1 deocdeFromVideoDevice error: NotFoundException
at NotFoundException.getNotFoundInstance (http://localhost:3000/static/js/vendors~main.chunk.js:93051:12)
at PDF417ScanningDecoder.adjustCodewordCount (http://localhost:3000/static/js/vendors~main.chunk.js:116158:74)
at PDF417ScanningDecoder.createDecoderResult (http://localhost:3000/static/js/vendors~main.chunk.js:116179:27)
at PDF417ScanningDecoder.decode (http://localhost:3000/static/js/vendors~main.chunk.js:115963:34)
at PDF417Reader.decode (http://localhost:3000/static/js/vendors~main.chunk.js:112829:100)
at PDF417Reader.decode (http://localhost:3000/static/js/vendors~main.chunk.js:112776:31)
at BrowserCodeReader.decodeBitmap (http://localhost:3000/static/js/vendors~main.chunk.js:86999:24)
at BrowserCodeReader.decodeFromCanvas (http://localhost:3000/static/js/vendors~main.chunk.js:87008:17)
at loop (http://localhost:3000/static/js/vendors~main.chunk.js:87775:28)

@ozzmaster
Copy link

I have the same issue.

I would also like to use this PDF417 scan via the camera and not just an image. Is this possible?

Thank you so much for a great library!

@ozzmaster
Copy link

The PDF417 bar code scanner is working, but another bar code I am trying to scan is encrypted. Is it possible to retrieve the raw data from the scan, instead of letting zxing decode the data to JSON? I have a different library that can decrypt the data.

@bea314
Copy link

bea314 commented Sep 1, 2022

I have the same problem. I made it work unencrypted with this code:

const fs     = require('fs');
const jpeg    = require('jpeg-js');
const { MultiFormatReader, BarcodeFormat, RGBLuminanceSource, BinaryBitmap, HybridBinarizer, DecodeHintType, PDF417Reader } = require('@zxing/library');

async function ServiceTest(req, res) {

  var path = '{your file's path}/test01.png';
  
  let pathData = await fs.readFileSync(path);
  let decoded;

  let rawImageData = await jpeg.decode(pathData) ;
  
  const hints = new Map();
  const formats = [BarcodeFormat.PDF_417];
  hints.set(DecodeHintType.POSSIBLE_FORMATS, formats);
  hints.set(DecodeHintType.TRY_HARDER, true);
  hints.set(DecodeHintType.PURE_BARCODE, true);
  hints.set(DecodeHintType.PURE_BARCODE, true);
  const reader = new PDF417Reader(hints);

  const len = rawImageData.width * rawImageData.height

  const luminancesUint8Array = new Uint8ClampedArray(len);

  for (let i = 0; i < len; i++) {
    luminancesUint8Array[i] = ((rawImageData.data[i * 4] + rawImageData.data[i * 4 + 1] * 2 + rawImageData.data[i * 4 + 2]) / 4) & 0xff;
  }

  const luminanceSource = new RGBLuminanceSource(luminancesUint8Array, rawImageData.width, rawImageData.height);
  const binaryBitmap    = new BinaryBitmap(new HybridBinarizer(luminanceSource));
  
  const detection = reader.decode(binaryBitmap);
  
  console.log(detection.getText());
  console.log(detection.getBarcodeFormat());
  console.log(detection.putAllMetadata());
}

However, when I try to read an encrypted PDF417, I get some errors.

If i use "PDF417Reader":
image

If i use "MultiFormatReader":
image

Did you find a solution?

@WhatTheChad
Copy link

@rlyle - Were you ever able to get the back of drivers license scan working?

I have the same use case and am getting the same error. I've tried all the way up to 600dpi quality scan in both black and white and color using the ZXing.BrowserPDF417Reader or the ZXing.MultiFormatReader

@drborges
Copy link

I was having the same issue and this suggested workaround got me going.

@rlyle
Copy link
Author

rlyle commented Mar 10, 2023

@rlyle - Were you ever able to get the back of drivers license scan working?

I have the same use case and am getting the same error. I've tried all the way up to 600dpi quality scan in both black and white and color using the ZXing.BrowserPDF417Reader or the ZXing.MultiFormatReader

Nope, we just gave up on supporting PC scanning.. which was ok for us, as our primary users are on iOS and android.

@matias-facenote
Copy link

For me the reason it was not working was that I was passing a UInt8ClampedArray. Apparently, it only works with Int32Array so the workaround was doing new Int32Array(clampedArray.buffer)

Copy link

Stale issue message

@PaulMColeman
Copy link

P.S. none of the sample PDF_417 in the live demo are working either..

image

Okay, I have been having the same issue. The Current Demo DOES work, but only on the second press. I have not found a way to make it work on a single press. First Decode gives an "N" and console errors described above. Second press DOES work correctly.

I found that if you go back to Version 0.18.6 the Demo Works correctly, and as expected for Decoding PDF417.
Something happened in 0.19.0 and on, and has not worked since then, but I couldn't tell you what.

so for now, I'm going to go with 18.6 and hope for the best with my PDF417 Project.

Good Luck all.

@werthdavid
Copy link
Member

Did a Git Bisect... The error comes from changes made here: #420

@werthdavid
Copy link
Member

I will try to fix that without breaking the feature from #420 ...

@werthdavid
Copy link
Member

The feature #420 was introduced to scan inverted codes. Now what happens is that for every scan, it is first tried by inverting the colors and the next scan it is tried with original colors. You can see that in the online example, if you press once, nothing is found, the second time it gets decoded correctly. The feature was intended for continuous video scan where there are several scans per second so it is not a problem... I will try to change the behavior so that the invert code is by default only applied in continuous scan mode.
any thoughts?

werthdavid added a commit that referenced this issue Aug 20, 2024
@werthdavid
Copy link
Member

please take a look at the PR. some feedback would be nice before merging

werthdavid added a commit that referenced this issue Aug 21, 2024
@werthdavid
Copy link
Member

Plz test v0.21.3 guys and let me know if that helped

@BryanPaoli
Copy link

Hi!

I'm currently trying to decode PDF 417 with the latest version (0.21.3) and still get:
Error decoding the barcode: NotFoundException2: No MultiFormat Readers were able to detect the code.
When I use a random file from the internet, it does work, but with a driver's license it doesn't.

I did test the same images on https://zxing.org/w/decode.jspx and all of my images are decoded correctly.

I tested it with PDF417Reader(), which seems to detect the barcode in an image, but it only worked with one of my examples. I'm not sure if the issue is related to image quality, as the one that worked was actually one of the more blurred images.

This is what I have right now, not sure if I'm doing something wrong. I'd appreciate any help:

const handleDecode = async (e: Event) => {
    const image = document.getElementById('decode') as HTMLImageElement;
    if (!image) {
      console.error("Image element not found");
      return;
    }

    const codeReader = new BrowserMultiFormatReader();

    codeReader.hints = new Map()
        .set(DecodeHintType.TRY_HARDER, true)
        .set(DecodeHintType.PURE_BARCODE, true)
        .set(DecodeHintType.POSSIBLE_FORMATS, [BarcodeFormat.PDF_417, BarcodeFormat.UPC_E]);

    try {
      console.log("Decoding image...");
      const result = await codeReader.decodeFromImage(image);
      console.log("Decoded result outside:", result);
    } catch (error) {
      console.error("Error decoding the barcode:", error);
    }
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants