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:
- 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.
- 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.
- 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.
- 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.