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.
Ensure that you install OpenCV version 4.5.2 from the Hardware Setup window.
For more information on how to use the Simulink Support Package for Android Devices to run a Simulink model on your Android device, see Getting Started with Android Devices.
For more information on how to get started with computer vision applications on your Android device, see Get Started with Computer Vision Applications Using Android Device.
Android device such as a phone or tablet
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
This example uses a preconfigured Simulink model from the Simulink Support Package for Android Devices.
To open the Simulink model, run this command in the MATLAB® Command Window.
Live Video Input
The 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
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 block to open the Block Parameters dialog box. Click Refresh. Set Resolution to
Back - 320X240.
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.
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.
Get Started with Computer Vision Applications Using Android Device
Implement Histogram Equalization and Median Filtering on Images Using Android Device
Detect and Match Local Features Between Image Frames Using Android Device