micjahn / ZXing.Net

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

Failed to recognize Barcode #508

Open Korzer420 opened 1 year ago

Korzer420 commented 1 year ago

Hey,

I've encountered a problem where a clear barcode couldn't be recognized by the BarcodeReader. I tried with all kinds of different options on the reader but without any success.

Below are the two versions of the image that I tried to use: Test3_Identifier Test3_Identifier2

In both images the code is in the middle (in case git formats the images a bit weird)

This is the code I'm using

BarcodeReader<Bitmap> barcodeReader = new BarcodeReader<Bitmap>(null,
            bitmap => new BitmapLuminanceSource(bitmap),
                        luminance => new GlobalHistogramBinarizer(luminance))
            {
                Options =
                {
                    CharacterSet = "ISO-8859-1",
                    TryHarder = true,
                    ReturnCodabarStartEnd = true
                }
            };
            Result[] result;
            using (Bitmap image = new Bitmap("C:\\Test\\Barcode\\Test3_Identifier2.png"))
                result = barcodeReader.DecodeMultiple(image);

Small note that the type of barcode is unknown by the time the image is provided, so I can't really pass any possible formats on the options, in case that would help.

Thank you^^

rob313663 commented 1 year ago

The images you provided are exactly the same, the only thing that differs is the quiet space. What tool/library generated them?

rob313663 commented 1 year ago

The first ten modules correspond to Interleaved 2 of 5 codeword "29":

{ "29", new Interleaved2Of5CodeWord() { Pattern = "bsBSbsbSBs" } },

You can manually check the rest for yourself if you like with the table below.

It looks like a really broken and invalid barcode. My guess it is an Interleaved 2 of 5 missing start and stop patterns.

        codewordPatterns = new Dictionary<string, Interleaved2Of5CodeWord>
        {
            { "00", new Interleaved2Of5CodeWord() { Pattern = "bsbsBSBSbs" } },
            { "01", new Interleaved2Of5CodeWord() { Pattern = "bSbsBsBsbS" } },
            { "02", new Interleaved2Of5CodeWord() { Pattern = "bsbSBsBsbS" } },
            { "03", new Interleaved2Of5CodeWord() { Pattern = "bSbSBsBsbs" } },
            { "04", new Interleaved2Of5CodeWord() { Pattern = "bsbsBSBsbS" } },
            { "05", new Interleaved2Of5CodeWord() { Pattern = "bSbsBSBsbs" } },
            { "06", new Interleaved2Of5CodeWord() { Pattern = "bsbSBSBsbs" } },
            { "07", new Interleaved2Of5CodeWord() { Pattern = "bsbsBsBSbS" } },
            { "08", new Interleaved2Of5CodeWord() { Pattern = "bSbsBsBSbs" } },
            { "09", new Interleaved2Of5CodeWord() { Pattern = "bsbSBsBSbs" } },
            { "10", new Interleaved2Of5CodeWord() { Pattern = "BsbsbSbSBs" } },
            { "11", new Interleaved2Of5CodeWord() { Pattern = "BSbsbsbsBS" } },
            { "12", new Interleaved2Of5CodeWord() { Pattern = "BsbSbsbsBS" } },
            { "13", new Interleaved2Of5CodeWord() { Pattern = "BSbSbsbsBs" } },
            { "14", new Interleaved2Of5CodeWord() { Pattern = "BsbsbSbsBS" } },
            { "15", new Interleaved2Of5CodeWord() { Pattern = "BSbsbSbsBs" } },
            { "16", new Interleaved2Of5CodeWord() { Pattern = "BsbSbSbsBs" } },
            { "17", new Interleaved2Of5CodeWord() { Pattern = "BsbsbsbSBS" } },
            { "18", new Interleaved2Of5CodeWord() { Pattern = "BSbsbsbSBs" } },
            { "19", new Interleaved2Of5CodeWord() { Pattern = "BsbSbsbSBs" } },
            { "20", new Interleaved2Of5CodeWord() { Pattern = "bsBsbSbSBs" } },
            { "21", new Interleaved2Of5CodeWord() { Pattern = "bSBsbsbsBS" } },
            { "22", new Interleaved2Of5CodeWord() { Pattern = "bsBSbsbsBS" } },
            { "23", new Interleaved2Of5CodeWord() { Pattern = "bSBSbsbsBs" } },
            { "24", new Interleaved2Of5CodeWord() { Pattern = "bsBsbSbsBS" } },
            { "25", new Interleaved2Of5CodeWord() { Pattern = "bSBsbSbsBs" } },
            { "26", new Interleaved2Of5CodeWord() { Pattern = "bsBSbSbsBs" } },
            { "27", new Interleaved2Of5CodeWord() { Pattern = "bsBsbsbSBS" } },
            { "28", new Interleaved2Of5CodeWord() { Pattern = "bSBsbsbSBs" } },
            { "29", new Interleaved2Of5CodeWord() { Pattern = "bsBSbsbSBs" } },
            { "30", new Interleaved2Of5CodeWord() { Pattern = "BsBsbSbSbs" } },
            { "31", new Interleaved2Of5CodeWord() { Pattern = "BSBsbsbsbS" } },
            { "32", new Interleaved2Of5CodeWord() { Pattern = "BsBSbsbsbS" } },
            { "33", new Interleaved2Of5CodeWord() { Pattern = "BSBSbsbsbs" } },
            { "34", new Interleaved2Of5CodeWord() { Pattern = "BsBsbSbsbS" } },
            { "35", new Interleaved2Of5CodeWord() { Pattern = "BSBsbSbsbs" } },
            { "36", new Interleaved2Of5CodeWord() { Pattern = "BsBSbSbsbs" } },
            { "37", new Interleaved2Of5CodeWord() { Pattern = "BsBsbsbSbS" } },
            { "38", new Interleaved2Of5CodeWord() { Pattern = "BSBsbsbSbs" } },
            { "39", new Interleaved2Of5CodeWord() { Pattern = "BsBSbsbSbs" } },
            { "40", new Interleaved2Of5CodeWord() { Pattern = "bsbsBSbSBs" } },
            { "41", new Interleaved2Of5CodeWord() { Pattern = "bSbsBsbsBS" } },
            { "42", new Interleaved2Of5CodeWord() { Pattern = "bsbSBsbsBS" } },
            { "43", new Interleaved2Of5CodeWord() { Pattern = "bSbSBsbsBs" } },
            { "44", new Interleaved2Of5CodeWord() { Pattern = "bsbsBSbsBS" } },
            { "45", new Interleaved2Of5CodeWord() { Pattern = "bSbsBSbsBs" } },
            { "46", new Interleaved2Of5CodeWord() { Pattern = "bsbSBSbsBs" } },
            { "47", new Interleaved2Of5CodeWord() { Pattern = "bsbsBsbSBS" } },
            { "48", new Interleaved2Of5CodeWord() { Pattern = "bSbsBsbSBs" } },
            { "49", new Interleaved2Of5CodeWord() { Pattern = "bsbSBsbSBs" } },
            { "50", new Interleaved2Of5CodeWord() { Pattern = "BsbsBSbSbs" } },
            { "51", new Interleaved2Of5CodeWord() { Pattern = "BSbsBsbsbS" } },
            { "52", new Interleaved2Of5CodeWord() { Pattern = "BsbSBsbsbS" } },
            { "53", new Interleaved2Of5CodeWord() { Pattern = "BSbSBsbsbs" } },
            { "54", new Interleaved2Of5CodeWord() { Pattern = "BsbsBSbsbS" } },
            { "55", new Interleaved2Of5CodeWord() { Pattern = "BSbsBSbsbs" } },
            { "56", new Interleaved2Of5CodeWord() { Pattern = "BsbSBSbsbs" } },
            { "57", new Interleaved2Of5CodeWord() { Pattern = "BsbsBsbSbS" } },
            { "58", new Interleaved2Of5CodeWord() { Pattern = "BSbsBsbSbs" } },
            { "59", new Interleaved2Of5CodeWord() { Pattern = "BsbSBsbSbs" } },
            { "60", new Interleaved2Of5CodeWord() { Pattern = "bsBsBSbSbs" } },
            { "61", new Interleaved2Of5CodeWord() { Pattern = "bSBsBsbsbS" } },
            { "62", new Interleaved2Of5CodeWord() { Pattern = "bsBSBsbsbS" } },
            { "63", new Interleaved2Of5CodeWord() { Pattern = "bSBSBsbsbs" } },
            { "64", new Interleaved2Of5CodeWord() { Pattern = "bsBsBSbsbS" } },
            { "65", new Interleaved2Of5CodeWord() { Pattern = "bSBsBSbsbs" } },
            { "66", new Interleaved2Of5CodeWord() { Pattern = "bsBSBSbsbs" } },
            { "67", new Interleaved2Of5CodeWord() { Pattern = "bsBsBsbSbS" } },
            { "68", new Interleaved2Of5CodeWord() { Pattern = "bSBsBsbSbs" } },
            { "69", new Interleaved2Of5CodeWord() { Pattern = "bsBSBsbSbs" } },
            { "70", new Interleaved2Of5CodeWord() { Pattern = "bsbsbSBSBs" } },
            { "71", new Interleaved2Of5CodeWord() { Pattern = "bSbsbsBsBS" } },
            { "72", new Interleaved2Of5CodeWord() { Pattern = "bsbSbsBsBS" } },
            { "73", new Interleaved2Of5CodeWord() { Pattern = "bSbSbsBsBs" } },
            { "74", new Interleaved2Of5CodeWord() { Pattern = "bsbsbSBsBS" } },
            { "75", new Interleaved2Of5CodeWord() { Pattern = "bSbsbSBsBs" } },
            { "76", new Interleaved2Of5CodeWord() { Pattern = "bsbSbSBsBs" } },
            { "77", new Interleaved2Of5CodeWord() { Pattern = "bsbsbsBSBS" } },
            { "78", new Interleaved2Of5CodeWord() { Pattern = "bSbsbsBSBs" } },
            { "79", new Interleaved2Of5CodeWord() { Pattern = "bsbSbsBSBs" } },
            { "80", new Interleaved2Of5CodeWord() { Pattern = "BsbsbSBSbs" } },
            { "81", new Interleaved2Of5CodeWord() { Pattern = "BSbsbsBsbS" } },
            { "82", new Interleaved2Of5CodeWord() { Pattern = "BsbSbsBsbS" } },
            { "83", new Interleaved2Of5CodeWord() { Pattern = "BSbSbsBsbs" } },
            { "84", new Interleaved2Of5CodeWord() { Pattern = "BsbsbSBsbS" } },
            { "85", new Interleaved2Of5CodeWord() { Pattern = "BSbsbSBsbs" } },
            { "86", new Interleaved2Of5CodeWord() { Pattern = "BsbSbSBsbs" } },
            { "87", new Interleaved2Of5CodeWord() { Pattern = "BsbsbsBSbS" } },
            { "88", new Interleaved2Of5CodeWord() { Pattern = "BSbsbsBSbs" } },
            { "89", new Interleaved2Of5CodeWord() { Pattern = "BsbSbsBSbs" } },
            { "90", new Interleaved2Of5CodeWord() { Pattern = "bsBsbSBSbs" } },
            { "91", new Interleaved2Of5CodeWord() { Pattern = "bSBsbsBsbS" } },
            { "92", new Interleaved2Of5CodeWord() { Pattern = "bsBSbsBsbS" } },
            { "93", new Interleaved2Of5CodeWord() { Pattern = "bSBSbsBsbs" } },
            { "94", new Interleaved2Of5CodeWord() { Pattern = "bsBsbSBsbS" } },
            { "95", new Interleaved2Of5CodeWord() { Pattern = "bSBsbSBsbs" } },
            { "96", new Interleaved2Of5CodeWord() { Pattern = "bsBSbSBsbs" } },
            { "97", new Interleaved2Of5CodeWord() { Pattern = "bsBsbsBSbS" } },
            { "98", new Interleaved2Of5CodeWord() { Pattern = "bSBsbsBSbs" } },
            { "99", new Interleaved2Of5CodeWord() { Pattern = "bsBSbsBSbs" } },
        };
Korzer420 commented 1 year ago

Hey, sorry for the late response.

The code was generated via labeljoy and the snippet of only the barcode was created with gimp. Below is the full pdf file. In both cases the barcode could not be read. labeljoy-code-Code11-1687868946318 (1).pdf