# Barcode Decoding using Hough Transform

In this project we want to decode many different barcodes with various angles. This mean, the direction of lines is not necessarily horizontal or vertical. Some of this barcodes show in Figure 1.

Figure. 1.

Some typical barcode images

For this purpose, the edges of this images extracted using canny edge detector as shown in Figure 2.

Figure. 2.

Canny edge detection result on a barcode

In the next step, the Hough transform is used. The result of this transform is a matrix containing, values of P and Ө. Points that have the maximum values in this matrix indicates a line. The lines that we want to extract have same Ө and different P. So, using these P values we could normalize and extract the weights of lines related to each line. For example, after normalizing, a weight equal to 3 shows 3 lines in a specific area. These weights are used for decoding.

In decoding stage we need to know about barcodes structures. The structure of a barcode is shown in Figure 3. As seen, barcodes have 3 guards, Left, Right and Middle. If black lines indicate with ‘1’ and white lines indicates with ‘0’, the left and right guards shown ‘101’ and also the middle guard codes with 5 bit, ‘01010’. By extracting weights in the past step, for each black line we insert ‘1’ equal to its weight. Also for white line we do the same. After this step, we have 95 binary digits. Binary digits that locate on positions of 1-3 and 93-95 are indicate the left and the right guards. Binary digits between 4-45 and 51-92 are grouped in classes with 7 digits that shown MANUFACTURER DIGIT. This is done helping Figure 3.

Figure. 3.

Structure of a barcode and decoding information of it.

**Technical Report:**

** S. Azizi,** N. Nazari, “Barcode Decoding using Hough Transform,” Final project of image processing course: Dr. B. Nazari, Isfahan University of Technology, 2012.