Instance Segmentation Example for micro:bit-MakeCode
Instance segmentation on HuskyLens 2 with micro:bit lets you detect multiple objects, read their ID, label, position, size and counts via serial, like turning the camera into a live object spreadsheet for kids’ AI projects.
1. Instance Segmentation Project Example
Before You Start:
1.1 Instance Segmentation and Output Relevant Data
When instance segmentation is enabled, objects appearing on the HuskyLens 2 screen will be detected and their outlines marked, allowing you to access key data: total detected instances, instance categories, center-closest instance, and specified ID instance. This data includes the instance's ID, name, center coordinates (XY), width, height, and confidence level will be displayed (confidence level cannot currently be retrieved via program.
Example program:
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 objects to observe the output.
As shown, when HuskyLens 2 detects instances such as "dog" and "person", the following data will display:
How to use instance segmentation, please refer to the Instance Segmentation tutorial.
Result: The serial port will output: total detected instances, ID of the center-closest instance, ID of the first detected instance.
There are 2 detected instances, so the dot matrix display shows "2".
1.2 Obtaining Instance Segmentation Feature Data
The system can capture detailed instance segmentation data for any detected object. Key readable information includes: instance ID, category name, width, height, center coordinates (X/Y), and segmentation confidence levels(Confidence leverls cannot be displayed in serial output).
For instance, the sample program below retrieves instance feature data positioned near the camera's center.
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 objects, and the serial port will display the instance ID along with detailed segmentation data.
1.3 Obtaining Data of a Specific Instance
When multiple instances with the same ID appear simultaneously, the program can count their occurrences and retrieve data for the nth instance in the detected sequence.
Example program:
Result: As shown, click "Download" to transfer the program. Align HuskyLens 2 with two instances labeled ID 1. After activation, the serial port will output data statistics for these instances, including their individual positions and segmentation information.
1.4 Instance Segmentation Blocks Description
| block | Description |
|---|---|
|
Used to obtain one set of Instance Segmentation data under the Instance Segmentation function of HUSKYLENS 2. |
|
Determine if an instance is present in the current frame. |
|
Retrieves data of the instance closest to the screen cross cursor, including instance ID, category name, center X/Y coordinates, width, and height. |
|
Get the total number of instances detected on the screen. |
|
When multiple instances are detected, retrieves data for a specified instance. |
|
Determine if an instance with the specified ID exists in the frame. |
|
Gets the total number of detected instances with a specified ID on the screen. |
|
Obtain the number of instances with the specified ID in the current frame. |
|
When multiple instances are detected, retrieve the relevant data of a specified instance. |
|
When multiple instances with the same ID are detected, retrieve the relevant data of a specified instance. |
Was this article helpful?
