Main Content

Detect and Display Live Barcode Using Android Device

This example shows how to use the Simulink® Support Package for Android® Devices to detect and display live barcode data using an Android device. The example uses the Computer Vision Toolbox™ to create an image processing system which can recognize and interpret a GTIN-13 and universal product code (UPC) barcode. The GTIN-13 barcode, formally known as EAN-13, is an international barcode standard. It is a superset of the widely used universal product code UPC standard.


Required Hardware

  • Android device such as a phone or tablet

  • USB cable

Hardware Setup

Connect your Android device to the host computer using the USB cable. Set up your Android device using the Hardware Setup. For more information, see Hardware Setup.

Configure Simulink Model and Calibrate Parameters

Open the androidVisionBarcodeRecognition Simulink model.

Live Video Input

The Camera block acquires the RGB frames. The transpose of these RGB frame signals is then concatenated using the Vector Concatenate block at every simulation time step.


The algorithm performs a search on some selected rows of the input image called scan lines. The scan lines are analyzed per pixel and marked by feature. Once all pixels are marked with a feature value, the sequence of patterns are analyzed. The example identifies the guard patterns and symbols by sequence and location. The symbols are up-sampled and compared with the codebook to determine a 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 check sum is correct and a matching score against the codebook is higher than a set threshold, the code is considered valid and is displayed on the Android device.

You can change the number and location of the scan lines by changing the value of the Row Positions of ScanLines parameter.

Deploy Simulink Model on Android Device

  1. Ensure to keep your Android device, that has been configured using the Hardware Setup, connected to your host computer. In the Simulink model, double-click the Camera block to open the Block Parameters dialog box. Click Refresh. Set Resolution to Back - 320X240.

  2. On the Hardware tab of the Simulink model, in the Mode section, click Run on board. In the Deploy section, click Build, Deploy & Start. The androidVisionBarcodeRecognition application launches automatically on your Android device.

  3. Hold your Android device directly above the barcode that you want to scan. Observe that the scan lines used to detect barcodes are displayed in red. When a GTIN-13 is correctly recognized and verified, the code is displayed on the application.

Other Things to Try

Implement an algorithm to detect and display quick response (QR) codes.

See Also