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

ITF barcode is not decoded in tiff image, but decoded in JPG image #512

Open SanKumSan opened 1 year ago

SanKumSan commented 1 year ago

I have an ITF barcode with 10 digits value.

When an scanned tiff image with ITF barcode, tried to decode this barcode, NO value is decoded. But the same image, when scanned as JPG, and tried to decode, it is decoded successfully.

I am wondering why the image format, tiff or jpeg, effects the decoding of this ITF value. Any inputs are appreciated.

micjahn commented 1 year ago

Can you provide the JPG and TIFF files?

SanKumSan commented 1 year ago

sample_Jpeg Here is a jpeg sample image with ITF barcode and it is decoded.

SanKumSan commented 1 year ago

https://github.com/SanKumSan/testercr7/blob/main/sample_tiff.tif

Here is the tiff file with the same ITF barcode and it is not decoded by ZXing.

Note : Tiff has LZW compression.

Does the compression of the tiff effects the decoding behaviour ?

Does the image formats (tiff, jpeg, png and others) effects the decoding behaviour ?

SanKumSan commented 1 year ago

Hello @micjahn ,

Are you able decode the sample tiff file for ITF barcode ? Thanks

micjahn commented 1 year ago

Sorry, I can't check it for the next three weeks. Anyway, the file format doesn't affect the decoding success. Internally every image format is converted to Bitmap before decoding. Only the compression algorithm of the format can in some cases affect the bitmap quality (difference between lossless and not lossless compression).

SanKumSan commented 1 year ago

Thanks @micjahn . Thanks for the answers.

micjahn commented 1 year ago

I couldn't decode both of them if I used the original image size. If I reduce the size to 75% both versions are successfully decoded. I think the main problem is more or less the black-and-white ratio of the image and the pixel artifacts in the black areas. Perhaps a real-world image with more content would give better results. Or you generally shrink the scanned image by 25% before decoding which reduces artifacts in the black areas.