3.2 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.
掩膜膨胀(2026-10-24)
C/C++ 示例支持 --mask-dilation N,N 为 0~100 的整数,默认 0。
Seg 的每个实例独立调用公共库 yolo_mask_dilate,再合成 RGB 编号图;保留重叠。
范围限制在模型 ROI(含调用方 ROI 覆盖)或整张原图内。JSON 的掩膜范围和
maskDilationRadius 对应处理后的数据;原始检测框和拟合几何保持原值。
公共库推理接口本身仍返回原始掩膜,RGB 合成函数本身不做膨胀。
调用流程:先用 NULL 输出、stride=0、capacity=0 查询返回尺寸与原点; 由调用方分配 widthheight 字节,再调用一次得到二值掩膜。 保留结果集直到原始输入读取结束;膨胀输出由调用方持有并释放。 圆核满足 dxdx+dydy <= NN;N=0 保留原像素。输入输出不可共用缓冲区。 失败不改变输出及元数据,成功不改变行尾填充。可直接处理二值数据,无需保存图片。 RGB 最多保存三个重叠编号的限制保持不变;膨胀本身没有这个实例重叠限制。 可选膨胀耗时在推理计时之外;SDK/ARM64 交叉编译不能代替 NPU 实机验收。