diff --git a/c_api/fastdeploy_capi/fd_type.h b/c_api/fastdeploy_capi/fd_type.h index 4a3d8cadd..a7860e982 100644 --- a/c_api/fastdeploy_capi/fd_type.h +++ b/c_api/fastdeploy_capi/fd_type.h @@ -67,6 +67,11 @@ typedef struct FD_C_TwoDimArrayFloat { typedef void* FD_C_Mat; +typedef struct FD_C_OneDimMat { + size_t size; + FD_C_Mat* data; +} FD_C_OneDimMat; + #ifdef __cplusplus extern "C" { #endif diff --git a/c_api/fastdeploy_capi/types_internal.cc b/c_api/fastdeploy_capi/types_internal.cc index 807f5dd21..988b39af1 100644 --- a/c_api/fastdeploy_capi/types_internal.cc +++ b/c_api/fastdeploy_capi/types_internal.cc @@ -18,38 +18,108 @@ namespace fastdeploy { #ifdef ENABLE_VISION -std::unique_ptr& -FD_C_CheckAndConvertPaddleClasModelWrapper( - FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper) { - FDASSERT( - fd_c_paddleclas_model_wrapper != nullptr, - "The pointer of fd_c_paddleclas_model_wrapper shouldn't be nullptr."); - return fd_c_paddleclas_model_wrapper->paddleclas_model; -} +// results: -std::unique_ptr& -FD_C_CheckAndConvertPPYOLOEWrapper(FD_C_PPYOLOEWrapper* fd_c_ppyoloe_wrapper) { - FDASSERT(fd_c_ppyoloe_wrapper != nullptr, - "The pointer of fd_c_ppyoloe_wrapper shouldn't be nullptr."); - return fd_c_ppyoloe_wrapper->ppyoloe_model; -} +// ClassifyResult +DECL_AND_IMPLEMENT_RESULT_FUNC_FOR_GET_PTR_FROM_WRAPPER( + ClassifyResult, fd_classify_result_wrapper, classify_result) +// DetectionResult +DECL_AND_IMPLEMENT_RESULT_FUNC_FOR_GET_PTR_FROM_WRAPPER( + DetectionResult, fd_detection_result_wrapper, detection_result) -std::unique_ptr& -FD_C_CheckAndConvertClassifyResultWrapper( - FD_C_ClassifyResultWrapper* fd_c_classify_result_wrapper) { - FDASSERT(fd_c_classify_result_wrapper != nullptr, - "The pointer of fd_c_classify_result_wrapper shouldn't be nullptr."); - return fd_c_classify_result_wrapper->classify_result; -} +// Models: + +// Classification + +// PaddleClasModel +DECL_AND_IMPLEMENT_CLASSIFICATION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PaddleClasModel, fd_paddleclas_model_wrapper, paddleclas_model) + +// detection models: + +// PPYOLOE + +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PPYOLOE, fd_ppyoloe_wrapper, ppyoloe_model) + +// PicoDet +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PicoDet, fd_picodet_wrapper, picodet_model) + +// PPYOLO +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PPYOLO, fd_ppyolo_wrapper, ppyolo_model) + +// YOLOv3 +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + YOLOv3, fd_yolov3_wrapper, yolov3_model) + +// PaddleYOLOX +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PaddleYOLOX, fd_paddleyolox_wrapper, paddleyolox_model) + +// FasterRCNN +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + FasterRCNN, fd_fasterrcnn_wrapper, fasterrcnn_model) + +// MaskRCNN +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + MaskRCNN, fd_maskrcnn_wrapper, maskrcnn_model) + +// SSD +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(SSD, + fd_ssd_wrapper, + ssd_model) + +// PaddleYOLOv5 +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PaddleYOLOv5, fd_paddleyolov5_wrapper, paddleyolov5_model) + +// PaddleYOLOv6 +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PaddleYOLOv6, fd_paddleyolov6_wrapper, paddleyolov6_model) + +// PaddleYOLOv7 +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PaddleYOLOv7, fd_paddleyolov7_wrapper, paddleyolov7_model) + +// PaddleYOLOv8 +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PaddleYOLOv8, fd_paddleyolov8_wrapper, paddleyolov8_model) + +// RTMDet +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + RTMDet, fd_rtmdet_wrapper, rtmdet_model) + +// CascadeRCNN +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + CascadeRCNN, fd_cascadercnn_wrapper, cascadercnn_model) + +// PSSDet +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PSSDet, fd_pssdet_wrapper, pssdet_model) + +// RetinaNet +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + RetinaNet, fd_retinanet_wrapper, retinanet_model) + +// FCOS +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + FCOS, fd_fcos_wrapper, fcos_model) + +// TTFNet +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + TTFNet, fd_ttfnet_wrapper, ttfnet_model) + +// TOOD +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + TOOD, fd_tood_wrapper, tood_model) + +// GFL +DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(GFL, + fd_gfl_wrapper, + gfl_model) -std::unique_ptr& -FD_C_CheckAndConvertDetectionResultWrapper( - FD_C_DetectionResultWrapper* fd_c_detection_result_wrapper) { - FDASSERT( - fd_c_detection_result_wrapper != nullptr, - "The pointer of fd_c_detection_result_wrapper shouldn't be nullptr."); - return fd_c_detection_result_wrapper->detection_result; -} #endif std::unique_ptr& diff --git a/c_api/fastdeploy_capi/types_internal.h b/c_api/fastdeploy_capi/types_internal.h index f8a2cfbe9..c3238de51 100644 --- a/c_api/fastdeploy_capi/types_internal.h +++ b/c_api/fastdeploy_capi/types_internal.h @@ -23,39 +23,246 @@ #include "fastdeploy/vision/common/result.h" #include "fastdeploy/vision/detection/ppdet/model.h" -typedef struct FD_C_ClassifyResultWrapper { - std::unique_ptr classify_result; -} FD_C_ClassifyResultWrapper; +#define DEFINE_RESULT_WRAPPER_STRUCT(typename, varname) typedef struct FD_C_##typename##Wrapper { \ + std::unique_ptr varname; \ +} FD_C_##typename##Wrapper -typedef struct FD_C_DetectionResultWrapper { - std::unique_ptr detection_result; -} FD_C_DetectionResultWrapper; +#define DEFINE_CLASSIFICATION_MODEL_WRAPPER_STRUCT(typename, varname) typedef struct FD_C_##typename##Wrapper { \ + std::unique_ptr \ + varname; \ +} FD_C_##typename##Wrapper -typedef struct FD_C_PaddleClasModelWrapper { - std::unique_ptr - paddleclas_model; -} FD_C_PaddleClasModelWrapper; +#define DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(typename, varname) typedef struct FD_C_##typename##Wrapper { \ + std::unique_ptr varname; \ +} FD_C_##typename##Wrapper -typedef struct FD_C_PPYOLOEWrapper { - std::unique_ptr ppyoloe_model; -} FD_C_PPYOLOEWrapper; +// ------------- belows are wrapper struct define --------------------- // + +// Results: + +// ClassifyResult +DEFINE_RESULT_WRAPPER_STRUCT(ClassifyResult, classify_result); + +// DetectionResult +DEFINE_RESULT_WRAPPER_STRUCT(DetectionResult, detection_result); + + +// Models: + +// Classification + +// PaddleClasModel + +DEFINE_CLASSIFICATION_MODEL_WRAPPER_STRUCT(PaddleClasModel, paddleclas_model); + +// Detection + +// PPYOLOE +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(PPYOLOE, ppyoloe_model); + + +// PicoDet +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(PicoDet, picodet_model); + +// PPYOLO +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(PPYOLO, ppyolo_model); + +// YOLOv3 +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(YOLOv3, yolov3_model); + +// PaddleYOLOX +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(PaddleYOLOX, paddleyolox_model); + +// FasterRCNN +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(FasterRCNN, fasterrcnn_model); + +// MaskRCNN +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(MaskRCNN, maskrcnn_model); + +// SSD +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(SSD, ssd_model); + +// PaddleYOLOv5 +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(PaddleYOLOv5, paddleyolov5_model); + +// PaddleYOLOv6 +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(PaddleYOLOv6, paddleyolov6_model); + +// PaddleYOLOv7 +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(PaddleYOLOv7, paddleyolov7_model); + +// PaddleYOLOv8 +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(PaddleYOLOv8, paddleyolov8_model); + +// RTMDet +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(RTMDet, rtmdet_model); + +// CascadeRCNN +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(CascadeRCNN, cascadercnn_model); + +// PSSDet +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(PSSDet, pssdet_model); + +// RetinaNet +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(RetinaNet, retinanet_model); + + +// FCOS +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(FCOS, fcos_model); + +// TTFNet +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(TTFNet, ttfnet_model); + +// TOOD +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(TOOD, tood_model); + +// GFL +DEFINE_DETECTION_MODEL_WRAPPER_STRUCT(GFL, gfl_model); + + +// ------------- belows are function declaration for get ptr from wrapper --------------------- // + +#define DECLARE_RESULT_FUNC_FOR_GET_PTR_FROM_WRAPPER(typename, varname) std::unique_ptr& \ +FD_C_CheckAndConvert##typename##Wrapper( \ + FD_C_##typename##Wrapper* varname) + +#define DECLARE_CLASSIFICATION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(typename, varname) std::unique_ptr& \ +FD_C_CheckAndConvert##typename##Wrapper( \ + FD_C_##typename##Wrapper* varname) + +#define DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(typename, varname) std::unique_ptr& \ +FD_C_CheckAndConvert##typename##Wrapper( \ + FD_C_##typename##Wrapper* varname) namespace fastdeploy { -std::unique_ptr& -FD_C_CheckAndConvertClassifyResultWrapper( - FD_C_ClassifyResultWrapper* fd_classify_result_wrapper); -std::unique_ptr& -FD_C_CheckAndConvertDetectionResultWrapper( - FD_C_DetectionResultWrapper* fd_detection_result_wrapper); -std::unique_ptr& -FD_C_CheckAndConvertPaddleClasModelWrapper( - FD_C_PaddleClasModelWrapper* fd_paddleclas_model_wrapper); -std::unique_ptr& -FD_C_CheckAndConvertPPYOLOEWrapper(FD_C_PPYOLOEWrapper* fd_ppyoloe_wrapper); + +// results: + +// ClassifyResult +DECLARE_RESULT_FUNC_FOR_GET_PTR_FROM_WRAPPER(ClassifyResult, + fd_classify_result_wrapper); +// DetectionResult +DECLARE_RESULT_FUNC_FOR_GET_PTR_FROM_WRAPPER(DetectionResult, + fd_detection_result_wrapper); + +// Models: + +// Classification + +// PaddleClasModel + +DECLARE_CLASSIFICATION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER( + PaddleClasModel, fd_paddleclas_model_wrapper); + + +// detection models: + +// PPYOLOE + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(PPYOLOE, + fd_ppyoloe_wrapper); + +// PicoDet + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(PicoDet, + fd_picodet_wrapper); + +// PPYOLO + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(PPYOLO, + fd_ppyolo_wrapper); + +// YOLOv3 + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(YOLOv3, + fd_yolov3_wrapper); + +// PaddleYOLOX + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(PaddleYOLOX, + fd_paddleyolox_wrapper); + +// FasterRCNN + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(FasterRCNN, + fd_fasterrcnn_wrapper); + +// MaskRCNN + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(MaskRCNN, + fd_maskrcnn_wrapper); + +// SSD + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(SSD, + fd_ssd_wrapper); + +// PaddleYOLOv5 + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(PaddleYOLOv5, + fd_paddleyolov5_wrapper); + +// PaddleYOLOv6 + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(PaddleYOLOv6, + fd_paddleyolov6_wrapper); + +// PaddleYOLOv7 + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(PaddleYOLOv7, + fd_paddleyolov7_wrapper); + +// PaddleYOLOv8 + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(PaddleYOLOv8, + fd_paddleyolov8_wrapper); + +// RTMDet + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(RTMDet, + fd_rtmdet_wrapper); + +// CascadeRCNN + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(CascadeRCNN, + fd_cascadercnn_wrapper); + +// PSSDet + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(PSSDet, + fd_pssdet_wrapper); + +// RetinaNet + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(RetinaNet, + fd_retinanet_wrapper); + +// FCOS + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(FCOS, + fd_fcos_wrapper); + +// TTFNet + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(TTFNet, + fd_ttfnet_wrapper); + +// TOOD + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(TOOD, + fd_tood_wrapper); + +// GFL + +DECLARE_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(GFL, + fd_gfl_wrapper); + } // namespace fastdeploy #endif + + typedef struct FD_C_RuntimeOptionWrapper { std::unique_ptr runtime_option; } FD_C_RuntimeOptionWrapper; @@ -68,3 +275,27 @@ FD_C_CheckAndConvertRuntimeOptionWrapper( #define CHECK_AND_CONVERT_FD_TYPE(TYPENAME, variable_name) \ fastdeploy::FD_C_CheckAndConvert##TYPENAME(variable_name) + +#define DECL_AND_IMPLEMENT_RESULT_FUNC_FOR_GET_PTR_FROM_WRAPPER(typename, var_wrapper_name, var_ptr_name) std::unique_ptr& \ +FD_C_CheckAndConvert##typename##Wrapper( \ + FD_C_##typename##Wrapper* var_wrapper_name) { \ + FDASSERT(var_wrapper_name != nullptr, \ + "The pointer of " #var_wrapper_name " shouldn't be nullptr."); \ + return var_wrapper_name->var_ptr_name; \ +} + +#define DECL_AND_IMPLEMENT_CLASSIFICATION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(typename, var_wrapper_name, var_ptr_name) std::unique_ptr& \ +FD_C_CheckAndConvert##typename##Wrapper( \ + FD_C_##typename##Wrapper* var_wrapper_name) { \ + FDASSERT(var_wrapper_name != nullptr, \ + "The pointer of " #var_wrapper_name " shouldn't be nullptr."); \ + return var_wrapper_name->var_ptr_name; \ +} + +#define DECL_AND_IMPLEMENT_DETECTION_MODEL_FUNC_FOR_GET_PTR_FROM_WRAPPER(typename, var_wrapper_name, var_ptr_name) std::unique_ptr& \ +FD_C_CheckAndConvert##typename##Wrapper( \ + FD_C_##typename##Wrapper* var_wrapper_name) { \ + FDASSERT(var_wrapper_name != nullptr, \ + "The pointer of " #var_wrapper_name " shouldn't be nullptr."); \ + return var_wrapper_name->var_ptr_name; \ +} diff --git a/c_api/fastdeploy_capi/vision/classification/ppcls/model.cc b/c_api/fastdeploy_capi/vision/classification/ppcls/model.cc index ad0028612..f88f59471 100644 --- a/c_api/fastdeploy_capi/vision/classification/ppcls/model.cc +++ b/c_api/fastdeploy_capi/vision/classification/ppcls/model.cc @@ -38,21 +38,82 @@ FD_C_PaddleClasModelWrapper* FD_C_CreatePaddleClasModelWrapper( } void FD_C_DestroyPaddleClasModelWrapper( - __fd_take FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper) { + FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper) { delete fd_c_paddleclas_model_wrapper; } FD_C_Bool FD_C_PaddleClasModelWrapperPredict( - __fd_take FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper, - FD_C_Mat img, FD_C_ClassifyResultWrapper* fd_c_classify_result_wrapper) { + FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper, FD_C_Mat img, + FD_C_ClassifyResult* fd_c_classify_result) { cv::Mat* im = reinterpret_cast(img); auto& paddleclas_model = CHECK_AND_CONVERT_FD_TYPE( PaddleClasModelWrapper, fd_c_paddleclas_model_wrapper); + FD_C_ClassifyResultWrapper* fd_c_classify_result_wrapper = + FD_C_CreateClassifyResultWrapper(); auto& classify_result = CHECK_AND_CONVERT_FD_TYPE( ClassifyResultWrapper, fd_c_classify_result_wrapper); - return paddleclas_model->Predict(im, classify_result.get()); + + bool successful = paddleclas_model->Predict(im, classify_result.get()); + if (successful) { + FD_C_ClassifyResult* res = + FD_C_ClassifyResultWrapperGetData(fd_c_classify_result_wrapper); + *fd_c_classify_result = *res; + } + return successful; +} + +FD_C_Bool FD_C_PaddleClasModelWrapperInitialized( + FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper) { + auto& paddleclas_model = CHECK_AND_CONVERT_FD_TYPE( + PaddleClasModelWrapper, fd_c_paddleclas_model_wrapper); + return paddleclas_model->Initialized(); +} + +FD_C_ClassifyResult* FD_C_ClassifyResultToC( + fastdeploy::vision::ClassifyResult* classify_result) { + // Internal use, transfer fastdeploy::vision::ClassifyResult to + // FD_C_ClassifyResult + FD_C_ClassifyResult* fd_c_classify_result_data = new FD_C_ClassifyResult(); + // copy label_ids + fd_c_classify_result_data->label_ids.size = classify_result->label_ids.size(); + fd_c_classify_result_data->label_ids.data = + new int32_t[fd_c_classify_result_data->label_ids.size]; + memcpy(fd_c_classify_result_data->label_ids.data, + classify_result->label_ids.data(), + sizeof(int32_t) * fd_c_classify_result_data->label_ids.size); + // copy scores + fd_c_classify_result_data->scores.size = classify_result->scores.size(); + fd_c_classify_result_data->scores.data = + new float[fd_c_classify_result_data->scores.size]; + memcpy(fd_c_classify_result_data->scores.data, classify_result->scores.data(), + sizeof(float) * fd_c_classify_result_data->scores.size); + fd_c_classify_result_data->type = + static_cast(classify_result->type); + return fd_c_classify_result_data; +} + +FD_C_Bool FD_C_PaddleClasModelWrapperBatchPredict( + FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper, + FD_C_OneDimMat imgs, FD_C_OneDimClassifyResult* results) { + std::vector imgs_vec; + std::vector results_out; + for (int i = 0; i < imgs.size; i++) { + imgs_vec.push_back(*(reinterpret_cast(imgs.data[i]))); + } + auto& paddleclas_model = CHECK_AND_CONVERT_FD_TYPE( + PaddleClasModelWrapper, fd_c_paddleclas_model_wrapper); + bool successful = paddleclas_model->BatchPredict(imgs_vec, &results_out); + if (successful) { + // copy results back to FD_C_OneDimClassifyResult + results->size = results_out.size(); + results->data = new FD_C_ClassifyResult[results->size]; + for (int i = 0; i < results_out.size(); i++) { + results->data[i] = *FD_C_ClassifyResultToC(&results_out[i]); + } + } + return successful; } #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/c_api/fastdeploy_capi/vision/classification/ppcls/model.h b/c_api/fastdeploy_capi/vision/classification/ppcls/model.h index db117e605..c523e76ac 100644 --- a/c_api/fastdeploy_capi/vision/classification/ppcls/model.h +++ b/c_api/fastdeploy_capi/vision/classification/ppcls/model.h @@ -54,12 +54,36 @@ FASTDEPLOY_CAPI_EXPORT extern void FD_C_DestroyPaddleClasModelWrapper( * * \param[in] fd_c_paddleclas_model_wrapper pointer to FD_C_PaddleClasModelWrapper object * \param[in] img pointer to cv::Mat image - * \param[in] fd_c_classify_result_wrapper pointer to FD_C_PaddleClasModelWrapper object, which stores the result. + * \param[in] fd_c_classify_result pointer to FD_C_ClassifyResult object, which stores the result. */ FASTDEPLOY_CAPI_EXPORT extern FD_C_Bool FD_C_PaddleClasModelWrapperPredict( - __fd_take FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper, - FD_C_Mat img, FD_C_ClassifyResultWrapper* fd_c_classify_result_wrapper); + __fd_keep FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper, + FD_C_Mat img, FD_C_ClassifyResult* fd_c_classify_result_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_paddleclas_model_wrapper pointer to FD_C_PaddleClasModelWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +FASTDEPLOY_CAPI_EXPORT extern FD_C_Bool FD_C_PaddleClasModelWrapperInitialized( + __fd_keep FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper); + + +/** \brief Predict the classification results for a batch of input images + * + * \param[in] fd_c_paddleclas_model_wrapper pointer to FD_C_PaddleClasModelWrapper object + * \param[in] imgs The input image list, each element comes from cv::imread() + * \param[in] results The output classification result list + * \return true if the prediction successed, otherwise false + */ +FASTDEPLOY_CAPI_EXPORT extern FD_C_Bool FD_C_PaddleClasModelWrapperBatchPredict( + __fd_keep FD_C_PaddleClasModelWrapper* fd_c_paddleclas_model_wrapper, + FD_C_OneDimMat imgs, + FD_C_OneDimClassifyResult* results); + #ifdef __cplusplus } // extern "C" diff --git a/c_api/fastdeploy_capi/vision/detection/ppdet/base_define.h b/c_api/fastdeploy_capi/vision/detection/ppdet/base_define.h new file mode 100644 index 000000000..13a647f3d --- /dev/null +++ b/c_api/fastdeploy_capi/vision/detection/ppdet/base_define.h @@ -0,0 +1,119 @@ +// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#define DECLARE_CREATE_WRAPPER_FUNCTION(model_type) FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_##model_type##Wrapper* \ +FD_C_Creates##model_type##Wrapper( \ + const char* model_file, const char* params_file, const char* config_file, \ + FD_C_RuntimeOptionWrapper* fd_c_runtime_option_wrapper, \ + const FD_C_ModelFormat model_format) + + +#define DECLARE_DESTROY_WRAPPER_FUNCTION(model_type, wrapper_var_name) FASTDEPLOY_CAPI_EXPORT extern void \ +FD_C_Destroy##model_type##Wrapper(__fd_take FD_C_##model_type##Wrapper* wrapper_var_name); + +#define DECLARE_PREDICT_FUNCTION(model_type, wrapper_var_name) FASTDEPLOY_CAPI_EXPORT extern FD_C_Bool FD_C_##model_type##WrapperPredict( \ + __fd_take FD_C_##model_type##Wrapper* wrapper_var_name, FD_C_Mat img, \ + FD_C_DetectionResult* fd_c_detection_result) + +#define DECLARE_INITIALIZED_FUNCTION(model_type, wrapper_var_name) FASTDEPLOY_CAPI_EXPORT extern FD_C_Bool FD_C_##model_type##WrapperInitialized( \ + __fd_keep FD_C_##model_type##Wrapper* wrapper_var_name) + + +#define DECLARE_BATCH_PREDICT_FUNCTION(model_type, wrapper_var_name) FASTDEPLOY_CAPI_EXPORT extern FD_C_Bool FD_C_##model_type##WrapperBatchPredict( \ + __fd_keep FD_C_##model_type##Wrapper* wrapper_var_name, \ + FD_C_OneDimMat imgs, \ + FD_C_OneDimDetectionResult* results) + +#define IMPLEMENT_CREATE_WRAPPER_FUNCTION(model_type, var_name) \ + auto& runtime_option = CHECK_AND_CONVERT_FD_TYPE(RuntimeOptionWrapper, \ + fd_c_runtime_option_wrapper); \ + FD_C_##model_type##Wrapper* fd_c_##model_type##_wrapper = new FD_C_##model_type##Wrapper(); \ + fd_c_##model_type##_wrapper->var_name = \ + std::unique_ptr( \ + new fastdeploy::vision::detection::model_type( \ + std::string(model_file), std::string(params_file), \ + std::string(config_file), *runtime_option, \ + static_cast(model_format))); \ + return fd_c_##model_type##_wrapper + +#define IMPLEMENT_DESTROY_WRAPPER_FUNCTION(model_type, wrapper_var_name) delete wrapper_var_name + +#define IMPLEMENT_PREDICT_FUNCTION(model_type, wrapper_var_name) \ + cv::Mat* im = reinterpret_cast(img); \ + auto& model = \ + CHECK_AND_CONVERT_FD_TYPE(model_type##Wrapper, wrapper_var_name); \ + FD_C_DetectionResultWrapper* fd_c_detection_result_wrapper = \ + FD_C_CreateDetectionResultWrapper(); \ + auto& detection_result = CHECK_AND_CONVERT_FD_TYPE( \ + DetectionResultWrapper, fd_c_detection_result_wrapper); \ + bool successful = model->Predict(im, detection_result.get()); \ + if (successful) { \ + FD_C_DetectionResult* res = \ + FD_C_DetectionResultWrapperGetData(fd_c_detection_result_wrapper); \ + *fd_c_detection_result = *res; \ + } \ + return successful + +#define IMPLEMENT_INITIALIZED_FUNCTION(model_type, wrapper_var_name) auto& model = \ + CHECK_AND_CONVERT_FD_TYPE(model_type##Wrapper, wrapper_var_name); \ +return model->Initialized(); + +#define IMPLEMENT_BATCH_PREDICT_FUNCTION(model_type, wrapper_var_name) std::vector imgs_vec; \ + std::vector results_out; \ + for (int i = 0; i < imgs.size; i++) { \ + imgs_vec.push_back(*(reinterpret_cast(imgs.data[i]))); \ + } \ + auto& model = \ + CHECK_AND_CONVERT_FD_TYPE(model_type##Wrapper, wrapper_var_name); \ + bool successful = model->BatchPredict(imgs_vec, &results_out); \ + if (successful) { \ + results->size = results_out.size(); \ + results->data = new FD_C_DetectionResult[results->size]; \ + for (int i = 0; i < results_out.size(); i++) { \ + results->data[i] = *FD_C_DetectionResultToC(&results_out[i]); \ + } \ + } \ + return successful; + +#define DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(model_type, var_name) FD_C_##model_type##Wrapper* FD_C_Creates##model_type##Wrapper(\ + const char* model_file, const char* params_file, const char* config_file, \ + FD_C_RuntimeOptionWrapper* fd_c_runtime_option_wrapper, \ + const FD_C_ModelFormat model_format) { \ + IMPLEMENT_CREATE_WRAPPER_FUNCTION(model_type, var_name); \ +} + +#define DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(model_type, wrapper_var_name) void FD_C_Destroy##model_type##Wrapper( \ + __fd_take FD_C_##model_type##Wrapper* wrapper_var_name) { \ + IMPLEMENT_DESTROY_WRAPPER_FUNCTION(model_type, wrapper_var_name); \ +} + + +#define DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(model_type, wrapper_var_name) FD_C_Bool FD_C_##model_type##WrapperPredict( \ + FD_C_##model_type##Wrapper* wrapper_var_name, FD_C_Mat img, \ + FD_C_DetectionResult* fd_c_detection_result) { \ + IMPLEMENT_PREDICT_FUNCTION(model_type, wrapper_var_name); \ +} + +#define DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(model_type, wrapper_var_name) FD_C_Bool FD_C_##model_type##WrapperInitialized( \ + FD_C_##model_type##Wrapper* wrapper_var_name) { \ + IMPLEMENT_INITIALIZED_FUNCTION(model_type, wrapper_var_name); \ +} + +#define DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(model_type, wrapper_var_name) FD_C_Bool FD_C_##model_type##WrapperBatchPredict( \ + FD_C_##model_type##Wrapper* wrapper_var_name, FD_C_OneDimMat imgs, \ + FD_C_OneDimDetectionResult* results) { \ + IMPLEMENT_BATCH_PREDICT_FUNCTION(model_type, wrapper_var_name); \ +} diff --git a/c_api/fastdeploy_capi/vision/detection/ppdet/model.cc b/c_api/fastdeploy_capi/vision/detection/ppdet/model.cc index e7055185f..7bfbd67f0 100644 --- a/c_api/fastdeploy_capi/vision/detection/ppdet/model.cc +++ b/c_api/fastdeploy_capi/vision/detection/ppdet/model.cc @@ -21,38 +21,248 @@ extern "C" { #endif +// PPYOLOE + FD_C_PPYOLOEWrapper* FD_C_CreatesPPYOLOEWrapper( const char* model_file, const char* params_file, const char* config_file, FD_C_RuntimeOptionWrapper* fd_c_runtime_option_wrapper, const FD_C_ModelFormat model_format) { - auto& runtime_option = CHECK_AND_CONVERT_FD_TYPE(RuntimeOptionWrapper, - fd_c_runtime_option_wrapper); - FD_C_PPYOLOEWrapper* fd_c_ppyoloe_wrapper = new FD_C_PPYOLOEWrapper(); - fd_c_ppyoloe_wrapper->ppyoloe_model = - std::unique_ptr( - new fastdeploy::vision::detection::PPYOLOE( - std::string(model_file), std::string(params_file), - std::string(config_file), *runtime_option, - static_cast(model_format))); - return fd_c_ppyoloe_wrapper; + IMPLEMENT_CREATE_WRAPPER_FUNCTION(PPYOLOE, ppyoloe_model); } void FD_C_DestroyPPYOLOEWrapper( - __fd_take FD_C_PPYOLOEWrapper* fd_c_ppyoloe_wrapper) { - delete fd_c_ppyoloe_wrapper; + __fd_take FD_C_PPYOLOEWrapper* fd_ppyoloe_wrapper) { + IMPLEMENT_DESTROY_WRAPPER_FUNCTION(PPYOLOE, fd_ppyoloe_wrapper); } FD_C_Bool FD_C_PPYOLOEWrapperPredict( - FD_C_PPYOLOEWrapper* fd_c_ppyoloe_wrapper, FD_C_Mat img, - FD_C_DetectionResultWrapper* fd_c_detection_result_wrapper) { - cv::Mat* im = reinterpret_cast(img); - auto& ppyoloe_model = - CHECK_AND_CONVERT_FD_TYPE(PPYOLOEWrapper, fd_c_ppyoloe_wrapper); - auto& detection_result = CHECK_AND_CONVERT_FD_TYPE( - DetectionResultWrapper, fd_c_detection_result_wrapper); - return ppyoloe_model->Predict(im, detection_result.get()); + FD_C_PPYOLOEWrapper* fd_ppyoloe_wrapper, FD_C_Mat img, + FD_C_DetectionResult* fd_c_detection_result) { + IMPLEMENT_PREDICT_FUNCTION(PPYOLOE, fd_ppyoloe_wrapper); } +FD_C_Bool FD_C_PPYOLOEWrapperInitialized( + FD_C_PPYOLOEWrapper* fd_ppyoloe_wrapper) { + IMPLEMENT_INITIALIZED_FUNCTION(PPYOLOE, fd_ppyoloe_wrapper); +} + +FD_C_DetectionResult* FD_C_DetectionResultToC( + fastdeploy::vision::DetectionResult* detection_result) { + // Internal use, transfer fastdeploy::vision::DetectionResult to + // FD_C_DetectionResult + FD_C_DetectionResult* fd_c_detection_result = new FD_C_DetectionResult(); + // copy boxes + const int boxes_coordinate_dim = 4; + fd_c_detection_result->boxes.size = detection_result->boxes.size(); + fd_c_detection_result->boxes.data = + new FD_C_OneDimArrayFloat[fd_c_detection_result->boxes.size]; + for (size_t i = 0; i < detection_result->boxes.size(); i++) { + fd_c_detection_result->boxes.data[i].size = boxes_coordinate_dim; + fd_c_detection_result->boxes.data[i].data = new float[boxes_coordinate_dim]; + for (size_t j = 0; j < boxes_coordinate_dim; j++) { + fd_c_detection_result->boxes.data[i].data[j] = + detection_result->boxes[i][j]; + } + } + // copy scores + fd_c_detection_result->scores.size = detection_result->scores.size(); + fd_c_detection_result->scores.data = + new float[fd_c_detection_result->scores.size]; + memcpy(fd_c_detection_result->scores.data, detection_result->scores.data(), + sizeof(float) * fd_c_detection_result->scores.size); + // copy label_ids + fd_c_detection_result->label_ids.size = detection_result->label_ids.size(); + fd_c_detection_result->label_ids.data = + new int32_t[fd_c_detection_result->label_ids.size]; + memcpy(fd_c_detection_result->label_ids.data, + detection_result->label_ids.data(), + sizeof(int32_t) * fd_c_detection_result->label_ids.size); + // copy masks + fd_c_detection_result->masks.size = detection_result->masks.size(); + fd_c_detection_result->masks.data = + new FD_C_Mask[fd_c_detection_result->masks.size]; + for (size_t i = 0; i < detection_result->masks.size(); i++) { + // copy data in mask + fd_c_detection_result->masks.data[i].data.size = + detection_result->masks[i].data.size(); + fd_c_detection_result->masks.data[i].data.data = + new uint8_t[detection_result->masks[i].data.size()]; + memcpy(fd_c_detection_result->masks.data[i].data.data, + detection_result->masks[i].data.data(), + sizeof(uint8_t) * detection_result->masks[i].data.size()); + // copy shape in mask + fd_c_detection_result->masks.data[i].shape.size = + detection_result->masks[i].shape.size(); + fd_c_detection_result->masks.data[i].shape.data = + new int64_t[detection_result->masks[i].shape.size()]; + memcpy(fd_c_detection_result->masks.data[i].shape.data, + detection_result->masks[i].shape.data(), + sizeof(int64_t) * detection_result->masks[i].shape.size()); + fd_c_detection_result->masks.data[i].type = + static_cast(detection_result->masks[i].type); + } + fd_c_detection_result->contain_masks = detection_result->contain_masks; + fd_c_detection_result->type = + static_cast(detection_result->type); + return fd_c_detection_result; +} + +FD_C_Bool FD_C_PPYOLOEWrapperBatchPredict( + FD_C_PPYOLOEWrapper* fd_ppyoloe_wrapper, FD_C_OneDimMat imgs, + FD_C_OneDimDetectionResult* results) { + IMPLEMENT_BATCH_PREDICT_FUNCTION(PPYOLOE, fd_ppyoloe_wrapper); +} + +// PicoDet +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(PicoDet, picodet_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(PicoDet, fd_picodet_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(PicoDet, fd_picodet_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(PicoDet, fd_picodet_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(PicoDet, fd_picodet_wrapper) + +// PPYOLO +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(PPYOLO, ppyolo_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(PPYOLO, fd_ppyolo_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(PPYOLO, fd_ppyolo_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(PPYOLO, fd_ppyolo_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(PPYOLO, fd_ppyolo_wrapper) + +// YOLOv3 +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(YOLOv3, yolov3_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(YOLOv3, fd_yolov3_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(YOLOv3, fd_yolov3_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(YOLOv3, fd_yolov3_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(YOLOv3, fd_yolov3_wrapper) + +// PaddleYOLOX +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(PaddleYOLOX, paddleyolox_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(PaddleYOLOX, + fd_paddleyolox_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(PaddleYOLOX, fd_paddleyolox_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(PaddleYOLOX, fd_paddleyolox_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(PaddleYOLOX, + fd_paddleyolox_wrapper) + +// FasterRCNN +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(FasterRCNN, fasterrcnn_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(FasterRCNN, + fd_fasterrcnn_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(FasterRCNN, fd_fasterrcnn_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(FasterRCNN, fd_fasterrcnn_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(FasterRCNN, fd_fasterrcnn_wrapper) + +// MaskRCNN +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(MaskRCNN, maskrcnn_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(MaskRCNN, fd_maskrcnn_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(MaskRCNN, fd_maskrcnn_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(MaskRCNN, fd_maskrcnn_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(MaskRCNN, fd_maskrcnn_wrapper) + +// SSD +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(SSD, ssd_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(SSD, fd_ssd_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(SSD, fd_ssd_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(SSD, fd_ssd_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(SSD, fd_ssd_wrapper) + +// PaddleYOLOv5 +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(PaddleYOLOv5, paddleyolov5_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(PaddleYOLOv5, + fd_paddleyolov5_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(PaddleYOLOv5, fd_paddleyolov5_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(PaddleYOLOv5, + fd_paddleyolov5_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(PaddleYOLOv5, + fd_paddleyolov5_wrapper) + +// PaddleYOLOv6 +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(PaddleYOLOv6, paddleyolov6_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(PaddleYOLOv6, + fd_paddleyolov6_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(PaddleYOLOv6, fd_paddleyolov6_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(PaddleYOLOv6, + fd_paddleyolov6_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(PaddleYOLOv6, + fd_paddleyolov6_wrapper) + +// PaddleYOLOv7 +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(PaddleYOLOv7, paddleyolov7_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(PaddleYOLOv7, + fd_paddleyolov7_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(PaddleYOLOv7, fd_paddleyolov7_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(PaddleYOLOv7, + fd_paddleyolov7_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(PaddleYOLOv7, + fd_paddleyolov7_wrapper) + +// PaddleYOLOv8 +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(PaddleYOLOv8, paddleyolov8_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(PaddleYOLOv8, + fd_paddleyolov8_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(PaddleYOLOv8, fd_paddleyolov8_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(PaddleYOLOv8, + fd_paddleyolov8_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(PaddleYOLOv8, + fd_paddleyolov8_wrapper) + +// RTMDet +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(RTMDet, rtmdet_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(RTMDet, fd_rtmdet_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(RTMDet, fd_rtmdet_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(RTMDet, fd_rtmdet_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(RTMDet, fd_rtmdet_wrapper) + +// CascadeRCNN +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(CascadeRCNN, cascadercnn_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(CascadeRCNN, + fd_cascadercnn_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(CascadeRCNN, fd_cascadercnn_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(CascadeRCNN, fd_cascadercnn_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(CascadeRCNN, + fd_cascadercnn_wrapper) + +// PSSDet +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(PSSDet, pssdet_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(PSSDet, fd_pssdet_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(PSSDet, fd_pssdet_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(PSSDet, fd_pssdet_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(PSSDet, fd_pssdet_wrapper) + +// RetinaNet +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(RetinaNet, retinanet_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(RetinaNet, fd_retinanet_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(RetinaNet, fd_retinanet_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(RetinaNet, fd_retinanet_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(RetinaNet, fd_retinanet_wrapper) + +// FCOS +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(FCOS, fcos_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(FCOS, fd_fcos_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(FCOS, fd_fcos_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(FCOS, fd_fcos_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(FCOS, fd_fcos_wrapper) + +// TTFNet +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(TTFNet, ttfnet_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(TTFNet, fd_ttfnet_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(TTFNet, fd_ttfnet_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(TTFNet, fd_ttfnet_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(TTFNet, fd_ttfnet_wrapper) + +// TOOD +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(TOOD, tood_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(TOOD, fd_tood_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(TOOD, fd_tood_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(TOOD, fd_tood_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(TOOD, fd_tood_wrapper) + +// GFL +DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(GFL, gfl_model) +DECLARE_AND_IMPLEMENT_DESTROY_WRAPPER_FUNCTION(GFL, fd_gfl_wrapper) +DECLARE_AND_IMPLEMENT_PREDICT_FUNCTION(GFL, fd_gfl_wrapper) +DECLARE_AND_IMPLEMENT_INITIALIZED_FUNCTION(GFL, fd_gfl_wrapper) +DECLARE_AND_IMPLEMENT_BATCH_PREDICT_FUNCTION(GFL, fd_gfl_wrapper) + #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/c_api/fastdeploy_capi/vision/detection/ppdet/model.h b/c_api/fastdeploy_capi/vision/detection/ppdet/model.h index 6dce7a64e..71b74bcdf 100644 --- a/c_api/fastdeploy_capi/vision/detection/ppdet/model.h +++ b/c_api/fastdeploy_capi/vision/detection/ppdet/model.h @@ -18,14 +18,18 @@ #include "fastdeploy_capi/fd_type.h" #include "fastdeploy_capi/runtime_option.h" #include "fastdeploy_capi/vision/result.h" +#include "fastdeploy_capi/vision/detection/ppdet/base_define.h" -typedef struct FD_C_PPYOLOEWrapper FD_C_PPYOLOEWrapper; typedef struct FD_C_RuntimeOptionWrapper FD_C_RuntimeOptionWrapper; #ifdef __cplusplus extern "C" { #endif +// PPYOLOE + +typedef struct FD_C_PPYOLOEWrapper FD_C_PPYOLOEWrapper; + /** \brief Create a new FD_C_PPYOLOEWrapper object * * \param[in] model_file Path of model file, e.g resnet/model.pdmodel @@ -37,19 +41,14 @@ extern "C" { * \return Return a pointer to FD_C_PPYOLOEWrapper object */ -FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_PPYOLOEWrapper* -FD_C_CreatesPPYOLOEWrapper( - const char* model_file, const char* params_file, const char* config_file, - FD_C_RuntimeOptionWrapper* fd_c_runtime_option_wrapper, - const FD_C_ModelFormat model_format); +DECLARE_CREATE_WRAPPER_FUNCTION(PPYOLOE); /** \brief Destroy a FD_C_PPYOLOEWrapper object * * \param[in] fd_c_ppyoloe_wrapper pointer to FD_C_PPYOLOEWrapper object */ -FASTDEPLOY_CAPI_EXPORT extern void -FD_C_DestroyPPYOLOEWrapper(__fd_take FD_C_PPYOLOEWrapper* fd_c_ppyoloe_wrapper); +DECLARE_DESTROY_WRAPPER_FUNCTION(PPYOLOE, fd_c_ppyoloe_wrapper); /** \brief Predict the detection result for an input image * @@ -58,9 +57,1041 @@ FD_C_DestroyPPYOLOEWrapper(__fd_take FD_C_PPYOLOEWrapper* fd_c_ppyoloe_wrapper); * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. */ -FASTDEPLOY_CAPI_EXPORT extern FD_C_Bool FD_C_PPYOLOEWrapperPredict( - __fd_take FD_C_PPYOLOEWrapper* fd_c_ppyoloe_wrapper, FD_C_Mat img, - FD_C_DetectionResultWrapper* fd_c_detection_result_wrapper); +DECLARE_PREDICT_FUNCTION(PPYOLOE, fd_c_ppyoloe_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_ppyoloe_wrapper pointer to FD_C_PPYOLOEWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(PPYOLOE, fd_c_ppyoloe_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_ppyoloe_wrapper pointer to FD_C_PPYOLOEWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(PPYOLOE, fd_c_ppyoloe_wrapper); + +// PicoDet + +typedef struct FD_C_PicoDetWrapper FD_C_PicoDetWrapper; + +/** \brief Create a new FD_C_PicoDetWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_PicoDetWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(PicoDet); + +/** \brief Destroy a FD_C_PicoDetWrapper object + * + * \param[in] fd_c_picodet_wrapper pointer to FD_C_PicoDetWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(PicoDet, fd_c_picodet_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_picodet_wrapper pointer to FD_C_PicoDetWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(PicoDet, fd_c_picodet_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_picodet_wrapper pointer to FD_C_PicoDetWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(PicoDet, fd_c_picodet_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_picodet_wrapper pointer to FD_C_PicoDetWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(PicoDet, fd_c_picodet_wrapper); + + +// PPYOLO + +typedef struct FD_C_PPYOLOWrapper FD_C_PPYOLOWrapper; + +/** \brief Create a new FD_C_PPYOLOWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_PPYOLOWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(PPYOLO); + +/** \brief Destroy a FD_C_PPYOLOWrapper object + * + * \param[in] fd_c_ppyolo_wrapper pointer to FD_C_PPYOLOWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(PPYOLO, fd_c_ppyolo_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_ppyolo_wrapper pointer to FD_C_PPYOLOWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(PPYOLO, fd_c_ppyolo_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_ppyolo_wrapper pointer to FD_C_PPYOLOWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(PPYOLO, fd_c_ppyolo_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_ppyolo_wrapper pointer to FD_C_PPYOLOWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(PPYOLO, fd_c_ppyolo_wrapper); + +// YOLOv3 + +typedef struct FD_C_YOLOv3Wrapper FD_C_YOLOv3Wrapper; + +/** \brief Create a new FD_C_YOLOv3Wrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_YOLOv3Wrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(YOLOv3); + +/** \brief Destroy a FD_C_YOLOv3Wrapper object + * + * \param[in] fd_c_yolov3_wrapper pointer to FD_C_YOLOv3Wrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(YOLOv3, fd_c_yolov3_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_yolov3_wrapper pointer to FD_C_YOLOv3Wrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(YOLOv3, fd_c_yolov3_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_yolov3_wrapper pointer to FD_C_YOLOv3Wrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(YOLOv3, fd_c_yolov3_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_yolov3_wrapper pointer to FD_C_YOLOv3Wrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(YOLOv3, fd_c_yolov3_wrapper); + +// PaddleYOLOX + +typedef struct FD_C_PaddleYOLOXWrapper FD_C_PaddleYOLOXWrapper; + +/** \brief Create a new FD_C_PaddleYOLOXWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_PaddleYOLOXWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(PaddleYOLOX); + +/** \brief Destroy a FD_C_PaddleYOLOXWrapper object + * + * \param[in] fd_c_paddleyolox_wrapper pointer to FD_C_PaddleYOLOXWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(PaddleYOLOX, fd_c_paddleyolox_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_paddleyolox_wrapper pointer to FD_C_PaddleYOLOXWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(PaddleYOLOX, fd_c_paddleyolox_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_paddleyolox_wrapper pointer to FD_C_PaddleYOLOXWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(PaddleYOLOX, fd_c_paddleyolox_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_paddleyolox_wrapper pointer to FD_C_PaddleYOLOXWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(PaddleYOLOX, fd_c_paddleyolox_wrapper); + +// FasterRCNN + +typedef struct FD_C_FasterRCNNWrapper FD_C_FasterRCNNWrapper; + +/** \brief Create a new FD_C_FasterRCNNWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_FasterRCNNWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(FasterRCNN); + +/** \brief Destroy a FD_C_FasterRCNNWrapper object + * + * \param[in] fd_c_fasterrcnn_wrapper pointer to FD_C_FasterRCNNWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(FasterRCNN, fd_c_fasterrcnn_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_fasterrcnn_wrapper pointer to FD_C_FasterRCNNWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(FasterRCNN, fd_c_fasterrcnn_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_fasterrcnn_wrapper pointer to FD_C_FasterRCNNWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(FasterRCNN, fd_c_fasterrcnn_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_fasterrcnn_wrapper pointer to FD_C_FasterRCNNWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(FasterRCNN, fd_c_fasterrcnn_wrapper); + +// MaskRCNN + +typedef struct FD_C_MaskRCNNWrapper FD_C_MaskRCNNWrapper; + +/** \brief Create a new FD_C_MaskRCNNWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_MaskRCNNWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(MaskRCNN); + +/** \brief Destroy a FD_C_MaskRCNNWrapper object + * + * \param[in] fd_c_maskrcnn_wrapper pointer to FD_C_MaskRCNNWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(MaskRCNN, fd_c_maskrcnn_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_maskrcnn_wrapper pointer to FD_C_MaskRCNNWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(MaskRCNN, fd_c_maskrcnn_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_maskrcnn_wrapper pointer to FD_C_MaskRCNNWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(MaskRCNN, fd_c_maskrcnn_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_maskrcnn_wrapper pointer to FD_C_MaskRCNNWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(MaskRCNN, fd_c_maskrcnn_wrapper); + +// SSD + +typedef struct FD_C_SSDWrapper FD_C_SSDWrapper; + +/** \brief Create a new FD_C_SSDWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_SSDWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(SSD); + +/** \brief Destroy a FD_C_SSDWrapper object + * + * \param[in] fd_c_ssd_wrapper pointer to FD_C_SSDWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(SSD, fd_c_ssd_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_ssd_wrapper pointer to FD_C_SSDWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(SSD, fd_c_ssd_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_ssd_wrapper pointer to FD_C_SSDWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(SSD, fd_c_ssd_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_ssd_wrapper pointer to FD_C_SSDWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(SSD, fd_c_ssd_wrapper); + +// PaddleYOLOv5 + +typedef struct FD_C_PaddleYOLOv5Wrapper FD_C_PaddleYOLOv5Wrapper; + +/** \brief Create a new FD_C_PaddleYOLOv5Wrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_PaddleYOLOv5Wrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(PaddleYOLOv5); + +/** \brief Destroy a FD_C_PaddleYOLOv5Wrapper object + * + * \param[in] fd_c_paddleyolov5_wrapper pointer to FD_C_PaddleYOLOv5Wrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(PaddleYOLOv5, fd_c_paddleyolov5_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_paddleyolov5_wrapper pointer to FD_C_PaddleYOLOv5Wrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(PaddleYOLOv5, fd_c_paddleyolov5_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_paddleyolov5_wrapper pointer to FD_C_PaddleYOLOv5Wrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(PaddleYOLOv5, fd_c_paddleyolov5_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_paddleyolov5_wrapper pointer to FD_C_PaddleYOLOv5Wrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(PaddleYOLOv5, fd_c_paddleyolov5_wrapper); + +// PaddleYOLOv6 + +typedef struct FD_C_PaddleYOLOv6Wrapper FD_C_PaddleYOLOv6Wrapper; + +/** \brief Create a new FD_C_PaddleYOLOv6Wrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_PaddleYOLOv6Wrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(PaddleYOLOv6); + +/** \brief Destroy a FD_C_PaddleYOLOv6Wrapper object + * + * \param[in] fd_c_paddleyolov6_wrapper pointer to FD_C_PaddleYOLOv6Wrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(PaddleYOLOv6, fd_c_paddleyolov6_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_paddleyolov6_wrapper pointer to FD_C_PaddleYOLOv6Wrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(PaddleYOLOv6, fd_c_paddleyolov6_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_paddleyolov6_wrapper pointer to FD_C_PaddleYOLOv6Wrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(PaddleYOLOv6, fd_c_paddleyolov6_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_paddleyolov6_wrapper pointer to FD_C_PaddleYOLOv6Wrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(PaddleYOLOv6, fd_c_paddleyolov6_wrapper); + +// PaddleYOLOv7 + +typedef struct FD_C_PaddleYOLOv7Wrapper FD_C_PaddleYOLOv7Wrapper; + +/** \brief Create a new FD_C_PaddleYOLOv7Wrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_PaddleYOLOv7Wrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(PaddleYOLOv7); + +/** \brief Destroy a FD_C_PaddleYOLOv7Wrapper object + * + * \param[in] fd_c_paddleyolov7_wrapper pointer to FD_C_PaddleYOLOv7Wrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(PaddleYOLOv7, fd_c_paddleyolov7_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_paddleyolov7_wrapper pointer to FD_C_PaddleYOLOv7Wrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(PaddleYOLOv7, fd_c_paddleyolov7_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_paddleyolov7_wrapper pointer to FD_C_PaddleYOLOv7Wrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(PaddleYOLOv7, fd_c_paddleyolov7_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_paddleyolov7_wrapper pointer to FD_C_PaddleYOLOv7Wrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(PaddleYOLOv7, fd_c_paddleyolov7_wrapper); + +// PaddleYOLOv8 + +typedef struct FD_C_PaddleYOLOv8Wrapper FD_C_PaddleYOLOv8Wrapper; + +/** \brief Create a new FD_C_PaddleYOLOv8Wrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_PaddleYOLOv8Wrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(PaddleYOLOv8); + +/** \brief Destroy a FD_C_PaddleYOLOv8Wrapper object + * + * \param[in] fd_c_paddleyolov8_wrapper pointer to FD_C_PaddleYOLOv8Wrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(PaddleYOLOv8, fd_c_paddleyolov8_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_paddleyolov8_wrapper pointer to FD_C_PaddleYOLOv8Wrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(PaddleYOLOv8, fd_c_paddleyolov8_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_paddleyolov8_wrapper pointer to FD_C_PaddleYOLOv8Wrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(PaddleYOLOv8, fd_c_paddleyolov8_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_paddleyolov8_wrapper pointer to FD_C_PaddleYOLOv8Wrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(PaddleYOLOv8, fd_c_paddleyolov8_wrapper); + +// RTMDet + +typedef struct FD_C_RTMDetWrapper FD_C_RTMDetWrapper; + +/** \brief Create a new FD_C_RTMDetWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_RTMDetWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(RTMDet); + +/** \brief Destroy a FD_C_RTMDetWrapper object + * + * \param[in] fd_c_rtmdet_wrapper pointer to FD_C_RTMDetWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(RTMDet, fd_c_rtmdet_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_rtmdet_wrapper pointer to FD_C_RTMDetWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(RTMDet, fd_c_rtmdet_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_rtmdet_wrapper pointer to FD_C_RTMDetWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(RTMDet, fd_c_rtmdet_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_rtmdet_wrapper pointer to FD_C_RTMDetWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(RTMDet, fd_c_rtmdet_wrapper); + +// CascadeRCNN + +typedef struct FD_C_CascadeRCNNWrapper FD_C_CascadeRCNNWrapper; + +/** \brief Create a new FD_C_CascadeRCNNWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_CascadeRCNNWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(CascadeRCNN); + +/** \brief Destroy a FD_C_CascadeRCNNWrapper object + * + * \param[in] fd_c_cascadercnn_wrapper pointer to FD_C_CascadeRCNNWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(CascadeRCNN, fd_c_cascadercnn_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_cascadercnn_wrapper pointer to FD_C_CascadeRCNNWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(CascadeRCNN, fd_c_cascadercnn_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_cascadercnn_wrapper pointer to FD_C_CascadeRCNNWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(CascadeRCNN, fd_c_cascadercnn_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_cascadercnn_wrapper pointer to FD_C_CascadeRCNNWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(CascadeRCNN, fd_c_cascadercnn_wrapper); + +// PSSDet + +typedef struct FD_C_PSSDetWrapper FD_C_PSSDetWrapper; + +/** \brief Create a new FD_C_PSSDetWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_PSSDetWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(PSSDet); + +/** \brief Destroy a FD_C_PSSDetWrapper object + * + * \param[in] fd_c_pssdet_wrapper pointer to FD_C_PSSDetWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(PSSDet, fd_c_pssdet_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_pssdet_wrapper pointer to FD_C_PSSDetWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(PSSDet, fd_c_pssdet_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_pssdet_wrapper pointer to FD_C_PSSDetWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(PSSDet, fd_c_pssdet_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_pssdet_wrapper pointer to FD_C_PSSDetWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(PSSDet, fd_c_pssdet_wrapper); + +// RetinaNet + +typedef struct FD_C_RetinaNetWrapper FD_C_RetinaNetWrapper; + +/** \brief Create a new FD_C_RetinaNetWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_RetinaNetWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(RetinaNet); + +/** \brief Destroy a FD_C_RetinaNetWrapper object + * + * \param[in] fd_c_retinanet_wrapper pointer to FD_C_RetinaNetWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(RetinaNet, fd_c_retinanet_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_retinanet_wrapper pointer to FD_C_RetinaNetWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(RetinaNet, fd_c_retinanet_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_retinanet_wrapper pointer to FD_C_RetinaNetWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(RetinaNet, fd_c_retinanet_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_retinanet_wrapper pointer to FD_C_RetinaNetWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(RetinaNet, fd_c_retinanet_wrapper); + +// FCOS + +typedef struct FD_C_FCOSWrapper FD_C_FCOSWrapper; + +/** \brief Create a new FD_C_FCOSWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_FCOSWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(FCOS); + +/** \brief Destroy a FD_C_FCOSWrapper object + * + * \param[in] fd_c_fcos_wrapper pointer to FD_C_FCOSWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(FCOS, fd_c_fcos_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_fcos_wrapper pointer to FD_C_FCOSWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(FCOS, fd_c_fcos_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_fcos_wrapper pointer to FD_C_FCOSWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(FCOS, fd_c_fcos_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_fcos_wrapper pointer to FD_C_FCOSWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(FCOS, fd_c_fcos_wrapper); + +// TTFNet + +typedef struct FD_C_TTFNetWrapper FD_C_TTFNetWrapper; + +/** \brief Create a new FD_C_TTFNetWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_TTFNetWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(TTFNet); + +/** \brief Destroy a FD_C_TTFNetWrapper object + * + * \param[in] fd_c_ttfnet_wrapper pointer to FD_C_TTFNetWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(TTFNet, fd_c_ttfnet_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_ttfnet_wrapper pointer to FD_C_TTFNetWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(TTFNet, fd_c_ttfnet_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_ttfnet_wrapper pointer to FD_C_TTFNetWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(TTFNet, fd_c_ttfnet_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_ttfnet_wrapper pointer to FD_C_TTFNetWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(TTFNet, fd_c_ttfnet_wrapper); + +// TOOD + +typedef struct FD_C_TOODWrapper FD_C_TOODWrapper; + +/** \brief Create a new FD_C_TOODWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_TOODWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(TOOD); + +/** \brief Destroy a FD_C_TOODWrapper object + * + * \param[in] fd_c_tood_wrapper pointer to FD_C_TOODWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(TOOD, fd_c_tood_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_tood_wrapper pointer to FD_C_TOODWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(TOOD, fd_c_tood_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_tood_wrapper pointer to FD_C_TOODWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(TOOD, fd_c_tood_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_tood_wrapper pointer to FD_C_TOODWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(TOOD, fd_c_tood_wrapper); + +// GFL + +typedef struct FD_C_GFLWrapper FD_C_GFLWrapper; + +/** \brief Create a new FD_C_GFLWrapper object + * + * \param[in] model_file Path of model file, e.g resnet/model.pdmodel + * \param[in] params_file Path of parameter file, e.g resnet/model.pdiparams, if the model format is ONNX, this parameter will be ignored + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + * \param[in] fd_c_runtime_option_wrapper RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends` + * \param[in] model_format Model format of the loaded model, default is Paddle format + * + * \return Return a pointer to FD_C_GFLWrapper object + */ + +DECLARE_CREATE_WRAPPER_FUNCTION(GFL); + +/** \brief Destroy a FD_C_GFLWrapper object + * + * \param[in] fd_c_gfl_wrapper pointer to FD_C_GFLWrapper object + */ + +DECLARE_DESTROY_WRAPPER_FUNCTION(GFL, fd_c_gfl_wrapper); + +/** \brief Predict the detection result for an input image + * + * \param[in] fd_c_gfl_wrapper pointer to FD_C_GFLWrapper object + * \param[in] img pointer to cv::Mat image + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object, which stores the result. + */ + +DECLARE_PREDICT_FUNCTION(GFL, fd_c_gfl_wrapper); + +/** \brief Check if the model is initialized successfully + * + * \param[in] fd_c_gfl_wrapper pointer to FD_C_GFLWrapper object + * + * \return Return a bool of value true if initialized successfully + */ + +DECLARE_INITIALIZED_FUNCTION(GFL, fd_c_gfl_wrapper); + +/** \brief Predict the detection results for a batch of input images + * + * \param[in] fd_c_gfl_wrapper pointer to FD_C_GFLWrapper object + * \param[in] imgs, The input image list, each element comes from cv::imread() + * \param[in] results The output detection result list + * + * \return true if the prediction successed, otherwise false + */ + +DECLARE_BATCH_PREDICT_FUNCTION(GFL, fd_c_gfl_wrapper); + + + + + + #ifdef __cplusplus } // extern "C" diff --git a/c_api/fastdeploy_capi/vision/result.cc b/c_api/fastdeploy_capi/vision/result.cc index 207ef3950..175c6b29c 100644 --- a/c_api/fastdeploy_capi/vision/result.cc +++ b/c_api/fastdeploy_capi/vision/result.cc @@ -90,6 +90,16 @@ FD_C_ClassifyResultWrapper* FD_C_CreateClassifyResultWrapperFromData( return fd_c_classify_result_wrapper; } +char* FD_C_ClassifyResultWrapperStr( + FD_C_ClassifyResultWrapper* fd_c_classify_result_wrapper) { + auto& classify_result = CHECK_AND_CONVERT_FD_TYPE( + ClassifyResultWrapper, fd_c_classify_result_wrapper); + std::string information = classify_result->Str(); + char* cstr = new char[information.length() + 1]; + std::strcpy(cstr, information.c_str()); + return cstr; +} + // Detection Results FD_C_DetectionResultWrapper* FD_C_CreateDetectionResultWrapper() { @@ -237,6 +247,17 @@ FD_C_DetectionResultWrapper* FD_C_CreateDetectionResultWrapperFromData( return fd_c_detection_result_wrapper; } + +char* FD_C_DetectionResultWrapperStr( + FD_C_DetectionResultWrapper* fd_c_detection_result_wrapper) { + auto& detection_result = CHECK_AND_CONVERT_FD_TYPE( + DetectionResultWrapper, fd_c_detection_result_wrapper); + std::string information = detection_result->Str(); + char* cstr = new char[information.length() + 1]; + std::strcpy(cstr, information.c_str()); + return cstr; +} + #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/c_api/fastdeploy_capi/vision/result.h b/c_api/fastdeploy_capi/vision/result.h index 247ec50f6..40a846af4 100644 --- a/c_api/fastdeploy_capi/vision/result.h +++ b/c_api/fastdeploy_capi/vision/result.h @@ -30,6 +30,11 @@ typedef struct FD_C_ClassifyResult { FD_C_ResultType type; } FD_C_ClassifyResult; +typedef struct FD_C_OneDimClassifyResult { + size_t size; + FD_C_ClassifyResult* data; +} FD_C_OneDimClassifyResult; + typedef struct FD_C_Mask { FD_C_OneDimArrayUint8 data; FD_C_OneDimArrayInt64 shape; @@ -50,6 +55,11 @@ typedef struct FD_C_DetectionResult { FD_C_ResultType type; } FD_C_DetectionResult; +typedef struct FD_C_OneDimDetectionResult { + size_t size; + FD_C_DetectionResult* data; +} FD_C_OneDimDetectionResult; + // Classification Results /** \brief Create a new FD_C_ClassifyResultWrapper object @@ -95,6 +105,16 @@ FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_ClassifyResultWrapper* FD_C_CreateClassifyResultWrapperFromData( __fd_keep FD_C_ClassifyResult* fd_c_classify_result); +/** \brief Print ClassifyResult formated information + * + * \param[in] fd_c_classify_result_wrapper pointer to FD_C_ClassifyResultWrapper object + * \return Return a string pointer + */ + +FASTDEPLOY_CAPI_EXPORT extern __fd_give char* +FD_C_ClassifyResultWrapperStr( + __fd_keep FD_C_ClassifyResultWrapper* fd_c_classify_result_wrapper); + // Detection Results /** \brief Create a new FD_C_DetectionResultWrapper object @@ -140,6 +160,16 @@ FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_DetectionResultWrapper* FD_C_CreateDetectionResultWrapperFromData( __fd_keep FD_C_DetectionResult* fd_c_detection_result); +/** \brief Print DetectionResult formated information + * + * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object + * \return Return a string pointer + */ + +FASTDEPLOY_CAPI_EXPORT extern __fd_give char* +FD_C_DetectionResultWrapperStr( + __fd_keep FD_C_DetectionResultWrapper* fd_c_detection_result_wrapper); + #ifdef __cplusplus } // extern "C" #endif diff --git a/c_api/fastdeploy_capi/vision/visualize.cc b/c_api/fastdeploy_capi/vision/visualize.cc index 6045270bd..ffa0b0939 100644 --- a/c_api/fastdeploy_capi/vision/visualize.cc +++ b/c_api/fastdeploy_capi/vision/visualize.cc @@ -29,11 +29,31 @@ FD_C_Mat FD_C_VisDetection(FD_C_Mat im, FD_C_CreateDetectionResultWrapperFromData(fd_c_detection_result); auto& detection_result = CHECK_AND_CONVERT_FD_TYPE( DetectionResultWrapper, fd_c_detection_result_wrapper); - cv::Mat result = fastdeploy::vision::Visualize::VisDetection( + cv::Mat result = fastdeploy::vision::VisDetection( *(reinterpret_cast(im)), *detection_result, score_threshold, line_size, font_size); return new cv::Mat(result); } + +FD_C_Mat FD_C_VisDetectionWithLabel(FD_C_Mat im, + FD_C_DetectionResult* fd_c_detection_result, + FD_C_OneDimArrayCstr* labels, + float score_threshold, int line_size, + float font_size) { + std::vector labels_in; + for (int i = 0; i < labels->size; i++) { + labels_in.emplace_back(labels->data[i].data); + } + FD_C_DetectionResultWrapper* fd_c_detection_result_wrapper = + FD_C_CreateDetectionResultWrapperFromData(fd_c_detection_result); + auto& detection_result = CHECK_AND_CONVERT_FD_TYPE( + DetectionResultWrapper, fd_c_detection_result_wrapper); + cv::Mat result = fastdeploy::vision::VisDetection( + *(reinterpret_cast(im)), *detection_result, labels_in, + score_threshold, line_size, font_size); + return new cv::Mat(result); +} + #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/c_api/fastdeploy_capi/vision/visualize.h b/c_api/fastdeploy_capi/vision/visualize.h index 43d406dab..ca5bfcab3 100644 --- a/c_api/fastdeploy_capi/vision/visualize.h +++ b/c_api/fastdeploy_capi/vision/visualize.h @@ -22,15 +22,37 @@ extern "C" { #endif -/** \brief Visualize Detection +/** \brief Show the visualized results for detection models * - * \return Return a pointer to cv::Mat object + * \param[in] im the input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format + * \param[in] result the result produced by model + * \param[in] score_threshold threshold for result scores, the bounding box will not be shown if the score is less than score_threshold + * \param[in] line_size line size for bounding boxes + * \param[in] font_size font size for text + * \return cv::Mat type stores the visualized results */ FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_Mat FD_C_VisDetection(FD_C_Mat im, FD_C_DetectionResult* fd_detection_result, float score_threshold, int line_size, float font_size); +/** \brief Show the visualized results with custom labels for detection models + * + * \param[in] im the input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format + * \param[in] result the result produced by model + * \param[in] labels the visualized result will show the bounding box contain class label + * \param[in] score_threshold threshold for result scores, the bounding box will not be shown if the score is less than score_threshold + * \param[in] line_size line size for bounding boxes + * \param[in] font_size font size for text + * \return cv::Mat type stores the visualized results + */ +FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_Mat FD_C_VisDetectionWithLabel( + FD_C_Mat im, + FD_C_DetectionResult* fd_detection_result, + FD_C_OneDimArrayCstr* labels, + float score_threshold, + int line_size, float font_size); + #ifdef __cplusplus } // extern "C" #endif