44 lines
1.6 KiB
Markdown
Raw Normal View History

# 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.