Color Recognition Example
HUSKYLENS 2 color recognition tracks learned or raw color blocks, like a smart camera counting and locating colored stickers on a board, and returns IDs, names, coordinates, size, totals, and per‑ID statistics for any specified block in view.
1. Color Recognition Example
Before You Start:
1.1 Recognizing Colors and Outputting Related Data
HUSKYLENS 2 can recognize and frame color blocks within its field of view and output related color block data. The readable data include: the total number of detected color blocks, the total number of learned color blocks, as well as the ID, name, center point coordinates, width, and height of the N-th detected color block and the color block closest to the center of the HUSKYLENS 2 camera view.
The example program is shown below.
Upload the program and wait for the upload to complete.
Use the crosshair on HUSKYLENS 2 to align with the color block for learning. For detailed instructions on how to learn colors, please refer to the Color Recognition.
After learning is completed, point the Camera of HUSKYLENS 2 at the color block and observe the output results.
Running Result: The total number of detected color blocks can be output. Regardless of whether the color block has been learned, as long as it is framed, it will be counted. The corresponding color block ID and other data can be output as required.
1.2 Obtaining Related Data of a Specified Color
After HUSKYLENS 2 recognizes colors, it can obtain related data of a specified color in the frame. For example, you can determine whether a color block with a specified ID is present in the frame, read the total number of detected color blocks with that ID, and obtain their name. When multiple color blocks with the same ID appear, you can specify and retrieve the related parameters of the N-th color block with the specified ID, including its name, X/Y coordinates, width, and height.
The example program is shown below:
Running Result: As shown in the figure, the total number of color blocks with ID 1 in the frame, the name of the color block with ID 1, and the coordinate position of the first detected color block with ID 1 can be obtained. (The color name can be customized and is "Color" by default.)
1.3 Color Recognition Blocks Description
| block | Description |
|---|---|
|
Used to obtain one set of color recognition data in the Color Recognition function of HUSKYLENS 2. |
|
Determines whether recognizable color blocks exist in the current frame. |
|
Obtains data for the color block closest to the crosshair on the screen, including ID, name, center X/Y coordinates, width, and height. |
|
Gets the total number of detected color blocks in the screen. |
|
When multiple color blocks are detected, obtaining the data of a specified block. (If the block is unlearned, its ID is 0.) |
|
get the number of colors that have been learned by HuskyLens 2, regardless of whether they appear in the current frame. |
|
Determines whether a color with a specified ID exists in the image. (After HUSKYLENS 2 learns colors, IDs are assigned sequentially.) |
|
Obtains the number of color blocks for a learned color in the current frame.. |
|
Obtains the data of a learned color. |
|
When multiple color blocks of the same color appear,they obtain the data of a specified block. |
Was this article helpful?
