#pragma once // #ifdef YOLO_EXPORTS #define YOLO_API __declspec(dllexport) #else #define YOLO_API __declspec(dllimport) #endif #include // struct Detection { int class_id; float score; int x; int y; int width; int height; }; extern "C" { // ======================================================================== // // ======================================================================== /** * @brief [新增] 创建一个检测器实例 (有状态) * @details 此函数加载ONNX模型并初始化Session,返回一个句柄。 * @param model_path ONNX模型的绝对路径 * @param input_width 模型输入宽度 (例如 640) * @param input_height 模型输入高度 (例如 640) * @return void* 指向检测器实例的句柄。如果失败则返回 nullptr。 */ YOLO_API void* create_detector( const wchar_t* model_path, int input_width, int input_height ); /** * @brief [新增] 释放由 create_detector 创建的检测器实例 * @param detector_handle 要释放的句柄 */ YOLO_API void free_detector(void* detector_handle); /** * @brief [新增] 使用已加载的检测器执行检测 (线程安全) * @details * @param detector_handle 由 create_detector 返回的句柄 * @param image_bytes 指向图像数据(BGR格式)的指针 * @param image_width 图像宽度 * @param image_height 图像高度 * @param out_detections [输出] Detection结构体数组指针 * @param out_detections_count [输出] 检测到的物体数量 * @param conf_threshold 置信度阈值 * @param iou_threshold NMS的IOU阈值 * @return int 0表示成功 */ YOLO_API int perform_detection_on_session( void* detector_handle, unsigned char* image_bytes, int image_width, int image_height, Detection** out_detections, int* out_detections_count, float conf_threshold, float iou_threshold ); // ======================================================================== // // ======================================================================== /** * @brief [保留] 原始的无状态检测函数 (非线程安全) */ YOLO_API int perform_detection( const wchar_t* model_path, unsigned char* image_bytes, int image_width, int image_height, Detection** out_detections, int* out_detections_count, const char** class_names, int class_names_count, float conf_threshold, // 置信度阈值 (例如 0.5f) float iou_threshold, // NMS的IOU阈值 (例如 0.5f) int input_width, // 模型输入宽度 (例如 640) int input_height // 模型输入高度 (例如 640) ); /** * @brief [保留] 释放由 perform_detection* 分配的内存 */ YOLO_API void free_memory(Detection* detections); /** * @brief [保留] 绘制函数 */ YOLO_API void draw_and_encode_image( unsigned char* image_bytes, int image_width, int image_height, const Detection* detections, int detections_count, const char** class_names, int class_names_count, unsigned char** out_image_bytes, int* out_image_size ); /** * @brief [保留] 释放由 draw_and_encode_image 分配的内存 */ YOLO_API void free_image_memory(unsigned char* image_bytes); }