rxing-core / rxing

cRustacean Crossing
https://crates.io/crates/rxing
Apache License 2.0
198 stars 19 forks source link

Brazillian barcode not being decoded #49

Closed filipesilva-l closed 3 months ago

filipesilva-l commented 3 months ago

Hi,

First of all, thank you for this amazing library.

I was testing it with a few examples, and the library is not detecting the I25 or ITF barcode:

test_brazillian_barcode

Using the CLI as an example, when I try to read this image, it correctly reads the two QR codes, but it doesn't detect the ITF barcode:

image

Using the online ZXing decoder, the ITF barcode can be read without any problems.

image

I have put together a simple repository that demonstrates the issue: GitHub Repository.

I'm trying to convert a PDF into an image and read the barcode from it, which is why the image is so large (there is more content, but I can't share it here). Should I be using the library in a different way? Any help is appreciated.

Thanks!

hschimke commented 3 months ago

I'll look into it, thanks for the report.

hschimke commented 3 months ago

I'm able to get it working with the "try_harder" option (-t on the cli).

In code, you can find an example here: https://github.com/rxing-core/rxing/blob/ec30be51fcba8a9deb99c8c52c2d18f3cc8316db/tests/github_issues.rs#L356

but the relevant part of the setup is:

let mut hints = DecodingHintDictionary::default();
hints.entry(DecodeHintType::TRY_HARDER)
     .or_insert(DecodeHintValue::TryHarder(true));

I'm happy to investigate more if this doesn't fix your issue.

hschimke commented 3 months ago

Going into a little more detail about why this is occurring, and probably what you would want if you only wanted the ITF code.

Because the line-reading function of the 1-d barcode isn't exceptionally efficient, it is only checked a few times in an image. It's likely that the ITF would be found in a cropped image, but, because of the dimensions of the input image it's unable to locate it. For large images, it's very possible to miss barcodes because of how the lines to be checked are calculated. Turning on try-harder tells the library to worry less about speed/efficiency and instead select correctness. This has numerous implications, but for 1-d barcodes it means that it checks many more lines throughout the image, and that it also checks for things like reversed barcodes.

To speed things up, if you ONLY care about the ITF code then tell the library to only scan for that barcode type, it will skip a lot of detection logic for codes you don't care about.

filipesilva-l commented 3 months ago

Hi, sorry for the delay. Thanks a lot!

I've just tested it and it works as expected when I pass the try harder hint.