ericblade / quagga2

An advanced barcode-scanner written in Javascript and TypeScript - Continuation from https://github.com/serratus/quaggajs
MIT License
758 stars 85 forks source link

Adding external barcode reader for PDF417 barcodes #388

Open victory-glitch opened 2 years ago

victory-glitch commented 2 years ago

Hi @ericblade , I saw your comment in https://github.com/serratus/quaggaJS/issues/70#issuecomment-396465816 where you mentioned that it could be possible to wire up js-zxing-pdf417 to quagga with the help of an external decoder. I am interested in using quagga to read pdf417 barcodes off of scanned documents that users will upload.

The quagga2 readme mentions that a qr-reader has been integrated in a separate repo, but the qr-reader doesn't use the BarcodeReader prototype for integration. I am wondering if making a PDF417 reader should follow the same path that the qr-reader is doing, considering that both qr and pdf417 are 2D barcodes?

github-actions[bot] commented 2 years ago

Thank you for filing an issue! Please be patient. :-)

ericblade commented 2 years ago

I believe that BarcodeReader is going to be probably mostly only useful for 1D barcodes, although if it were extended to be able to detect the area that 2D barcodes occupy, that would be a great improvement, as I'm sure providing just the imagedata that actually needs to be decoded would make it easier for any decoder to figure out.

So, yeah, I think probably best to wire it like the prototype QR reader, which simply takes the entire image data, and passes it to a separate library that figures it out from the entire image.

That said, if you are able to get any useful output from BarcodeReader as to where the rectangle that contains the barcode is, that would probably improve your chances of getting a good read.

victory-glitch commented 2 years ago

Thanks for the clarification! Can you explain more about "extending BarcodeReader to detect the area that 2D barcodes occupy":

  1. Is this a change that I would commit to the quagga2 repo?
  2. Assuming it is, then I assume all relevant changes would only need to be made in barcode_reader.ts, right?
  3. Assuming yes, can you provide some insight as to what the 5 protected functions in the BarcodeReader class are doing? (there's no documentation, so it's not entirely clear what role _nextUnset or _matchPattern is supposed to do)
  4. It seems public decodePattern(pattern: Array<number>) is the only function that we would override if we are going to create our own plugin on top of BarcodeReader. Assuming that the 2D processing is implemented, would that function signature change to something like public decodePattern(pattern: Array<Array<number>>)? Or should we add an entirely new function in BarcodeReader that users can override (eg public decodePattern2D(pattern: Array<Array<number>>)?
victory-glitch commented 2 years ago

@ericblade Hi, just following up on the above questions. Even if you don't have a complete answer for every question, even a partial answer for each question (eg knowledge of some functions) would be hugely helpful.

ericblade commented 2 years ago

@hareharey sorry, I didn't notice the first reply! Thanks for getting my attention again

One of the more important features in Quagga, I think, is the Locator in src/locator/barcode_locator , which figures out where in an image a barcode-like area is found, which I'm pretty sure if found, then goes through some processing to send only that area through to the decoder.

I was thinking if the locator could locate 2D barcodes as well as 1D, then even if we don't have any built in BarcodeReader classes that can handle it, we could at least make the job for whatever does read the code easier. Maybe my psuedo-solution of just passing the entire image to an external 2D reader would be fine, too.

I don't really know anything about 1D vs 2D codes, or if there is any standard delineation around them.

I also don't know if any of the pieces of BarcodeReader would be useful in decoding them. I honestly don't think, with such a good library as zxing-js available, that we would gain a lot by implementing a whole Reader/Decoder system, but there might be value to a Locator. There definitely is value in the locator in 1D barcodes, I tried a lot of barcode systems before quagga, and quagga was the only one that consistently was able to decode sideways and diagonal 1D codes

TonyKhorouzan commented 1 year ago

I am also interested in PDF417 barcodes.

It is important to distinguish between the more common types of barcodes:

  1. 1-dimensional barcodes
  2. 1-dimensional "stacked" barcodes. This includes PDF417, Code 49, and Code 16k. Effectively there are a series of small height bar codes that are stacked on top of each other. They have leading and trailing signatures that are the full height of the stacked bar codes. These signatures likely violate the standard "quiet zone" of a normal 1D barcode as they are in the zone and have their own quiet zone.
  3. True 2-dimensional bar codes, such as QR Codes, Data Matrix, Code One, and Aztec codes. These have special markers that help identify and locate the barcode.

The challenge with PDF417 may include increasing the resolution of the scanning (eliminating half-sample and decreasing the patch size) so that the individual bar codes that are stacked are recognized, changing the recognition of the quiet zone, and detecting the prefixing and suffixing signature.