MATLAB Examples

Barcode Recognition

This example shows how to create an image processing system which can recognize and interpret a GTIN-13 barcode. The GTIN-13 barcode, formally known as EAN-13, is an international barcode standard. It is a superset of the widely used UPC standard.


Example Model

The following figure shows the Barcode Recognition model:

The GTIN-13 Barcode

GTIN is the acronym for Global Trade Item Number, a family of product identification numbers that encompasses the various versions of the EAN barcodes and provides a unified worldwide numbering system. The GTIN-13 (EAN/UCC-13) barcode encodes a 13-digit number.


The barcode recognition example performs a search on selected rows of the input image, called scanlines. Prior to recognition, each pixel of the scanline is preprocessed by transforming it into a feature value. The feature value of a pixel is set to a 1, if the pixel is considered black, -1 if it is considered white, and a value between -1 and 1 otherwise. Once all pixels are transformed, the scanline sequences are analyzed. The example identifies the sequence and location of the guard patterns [1] and symbols. The symbols are upsampled and compared with the codebook to determine the corresponding code.

To compensate for various barcode orientations, the example analyzes from left-to-right and from right-to-left and chooses the better match. If the checksum is correct and a matching score against the codebook is higher than a set threshold, the code is considered valid and is displayed.

You can change the number and location of the scanlines by changing the value of the "Row Positions Of Scanlines" parameter.


The scanlines that have been used to detect barcodes are displayed in red. When a GTIN-13 is correctly recognized and verified, the code is displayed at the top of the image.

The specified simulation stop time (8.4333333333333336) is not an integer
multiple of the fixed step size (0.033333208296503096). Changing the stop time
to (8.4333016990152831).
Suggested Actions:
    • You can disable this diagnostic by specifying a stop time that is an
    integer multiple of the fixed step size. - Open
    • Set 'Automatic solver parameter selection' diagnostic to 'none' in the
    Diagnostics tab of the Configuration Parameters dialog - Apply

Available Example Versions

Example using stored video data: vipbarcoderecognition.slx (platform independent)

Example using live video acquisition: viplivebarcoderecognition_win.slx (Windows® only)


[1] T. Pavlidis, J. Swartz, and Y.P. Wang, Fundamentals of bar code information theory, Computer, pp. 74-86, vol. 23, no. 4, Apr 1990.