Barcode Recognition Example

Barcode recognition on HuskyLens 2 lets micro:bit read, count and locate barcodes on screen, like giving your robot eyes for labels, exposing ID, text, position, size and confidence for each detected or learned code.

1. Barcode Recognition Project Example

Before You Start:

1.1 Barcode Recognition and Output Relevant Data

When barcode recognition is enabled, barcodes appearing on the HuskyLens 2 screen will be detected and decoded, allowing you to access key data: total detected barcodes, total trained barcodes, center-closest barcode, nth detected barcode, and specified ID barcode. This data includes the barcode's ID, content, center coordinates (XY), width, and height.

Example program:

Interface Diagram

Connect to micro:bit and click Download to transfer the program. After successful download, click Show Data to activate data output mode. Align the HuskyLens 2 camera with a barcode to observe the output.

As shown, when HuskyLens 2 detects three barcodes such as "1434" ,“hello”and "23", the following data will display:

How to learn barcodes, please refer to the Barcode Recognition.
Result: The serial port will output: total detected barcodes, ID of the center-closest barcode, content of the first detected barcode, and total the learned barcodes.

Interface Diagram

There are 3 detected barcodes, so the dot matrix display shows "3".

Interface Diagram

1.2 Obtaining Barcode Recognition Feature Data

The system can capture detailed barcode recognition data for any detected barcode. Key readable information includes: barcode ID, content, width, height, center coordinates (X/Y), and decoding confidence levels.

For instance, the sample program below retrieves barcode feature data positioned near the camera's center; this functionality works even for barcodes not previously learned.

Interface Diagram

Operation Result: As shown, click "Download" to transfer the program to micro:bit. After successful download, click "Show Device" to activate data output. Align HuskyLens 2 with a barcode, and the serial port will display the barcode ID along with its decoded content, positional and dimensions.

Interface Diagram

1.3 Obtaining Data of a Specific Barcode

When multiple barcodes with the same ID appear simultaneously, the program can count their occurrences and retrieve data for the nth barcode in the detected sequence.

Example program:

Interface Diagram

Result: As shown, click "Download" to transfer the program. Align HuskyLens 2 with two barcodes labeled ID 1. After activation, the serial port will output data statistics for these two barcodes, including their individual positions, dimensions, and decoded content.

Interface Diagram

1.4 Barcode Recognition Blocks Description

block Description
Used to obtain one set of Barcode Recognition data under the Barcode Recognition function of HUSKYLENS 2.
Determine if a barcode is present in the current frame.
Retrieves data of the barcode closest to the screen cross cursor, including barcode ID, decoded content, center X/Y coordinates, width, and height.
Get the total number of barcodes detected on the screen, including both unregistered and registered barcodes.
When multiple barcodes are detected, retrieves data for a specified barcode.
Get the total number of learned barcodes, regardless of whether they appear in the current frame.
Determine if a barcode with the specified ID exists in the frame. Unlearned IDs are uniformly set to 0, and learned IDs are sorted in learning order.
Gets the total number of detected barcodes with a specified ID on the screen.
When multiple barcodes are detected, retrieve the relevant data of a specified barcode.
When multiple barcodes with the same ID are detected, retrieve the relevant data of a specified barcode.

Was this article helpful?

TOP