micjahn / ZXing.Net

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

At all dpi's I get different results #471

Open Taldrit78 opened 1 year ago

Taldrit78 commented 1 year ago

I tried to get the barcode from this page Screenshot 2022-12-12 143259 I tried to get it with this code:

            Image currentPageImage = RenderPageToImage(CurrentPage, Dpi);

            BarcodeReader barcodeReader = new BarcodeReader()
            {
                AutoRotate = true,
                Options = new ZXing.Common.DecodingOptions()
                {
                    TryInverted = true,
                    PureBarcode = false,
                    TryHarder = true,
                    PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.AZTEC, BarcodeFormat.CODABAR, BarcodeFormat.CODE_39, BarcodeFormat.CODE_93, BarcodeFormat.CODE_128, BarcodeFormat.DATA_MATRIX, BarcodeFormat.EAN_8, BarcodeFormat.EAN_13, BarcodeFormat.ITF, BarcodeFormat.MAXICODE, BarcodeFormat.PDF_417, BarcodeFormat.QR_CODE, BarcodeFormat.RSS_14, BarcodeFormat.RSS_EXPANDED, BarcodeFormat.UPC_A, BarcodeFormat.UPC_E, BarcodeFormat.All_1D, BarcodeFormat.UPC_EAN_EXTENSION, BarcodeFormat.MSI, BarcodeFormat.PLESSEY, BarcodeFormat.IMB, BarcodeFormat.PHARMA_CODE }
                }
            };
            Result[] results = barcodeReader.DecodeMultiple((Bitmap)currentPageImage);
            Result = string.Empty;
            if (results != null)
            {
                foreach (Result result in results)
                {
                    Result += result.Text + Environment.NewLine;
                }
            }

If I now use 72 dpi (standard PDF dpi) I get no results. If I use 96 dpi (standard WPF dpi) I get = [95001, 6, 3] 150 dpi = [6, 9, 11117131, 7, 3, 8000, 4] 200 dpi = [14, 00800000000, 3, 6, 000, 00000000, 7, 35, 9, 4] 300 dpi = [6, 4, 3] 600 dpi = [6, 3, 8, 5, 7, 4]

So my question would be: "How can I get this barcode if I do NOT know in which codec it was printed?" We get different PDF documents and have to scan them for all barcodes. How could I achieve that or is it even possible with this library?

micjahn commented 1 year ago

You should not enable the barcode formats MSI, IMB and PharmaCode and are not widely used. They produce too many false positives. If you have a fixed list of formats that can be used with your forms, then enable only them. If you know that the code is always at a specific position or in a specific area you should crop the image before decoding.