2.1 KiB
RGB mask example: start in main.cpp
Both SDKs automatically include examples/cpp/main.cpp, examples/c/main.c,
public headers, matching libraries, docs and prebuilt C/C++ examples. For Seg,
the examples ALWAYS compose RGB instance IDs in memory after inference. No
--rgb-mask switch or BMP output is required; the old switch remains accepted.
The C++ main file directly demonstrates all 16 public APIs: lifecycle, model
info, image inference, count/performance/common results, bounding/rotated boxes,
Seg geometry/binary masks, pose keypoints and RGB composition. Task-specific
getters run only for the corresponding model. write_result_json is solely an
optional file-format illustration; the main's mask flow does not depend on it.
Read the numbered steps in main.cpp: get each borrowed 0/255 mask and geometry; pass ordered mask views to yolo_masks_compose_rgb_ids; own the resulting RGB888 buffer; read a pixel at ystride+x3; remove zero and duplicate channel values to obtain the one/two/three instance IDs. IDs are result index+1 (1..255), not class IDs or cross-frame tracking IDs. RGB_PIXEL prints a real foreground pixel and decoded IDs; ID_PIXELS prints membership counts. The C main shows the same mask/RGB flow with explicit malloc/free.
Background=(0,0,0), single=(id,id,id), two=(id1,id2,id1), three=(id1,id2,id3), ascending IDs. More than three overlaps returns an error. Holes/disconnected regions stay intact. No dilation is performed by the SDK. Do your processing at the marked location before RGB storage is freed; keep the result set alive while using borrowed binary masks. RGB data requires no file saving. A retained common/rgb_mask.h is an optional utility for older integrations; the primary C/C++ examples no longer delegate mask handling to it.
Examples (use .exe on Windows):
yolo_cpp_example --config models/primary/model.yaml --image examples/assets/sample.bmp --json result.json --seg-geometry fit
Geometry modes: rect, circle, mean, fit. Seg RGB composition runs for each mode. For other task types, RGB composition is not requested.