micjahn / ZXing.Net

.Net port of the original java-based barcode reader and generator library zxing
Apache License 2.0
2.7k stars 666 forks source link

Can't decode UPC-E and EAN-8 barcodes if they are on the same page. #423

Open sabiinlaw opened 2 years ago

sabiinlaw commented 2 years ago

I tried to use different barcode readers (BarcodeReader, GenericMultipleBarcodeReader) to decode single page file with multiple barcodes, but it can't find both UPC-E and EAN-8 barcodes together.

  1. It finds only UPC-E barcode if EAN-8 is on the same row.
  2. If I change input image file and move UPC-E barcode to another row - than EAN-8 is found, but UPC-E isn't. Please see attached test files: image1 image2
micjahn commented 2 years ago

ZXing.Net uses a very simple algorithm to find more than one barcode inside an image. Because of that, it can happen that not all codes will be found. Feel free to provide a PR with some enhancements.

Lakritzator commented 2 years ago

Maybe as a workaround you can draw something (e.g. a rectangle) over the detected barcores, using the ResultPoints in the result, and trigger another decode?

micjahn commented 2 years ago

Works only for 2D codes. For 1D codes you are getting only a line as the result points, not the whole rectangle.

sabiinlaw commented 2 years ago

As a workaround I tried some solutions from this article (https://localcoder.org/zxing-finding-the-bounding-rectangle-of-barcode), but it's not always possible to find correct coordinates. For now it is not that critical for me if some barcodes are missed and looks like a rare case when 2 barcodes placed exactly on same line. Thank you for your support 👍

Lakritzator commented 2 years ago

Not directly on topic, but some background information:

@micjahn I actually had a bit of an similar challenge, I added ZWing to Greenshot so it was able to provide the user with a way to use bar/QR codes on the screen. I noticed that it failed to find all when there are multiple. Back then I did the workaround which I mentioned, but I never released the functionality so there wasn't a lot of testing, I probably missed the use-case with a 1D code 🤷‍♂️ .

I might come back to that use-case, I also have similar stuff with text in the most recent versions, where one can select text (for the clipboard) directly from the screenshot. I was hoping to be able have the QR code positions too.

Example: image

micjahn commented 2 years ago

grafik The green rectangle shows the result points for QR decoding. In that case, it would work.

PDF417 should also work grafik

And this is a sample for 1D decoding grafik

ZXing saves the additional CPU cycles which are needed to find the whole rectangle.

Lakritzator commented 2 years ago

Thanks a lot for the thorough feedback, your examples is what I saw when I got the ResultPoints. But I never tested a 1D variant, that makes total sense for the recognition. 👍

axxel commented 1 year ago

For whom it may concern: https://github.com/zxing-cpp/zxing-cpp/ uses a completely different approach to detect multiple symbols in one image and detects all of the 9 symbols in the first image above just fine.

axxel commented 7 months ago

As a followup to my comment from last year: zxing-cpp now comes with a .NET wrapper.