Color Recognition Example
Color recognition on HUSKYLENS 2 lets you detect, count and track colored blocks via Mind+ and serial data. It’s like giving the camera color-aware eyes that report IDs, names, coordinates and sizes so you can check if a target color appears, how many blocks exist, and which one is closest to the crosshair for interactive AI projects.
1. Color Recognition block
Before You Start:
1.1 Color Recognition Outputs Data
HUSKYLENS 2 can recognize color blocks within its field of view and print related data through the serial port. The readable data include the ID of the color block closest to the center of the HUSKYLENS 2 camera, the total number of detected color blocks, and the ID of the first detected color block.
The sample program is shown below.
Click “Upload” in Mind+ and wait for the upload to complete.Use the touchscreen to enter the Color Recognition function of HUSKYLENS 2.
Align the crosshair of HUSKYLENS 2 with the color block in the image to start learning. For detailed instructions, read Color Recognition.
After the learning process is complete, open the serial port in Mind+ and observe the output results.
Result:The output includes the total number of detected color blocks. Regardless of whether a color has been learned, any framed color block will be counted. The corresponding color block ID numbers can be displayed as required. The color block nearest to the center is outlined with a white frame, representing an unlearned color, therefore its ID is 0.
1.2 Obtain Data of Specified Color
After HUSKYLENS 2 recognizes colors, it can obtain the data of specified colors in the image. For example, determine whether a learned color appears in the frame, get its name, or obtain the number of color blocks of the same color. When multiple blocks of the same color appear, you can specify one to retrieve parameters such as name, X/Y coordinates, width, and height.
The sample program is shown below:
Result: As shown in the figure, you can obtain the total number and name of color blocks with ID1, as well as the coordinates of the first detected ID1 color block. (The color name can be customized; the default name is “Color”.)
1.3 Color Recognition 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, obtains the data of a specified block. (If the block is unlearned, its ID is 0.) |
|
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, obtains the data of a specified block. |
Was this article helpful?
