GrabBag/AppModel/lib/Arm/include/yolo_runtime.h

132 lines
5.9 KiB
C

#pragma once
#include "yolo_runtime_types.h"
#if defined(_WIN32)
#define YOLO_RUNTIME_API
#elif defined(__GNUC__) || defined(__clang__)
#define YOLO_RUNTIME_API __attribute__((visibility("default")))
#else
#define YOLO_RUNTIME_API
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct yolo_runtime yolo_runtime_t;
typedef struct yolo_result_set yolo_result_set_t;
/* Independently dilate one binary (0/255) mask with the exact integer disk
dx*dx+dy*dy <= radius*radius, radius 0..100 (0 copies original pixels).
region is REQUIRED: full-image bounds or the processing ROI in original
coordinates. Input must be entirely inside it; output is expanded then clipped
to it. No geometry/result-set mutation or inter-instance overlap suppression.
Initialize result's struct_size/version as YOLO_MASK_VIEW_VERSION.
Query: output=NULL, stride=capacity=0 returns OK and result dimensions/origin,
packed stride and NULL data; allocate result.width*result.height bytes, then
call again. Caller owns output, independent of result-set lifetime.
Output padding is untouched. On failure output and result remain unchanged.
Input/output buffers must not overlap. ABI 5 existing layouts stay unchanged. */
YOLO_RUNTIME_API yolo_status_t yolo_mask_dilate(
const yolo_mask_view_v1_t* mask, int32_t radius,
const yolo_roi_v1_t* region, unsigned char* output,
int32_t row_stride_bytes, uint64_t output_capacity_bytes,
yolo_mask_view_v1_t* result, yolo_error_info_v1_t* error);
/* Compose mask_count binary (0/255) masks into an RGB888 canvas, without dilation.
IDs are input index + 1 (1..255); origins locate masks on the canvas.
Background=(0,0,0), single=(id,id,id), two=(id1,id2,id1),
three=(id1,id2,id3), where id1 < id2 < id3. Remove zero/duplicate
channels to decode membership. Holes and disconnected regions are preserved.
Zero masks (masks may be NULL) produces a black canvas.
Caller owns output; capacity must cover (height-1)*stride + width*3 bytes.
Padding and the entire output on failure remain unchanged. Output must not
overlap mask data. More than 255 masks or >3 memberships at any pixel returns
UNSUPPORTED; malformed binary data/bounds return INVALID_ARGUMENT.
This additive API does not change the existing ABI 5 structures/interfaces. */
YOLO_RUNTIME_API yolo_status_t yolo_masks_compose_rgb_ids(
const yolo_mask_view_v1_t* masks, uint32_t mask_count,
int32_t width, int32_t height, unsigned char* output,
int32_t row_stride_bytes, uint64_t output_capacity_bytes,
yolo_error_info_v1_t* error);
YOLO_RUNTIME_API uint32_t yolo_runtime_get_abi_version(void);
YOLO_RUNTIME_API yolo_status_t yolo_runtime_create(
const char* config_path,
yolo_runtime_t** runtime,
yolo_error_info_v1_t* error);
YOLO_RUNTIME_API yolo_status_t yolo_runtime_get_info(
const yolo_runtime_t* runtime,
yolo_runtime_info_v1_t* info);
YOLO_RUNTIME_API yolo_status_t yolo_runtime_infer_image(
yolo_runtime_t* runtime,
const yolo_image_view_v1_t* image,
const yolo_infer_options_v1_t* options,
yolo_result_set_t** results,
yolo_error_info_v1_t* error);
/* Supply the full image and a final ROI [x,x+width), [y,y+height).
WHLT callers construct it with yolo_roi_from_whlt(W, H, L, T):
width=W, height=H, x=L, y=T. Do not initialize ABI fields in WHLT order.
yolo_roi_default() supplies W=800,H=736,L=0,T=0; caller values may override.
Defaults are explicit initialization only; no inference-time replacement.
NULL ROI is exactly infer_image. Invalid/empty/out-of-bounds ROIs fail;
they are never clipped or replaced by full-image inference.
All positional results (bbox, OBB, SEG geometry, mask origins, keypoints)
are returned in FULL IMAGE coordinates. Mask pixels stay locally stored
and borrowed until result_set_release, as in the existing API.
Input is borrowed only for this synchronous call. Packed formats retain
their row stride; NV12/NV21 ROIs, including odd bounds, are converted to RGB.
No TXT parsing, GUI, or model reload is required. Classification scores
describe the cropped input and have no positional mapping.
Existing ABI 5 structures and infer_image semantics remain unchanged. */
YOLO_RUNTIME_API yolo_status_t yolo_runtime_infer_image_roi(
yolo_runtime_t* runtime,
const yolo_image_view_v1_t* full_image,
const yolo_roi_v1_t* roi,
const yolo_infer_options_v1_t* options,
yolo_result_set_t** results,
yolo_error_info_v1_t* error);
YOLO_RUNTIME_API yolo_status_t yolo_result_set_get_count(
const yolo_result_set_t* results,
uint32_t* count);
YOLO_RUNTIME_API yolo_status_t yolo_result_set_get_performance(
const yolo_result_set_t* results,
yolo_performance_v1_t* performance);
YOLO_RUNTIME_API yolo_status_t yolo_result_set_get_common(
const yolo_result_set_t* results,
uint32_t index,
yolo_result_common_v1_t* result);
YOLO_RUNTIME_API yolo_status_t yolo_result_set_get_bbox(
const yolo_result_set_t* results,
uint32_t index,
yolo_bbox_v1_t* bbox);
YOLO_RUNTIME_API yolo_status_t yolo_result_set_get_obb(
const yolo_result_set_t* results,
uint32_t index,
yolo_rotated_rect_v1_t* obb);
YOLO_RUNTIME_API yolo_status_t yolo_result_set_get_seg_mask(
const yolo_result_set_t* results,
uint32_t index,
yolo_mask_view_v1_t* mask);
YOLO_RUNTIME_API yolo_status_t yolo_result_set_get_seg_geometry(
const yolo_result_set_t* results,
uint32_t index,
yolo_seg_geometry_v1_t* geometry);
YOLO_RUNTIME_API yolo_status_t yolo_result_set_get_pose_keypoint_count(
const yolo_result_set_t* results,
uint32_t index,
uint32_t* count);
YOLO_RUNTIME_API yolo_status_t yolo_result_set_copy_pose_keypoints(
const yolo_result_set_t* results,
uint32_t index,
yolo_keypoint_v1_t* keypoints,
uint32_t capacity,
uint32_t* count);
YOLO_RUNTIME_API void yolo_result_set_release(yolo_result_set_t* results);
YOLO_RUNTIME_API void yolo_runtime_destroy(yolo_runtime_t* runtime);
#ifdef __cplusplus
}
#endif