mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-16 13:41:30 +08:00
[C API] add ppseg c api (#1384)
* add ppseg c api * fix bug * fix interface
This commit is contained in:
@@ -61,11 +61,10 @@ FD_C_Destroy##model_type##Wrapper(__fd_take FD_C_##model_type##Wrapper* wrapper_
|
||||
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
|
||||
FD_C_DetectionResultWrapperToCResult(fd_c_detection_result_wrapper, fd_c_detection_result); \
|
||||
} \
|
||||
FD_C_DestroyDetectionResultWrapper(fd_c_detection_result_wrapper); \
|
||||
return successful
|
||||
|
||||
#define IMPLEMENT_INITIALIZED_FUNCTION(model_type, wrapper_var_name) auto& model = \
|
||||
CHECK_AND_CONVERT_FD_TYPE(model_type##Wrapper, wrapper_var_name); \
|
||||
@@ -73,8 +72,11 @@ return model->Initialized();
|
||||
|
||||
#define IMPLEMENT_BATCH_PREDICT_FUNCTION(model_type, wrapper_var_name) std::vector<cv::Mat> imgs_vec; \
|
||||
std::vector<fastdeploy::vision::DetectionResult> results_out; \
|
||||
std::vector<FD_C_DetectionResultWrapper*> results_wrapper_out; \
|
||||
for (int i = 0; i < imgs.size; i++) { \
|
||||
imgs_vec.push_back(*(reinterpret_cast<cv::Mat*>(imgs.data[i]))); \
|
||||
FD_C_DetectionResultWrapper* fd_detection_result_wrapper = FD_C_CreateDetectionResultWrapper(); \
|
||||
results_wrapper_out.push_back(fd_detection_result_wrapper); \
|
||||
} \
|
||||
auto& model = \
|
||||
CHECK_AND_CONVERT_FD_TYPE(model_type##Wrapper, wrapper_var_name); \
|
||||
@@ -83,9 +85,14 @@ return model->Initialized();
|
||||
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]); \
|
||||
(*CHECK_AND_CONVERT_FD_TYPE(DetectionResultWrapper, \
|
||||
results_wrapper_out[i])) = std::move(results_out[i]); \
|
||||
FD_C_DetectionResultWrapperToCResult(results_wrapper_out[i], &results->data[i]); \
|
||||
} \
|
||||
} \
|
||||
for (int i = 0; i < results_out.size(); i++) { \
|
||||
FD_C_DestroyDetectionResultWrapper(results_wrapper_out[i]); \
|
||||
}\
|
||||
return successful;
|
||||
|
||||
#define DECLARE_AND_IMPLEMENT_CREATE_WRAPPER_FUNCTION(model_type, var_name) FD_C_##model_type##Wrapper* FD_C_Create##model_type##Wrapper(\
|
||||
|
@@ -46,67 +46,6 @@ FD_C_Bool FD_C_PPYOLOEWrapperInitialized(
|
||||
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<FD_C_ResultType>(detection_result->masks[i].type);
|
||||
}
|
||||
fd_c_detection_result->contain_masks = detection_result->contain_masks;
|
||||
fd_c_detection_result->type =
|
||||
static_cast<FD_C_ResultType>(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) {
|
||||
|
Reference in New Issue
Block a user