SoftwarePractice.org: Home | Courseware | Wiki | Archive

Image Processing to Barcode Reader

From SoftwarePractice.org

Contents

Bridging the gap

The image processor outputs a single, one dimensional binary array (i.e. 1s and 0s representing black and white). This is essentially taken as a line across the centre of the barcode. The following processes take the output from the image processor and format them in a way that the barcode reader can interpret.

Training algorithm

Prior to reading the barcode the following issues remain, firstly the application needs to learn the widths expected for the various elements of the barcode, what width consitites a wide element and what width constitutes a narrow. This is achieved through the use of a training process does the following:

  • Reads the array until it finds a dark section (i.e. a 1)
  • Determines the width of this first dark element by reading until a 0 is found
  • Repeats this process for the first 9 elements
  • Assumes the width of the first element to be the width of a narrow element and the following, the width of a wide element (based on the code of a star character)
  • Ensures that the ratio of the wide and narrow widths is within the standard
  • Calculates the acceptable variance in the widths of each element defining a clear cutoff point
  • Ensures that the first 9 elements fit the sequence of NWNNWNWNN (i.e. a star character)

This will return the follwing parameters for use by the preprocessor:

  • The expected width of a narrow element
  • The expected width of a wide element
  • The next array element to be read (after the star character)
  • The variance

Preprocessor

The next issue is presenting information to the barcode reader in a usable fashion. This is done by the preprocessor. This uses the inputs from the training algorithm and converts the inputs as follows:

  • A narrow element is shown as a 0 if it is a space or a 1 if it is a bar
  • A wide element is shown as a 00 if it is a space or a 11 if it is a bar
  • In accordance with the standard the space between characters is shown as a narrow space (i.e. a 0)

The preprocessor applies the same variance as is applied in the training algorithm.

Variance

Whilst the Code39 standard has tight restrictions on variance in the elements of a barcode we have elected to use relatively high tolerences to variation. We feel this is acceptable as the target is barcode recognition within an image, regardless of the image quality.

The initial thought was to declare the variance as a percentage of the element. This proved unreliable for two reasons:

1.The percentage declared could not be considered appropriate for all image sizes

2.The binary nature of the images means that a percentage can result in a zero effective variance

The next assumption made is that the larger the image, the higher the image quality. This was implemented by allowing a one pixel tolerence on all elements. This quickly became an untenable solution when dealing with realistic images.

Another option tested was a variance multiplier of 1. This resulted in an allowable value for a narrow element of 0 to 2 times the defined width, and an allowed value for a wide element of 0 to 2 times the the defined width. This option provided the best results for barcode recognition in an image. This result came about due to the fact that the element width is first compared to the narrow element variables. Almost all images were read successfully using this algorithm.

The next option put forward was to calculate the difference between the width of a narrow element and the width of a wide element, divide it by 2 and simply add and subtract this from the defined width of a wide and narrow to create the tolerance. This creates a clear threshold between what is considered a narrow element and what is considered to be wide element.

The final choice made was to use a cutoff point between a narrow element and a wide element which was equal to 80% of the width of a wide element. This has proven to be the most effective and has the highest read rate when used against all sample images. Whilst this choice exceeds that allowed by the standard we have found that this is required to account for poor image quality.

Final output

Between the training algorithm and the pre-processor the application determines the following:

  • The size of the bars are within the standard
  • The first character of the barcode is a star

This then ouputs a one dimensional array ready for character matching through the use of the barcode reader algorithm.

To view the next stage of the barcode reading process click here Barcode Character Recognition

To return to main page of Team B click here Bar code reading from image

Personal tools