40 lines
1.3 KiB
Markdown
40 lines
1.3 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/my_model/my_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, choose exactly one of `YOLO_SEG_GEOMETRY_MIN_AREA_RECT` and
|
|
`YOLO_SEG_GEOMETRY_MIN_ENCLOSING_CIRCLE`. Mask views and all other result-set
|
|
owned data remain valid until `yolo_result_set_release()`.
|