66 lines
3.0 KiB
Markdown
66 lines
3.0 KiB
Markdown
# C API
|
||
|
||
Include `include/yolo_runtime.h` and link with `libyolo_runtime.so.5`.
|
||
|
||
```c
|
||
yolo_error_info_v1_t error = {sizeof(error), YOLO_ERROR_INFO_VERSION};
|
||
yolo_runtime_t* runtime = NULL;
|
||
if (yolo_runtime_create("models/primary/model.yaml", &runtime, &error) != 0)
|
||
return 1;
|
||
|
||
yolo_runtime_info_v1_t info = {sizeof(info), YOLO_RUNTIME_INFO_VERSION};
|
||
yolo_runtime_get_info(runtime, &info);
|
||
|
||
yolo_image_view_v1_t image = {sizeof(image), YOLO_IMAGE_VIEW_ABI_VERSION};
|
||
image.data = rgb;
|
||
image.width = width;
|
||
image.height = height;
|
||
image.row_stride_bytes = width * 3;
|
||
image.pixel_format = YOLO_PIXEL_FORMAT_RGB888;
|
||
|
||
yolo_infer_options_v1_t options = {sizeof(options), YOLO_INFER_OPTIONS_VERSION};
|
||
options.seg_geometry_mode = info.task == YOLO_TASK_SEG
|
||
? YOLO_SEG_GEOMETRY_MIN_AREA_RECT
|
||
: YOLO_SEG_GEOMETRY_NONE;
|
||
|
||
yolo_result_set_t* results = NULL;
|
||
if (yolo_runtime_infer_image(runtime, &image, &options, &results, &error) != 0)
|
||
return 2;
|
||
|
||
uint32_t count = 0;
|
||
yolo_result_set_get_count(results, &count);
|
||
/* Read task-specific values with yolo_result_set_get_*(). */
|
||
yolo_result_set_release(results);
|
||
yolo_runtime_destroy(runtime);
|
||
```
|
||
|
||
For Seg, select MIN_AREA_RECT, MIN_ENCLOSING_CIRCLE, MEAN_DIAMETER_CIRCLE or ROBUST_FIT_CIRCLE (YOLO_SEG_GEOMETRY_ prefix). Mask views and all other result-set
|
||
owned data remain valid until `yolo_result_set_release()`.
|
||
|
||
|
||
## Direct mask and RGB examples
|
||
|
||
See `examples/cpp/main.cpp` for direct calls to all 16 public APIs and `docs/RGB_MASK.md` for the mask ownership/pixel decode walkthrough. C/C++ Seg examples always compose RGB in memory without a flag or image file.
|
||
|
||
|
||
## ROI
|
||
|
||
See [MODEL_CONFIG.md](MODEL_CONFIG.md#roi-使用说明whlt-与只传-lt) for WHLT, default 800×736 plus LT, and runnable Windows/RK3588 examples. Both ROI helpers are header-only; ABI remains 5.
|
||
|
||
|
||
## 掩膜膨胀(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 查询返回尺寸与原点;
|
||
由调用方分配 width*height 字节,再调用一次得到二值掩膜。
|
||
保留结果集直到原始输入读取结束;膨胀输出由调用方持有并释放。
|
||
圆核满足 dx*dx+dy*dy <= N*N;N=0 保留原像素。输入输出不可共用缓冲区。
|
||
失败不改变输出及元数据,成功不改变行尾填充。可直接处理二值数据,无需保存图片。
|
||
RGB 最多保存三个重叠编号的限制保持不变;膨胀本身没有这个实例重叠限制。
|
||
可选膨胀耗时在推理计时之外;SDK/ARM64 交叉编译不能代替 NPU 实机验收。
|