MATLAB Examples

Barcode Recognition Using Live Video Acquisition

This example shows how to use the From Video Device block provided by Image Acquisition Toolbox™ to acquire live image data from a Point Grey Flea® 2 camera into Simulink®. The example uses the Computer Vision System Toolbox™ 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.

Image Acquisition Toolbox™ provides functions for acquiring images and video directly into MATLAB® and Simulink from PC-compatible imaging hardware. You can detect hardware automatically, configure hardware properties, preview an acquisition, and acquire images and video.

This example requires Image Acquisition Toolbox and a Point Grey Flea® 2 camera to run the model.

Watch barcode recognition on live video stream. (11 seconds)


Example Model

The following figure shows the example model using the From Video Device block.

Example Description

This example uses the same algorithm as the Barcode Recognition example. Refer to the Barcode Recognition example for detailed information.


The scan lines 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

Even though a Point Grey Flea® 2 camera was used for this example, you can update this model to use other supported image acquisition devices, for example, webcams. This enables you to use the same Simulink model with different image acquisition hardware. Before using this example, please adjust the focus of your imaging device such that the barcodes are legible.

Available Example Versions

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

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