Click here to Skip to main content
Click here to Skip to main content

Bug Fixes for Reading Barcodes from an Image - III

By , 5 Jul 2012
 

This post provides bug fixes for Reading Barcodes from an Image - III. The author was contacted, but did not have time to review the fixes, so both the author and CodeProject editors agreed this post was the best option.

In 2011 I started working on a contract management project. The relation between the contracts and some records in a database where done by using barcodes. In June 2012 we performed the last tests on the software. During the test, an attentive member of the test team noticed that the barcode for the ID 100328 was not readable. I checked the issue and found out that the reason was due to our barcode reader module. Due to the time constraint to look for a complete new solution I decided to debug the barcode reader software, which is based on the nice Reading Barcodes from an Image - III article. With the help of wikipedia and the smashing page Le code 128 I learned about the theory of Code128. I created a small test environment, based on open source software iTextSharp, to produce a huge amount of testscans in a loop. Within the test environment I found out that the original software has several major bugs. The bugs cause about 0.5% of the scans not recognizable by the original software.

Here are the bugs in details and how I have fixed them:

  1. Checksum can be longer than two characters

    Each Code128 barcode consists of several patterns which always have the following schema: Start - Data - Checksum - Stop

    The original code uses only two characters to save the checksum and didn't take into account that it can be longer, e.g. 102. I have fixed that by using a stringlist instead of a string.

  2. Confusion of checksum and change of codepage

    In Code128 it is possible to change the codepage. This is done by using a special pattern. In rare cases it is possible that the checksum at the end of the data-part of the code is a special pattern. In original code this causes an error because the checksum is lost. I fixed that by saving the special pattern until it is clear on whether it is the end of the barcode or a code page change.

  3. Not less than 4 narrow black bars in barcode

    The original code make an assumption that it is not possible to have less than 4 black bars in the barcode. I found out that this assumption is incorrect. It is possible to have only two black bars in the barcode, e.g. in the Code128 representation of the number 30.

  4. Usage of pipe symbols to separate scan results

    The original code use pipe symbols | to separate the results if there are more than one barcode on a page. This causes errors when using such symbol in the barcode. Again, I fixed that by using a stringlist instead of a string.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Matthias Böhnke
Software Developer Masters of Arts Anwendungsentwicklung GmbH
Germany Germany
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
SuggestionTwo correctionsmembermatiascabanillas4 Oct '12 - 9:36 
Congrats for your corrections!!! Its help me a lot.
I founded two errors on that.
 
1- At line 1258
//Matthias Boehnke - ERRORFIX 02 - Part 2
//------------------------------
//It was a CodePage change, not a checksum.
//Replace the content of the last item with an empty string,
//because it is only a control value, not part of the data.
if (sResult.Count > 0)
{
    sResult[sResult.Count - 1] = "";
}
 
I included if statment just in case it happend at first time
 
2- At line 1198: there is an append pipe...
 
I replace by an other character in this way...
 
if (sbCode128Data.Length > 0)
                     sbCode128Data.Append("☼");
                     foreach (string stringInList in sCode128Code)
                        {
                            sbCode128Data.Append(stringInList);
                        }
 
and I added corrsponding lines on 270
 
string sCode128 = ParseCode128(sbEANPattern);
                    if (sCode128.Length > 0)
                    {
                        string[] listResult = sCode128.Split('☼');
                        for (int i = 0; i < listResult.Length; i++)
                        {
                            lBarCodes.Add(listResult[i]);
                        }
                    }
 

I hope its help.
QuestionHow to use this code?membervv_ekb21 Sep '12 - 7:53 
Excuse me, how to use this code?
 
Thanks!
QuestionSmall test environmentmemberMember 69975798 Sep '12 - 3:37 
There would be able to provide your test environment with itextsharp?
From already thank you.
GeneralThanks!memberFurryPlatypus6 Jul '12 - 9:11 
I appreciate the heads-up on the other issues... you saved me some future headaches Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 5 Jul 2012
Article Copyright 2012 by Matthias Böhnke
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid