mirror of
				https://github.com/PaddlePaddle/FastDeploy.git
				synced 2025-11-01 04:12:58 +08:00 
			
		
		
		
	[C API] Add create api for c results (#1547)
add create api for c results
This commit is contained in:
		| @@ -37,6 +37,11 @@ void FD_C_DestroyClassifyResultWrapper( | |||||||
|   delete fd_c_classify_result_wrapper; |   delete fd_c_classify_result_wrapper; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | FD_C_ClassifyResult* FD_C_CreateClassifyResult() { | ||||||
|  |   FD_C_ClassifyResult* fd_c_classify_result = new FD_C_ClassifyResult(); | ||||||
|  |   return fd_c_classify_result; | ||||||
|  | } | ||||||
|  |  | ||||||
| void FD_C_DestroyClassifyResult( | void FD_C_DestroyClassifyResult( | ||||||
|     __fd_take FD_C_ClassifyResult* fd_c_classify_result) { |     __fd_take FD_C_ClassifyResult* fd_c_classify_result) { | ||||||
|   if (fd_c_classify_result == nullptr) return; |   if (fd_c_classify_result == nullptr) return; | ||||||
| @@ -44,6 +49,7 @@ void FD_C_DestroyClassifyResult( | |||||||
|   delete[] fd_c_classify_result->label_ids.data; |   delete[] fd_c_classify_result->label_ids.data; | ||||||
|   // delete scores |   // delete scores | ||||||
|   delete[] fd_c_classify_result->scores.data; |   delete[] fd_c_classify_result->scores.data; | ||||||
|  |   delete fd_c_classify_result; | ||||||
| } | } | ||||||
|  |  | ||||||
| void FD_C_ClassifyResultWrapperToCResult( | void FD_C_ClassifyResultWrapperToCResult( | ||||||
| @@ -117,6 +123,11 @@ void FD_C_DestroyDetectionResultWrapper( | |||||||
|   delete fd_c_detection_result_wrapper; |   delete fd_c_detection_result_wrapper; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | FD_C_DetectionResult* FD_C_CreateDetectionResult() { | ||||||
|  |   FD_C_DetectionResult* fd_c_detection_result = new FD_C_DetectionResult(); | ||||||
|  |   return fd_c_detection_result; | ||||||
|  | } | ||||||
|  |  | ||||||
| void FD_C_DestroyDetectionResult( | void FD_C_DestroyDetectionResult( | ||||||
|     __fd_take FD_C_DetectionResult* fd_c_detection_result) { |     __fd_take FD_C_DetectionResult* fd_c_detection_result) { | ||||||
|   if (fd_c_detection_result == nullptr) return; |   if (fd_c_detection_result == nullptr) return; | ||||||
| @@ -134,6 +145,7 @@ void FD_C_DestroyDetectionResult( | |||||||
|     delete[] fd_c_detection_result->masks.data[i].data.data; |     delete[] fd_c_detection_result->masks.data[i].data.data; | ||||||
|     delete[] fd_c_detection_result->masks.data[i].shape.data; |     delete[] fd_c_detection_result->masks.data[i].shape.data; | ||||||
|   } |   } | ||||||
|  |   delete fd_c_detection_result; | ||||||
| } | } | ||||||
|  |  | ||||||
| void FD_C_DetectionResultWrapperToCResult( | void FD_C_DetectionResultWrapperToCResult( | ||||||
| @@ -275,6 +287,11 @@ void FD_C_DestroyOCRResultWrapper( | |||||||
|   delete fd_c_ocr_result_wrapper; |   delete fd_c_ocr_result_wrapper; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | FD_C_OCRResult* FD_C_CreateOCRResult() { | ||||||
|  |   FD_C_OCRResult* fd_c_ocr_result = new FD_C_OCRResult(); | ||||||
|  |   return fd_c_ocr_result; | ||||||
|  | } | ||||||
|  |  | ||||||
| void FD_C_DestroyOCRResult(__fd_take FD_C_OCRResult* fd_c_ocr_result) { | void FD_C_DestroyOCRResult(__fd_take FD_C_OCRResult* fd_c_ocr_result) { | ||||||
|   if (fd_c_ocr_result == nullptr) return; |   if (fd_c_ocr_result == nullptr) return; | ||||||
|   // delete boxes |   // delete boxes | ||||||
| @@ -293,6 +310,7 @@ void FD_C_DestroyOCRResult(__fd_take FD_C_OCRResult* fd_c_ocr_result) { | |||||||
|   delete[] fd_c_ocr_result->cls_scores.data; |   delete[] fd_c_ocr_result->cls_scores.data; | ||||||
|   // delete cls_labels |   // delete cls_labels | ||||||
|   delete[] fd_c_ocr_result->cls_labels.data; |   delete[] fd_c_ocr_result->cls_labels.data; | ||||||
|  |   delete fd_c_ocr_result; | ||||||
| } | } | ||||||
|  |  | ||||||
| void FD_C_OCRResultWrapperToCResult( | void FD_C_OCRResultWrapperToCResult( | ||||||
| @@ -418,6 +436,12 @@ void FD_C_DestroySegmentationResultWrapper( | |||||||
|   delete fd_c_segmentation_result_wrapper; |   delete fd_c_segmentation_result_wrapper; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | FD_C_SegmentationResult* FD_C_CreateSegmentationResult() { | ||||||
|  |   FD_C_SegmentationResult* fd_c_segmentation_result = | ||||||
|  |       new FD_C_SegmentationResult(); | ||||||
|  |   return fd_c_segmentation_result; | ||||||
|  | } | ||||||
|  |  | ||||||
| void FD_C_DestroySegmentationResult( | void FD_C_DestroySegmentationResult( | ||||||
|     __fd_take FD_C_SegmentationResult* fd_c_segmentation_result) { |     __fd_take FD_C_SegmentationResult* fd_c_segmentation_result) { | ||||||
|   if (fd_c_segmentation_result == nullptr) return; |   if (fd_c_segmentation_result == nullptr) return; | ||||||
| @@ -427,6 +451,7 @@ void FD_C_DestroySegmentationResult( | |||||||
|   delete[] fd_c_segmentation_result->score_map.data; |   delete[] fd_c_segmentation_result->score_map.data; | ||||||
|   // delete shape |   // delete shape | ||||||
|   delete[] fd_c_segmentation_result->shape.data; |   delete[] fd_c_segmentation_result->shape.data; | ||||||
|  |   delete fd_c_segmentation_result; | ||||||
| } | } | ||||||
|  |  | ||||||
| void FD_C_SegmentationResultWrapperToCResult( | void FD_C_SegmentationResultWrapperToCResult( | ||||||
|   | |||||||
| @@ -109,6 +109,13 @@ FD_C_CreateClassifyResultWrapper(); | |||||||
| FASTDEPLOY_CAPI_EXPORT extern void FD_C_DestroyClassifyResultWrapper( | FASTDEPLOY_CAPI_EXPORT extern void FD_C_DestroyClassifyResultWrapper( | ||||||
|     __fd_take FD_C_ClassifyResultWrapper* fd_c_classify_result_wrapper); |     __fd_take FD_C_ClassifyResultWrapper* fd_c_classify_result_wrapper); | ||||||
|  |  | ||||||
|  | /** \brief Create a new FD_C_ClassifyResult object | ||||||
|  |  * | ||||||
|  |  * \return Return a pointer to FD_C_ClassifyResult object | ||||||
|  |  */ | ||||||
|  | FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_ClassifyResult* | ||||||
|  | FD_C_CreateClassifyResult(); | ||||||
|  |  | ||||||
| /** \brief Destroy a FD_C_ClassifyResult object | /** \brief Destroy a FD_C_ClassifyResult object | ||||||
|  * |  * | ||||||
|  * \param[in] fd_c_classify_result pointer to FD_C_ClassifyResult object |  * \param[in] fd_c_classify_result pointer to FD_C_ClassifyResult object | ||||||
| @@ -159,6 +166,7 @@ FD_C_ClassifyResultStr( | |||||||
| FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_DetectionResultWrapper* | FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_DetectionResultWrapper* | ||||||
| FD_C_CreateDetectionResultWrapper(); | FD_C_CreateDetectionResultWrapper(); | ||||||
|  |  | ||||||
|  |  | ||||||
| /** \brief Destroy a FD_C_DetectionResultWrapper object | /** \brief Destroy a FD_C_DetectionResultWrapper object | ||||||
|  * |  * | ||||||
|  * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object |  * \param[in] fd_c_detection_result_wrapper pointer to FD_C_DetectionResultWrapper object | ||||||
| @@ -167,6 +175,14 @@ FD_C_CreateDetectionResultWrapper(); | |||||||
| FASTDEPLOY_CAPI_EXPORT extern void FD_C_DestroyDetectionResultWrapper( | FASTDEPLOY_CAPI_EXPORT extern void FD_C_DestroyDetectionResultWrapper( | ||||||
|     __fd_take FD_C_DetectionResultWrapper* fd_c_detection_result_wrapper); |     __fd_take FD_C_DetectionResultWrapper* fd_c_detection_result_wrapper); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** \brief Create a new FD_C_DetectionResult object | ||||||
|  |  * | ||||||
|  |  * \return Return a pointer to FD_C_DetectionResult object | ||||||
|  |  */ | ||||||
|  | FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_DetectionResult* | ||||||
|  | FD_C_CreateDetectionResult(); | ||||||
|  |  | ||||||
| /** \brief Destroy a FD_C_DetectionResult object | /** \brief Destroy a FD_C_DetectionResult object | ||||||
|  * |  * | ||||||
|  * \param[in] fd_c_detection_result pointer to FD_C_DetectionResult object |  * \param[in] fd_c_detection_result pointer to FD_C_DetectionResult object | ||||||
| @@ -225,6 +241,14 @@ FD_C_CreateOCRResultWrapper(); | |||||||
| FASTDEPLOY_CAPI_EXPORT extern void FD_C_DestroyOCRResultWrapper( | FASTDEPLOY_CAPI_EXPORT extern void FD_C_DestroyOCRResultWrapper( | ||||||
|     __fd_take FD_C_OCRResultWrapper* fd_c_ocr_result_wrapper); |     __fd_take FD_C_OCRResultWrapper* fd_c_ocr_result_wrapper); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** \brief Create a new FD_C_OCRResult object | ||||||
|  |  * | ||||||
|  |  * \return Return a pointer to FD_C_OCRResult object | ||||||
|  |  */ | ||||||
|  | FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_OCRResult* | ||||||
|  | FD_C_CreateOCRResult(); | ||||||
|  |  | ||||||
| /** \brief Destroy a FD_C_OCRResult object | /** \brief Destroy a FD_C_OCRResult object | ||||||
|  * |  * | ||||||
|  * \param[in] fd_c_ocr_result pointer to FD_C_OCRResult object |  * \param[in] fd_c_ocr_result pointer to FD_C_OCRResult object | ||||||
| @@ -282,6 +306,13 @@ FD_C_CreateSegmentationResultWrapper(); | |||||||
| FASTDEPLOY_CAPI_EXPORT extern void FD_C_DestroySegmentationResultWrapper( | FASTDEPLOY_CAPI_EXPORT extern void FD_C_DestroySegmentationResultWrapper( | ||||||
|     __fd_take FD_C_SegmentationResultWrapper* fd_c_segmentation_result_wrapper); |     __fd_take FD_C_SegmentationResultWrapper* fd_c_segmentation_result_wrapper); | ||||||
|  |  | ||||||
|  | /** \brief Create a new FD_C_SegmentationResult object | ||||||
|  |  * | ||||||
|  |  * \return Return a pointer to FD_C_SegmentationResult object | ||||||
|  |  */ | ||||||
|  | FASTDEPLOY_CAPI_EXPORT extern __fd_give FD_C_SegmentationResult* | ||||||
|  | FD_C_CreateSegmentationResult(); | ||||||
|  |  | ||||||
| /** \brief Destroy a FD_C_SegmentationResult object | /** \brief Destroy a FD_C_SegmentationResult object | ||||||
|  * |  * | ||||||
|  * \param[in] fd_c_segmentation_result pointer to FD_C_SegmentationResult object |  * \param[in] fd_c_segmentation_result pointer to FD_C_SegmentationResult object | ||||||
|   | |||||||
| @@ -49,8 +49,7 @@ void CpuInfer(const char* model_dir, const char* image_file) { | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_ClassifyResult* result = |   FD_C_ClassifyResult* result = FD_C_CreateClassifyResult(); | ||||||
|       (FD_C_ClassifyResult*)malloc(sizeof(FD_C_ClassifyResult)); |  | ||||||
|  |  | ||||||
|   if (!FD_C_PaddleClasModelWrapperPredict(model, im, result)) { |   if (!FD_C_PaddleClasModelWrapperPredict(model, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
| @@ -97,8 +96,7 @@ void GpuInfer(const char* model_dir, const char* image_file) { | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_ClassifyResult* result = |   FD_C_ClassifyResult* result = FD_C_CreateClassifyResult(); | ||||||
|       (FD_C_ClassifyResult*)malloc(sizeof(FD_C_ClassifyResult)); |  | ||||||
|  |  | ||||||
|   if (!FD_C_PaddleClasModelWrapperPredict(model, im, result)) { |   if (!FD_C_PaddleClasModelWrapperPredict(model, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
|   | |||||||
| @@ -47,8 +47,7 @@ void CpuInfer(const char* model_dir, const char* image_file) { | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_DetectionResult* result = |   FD_C_DetectionResult* result = FD_C_CreateDetectionResult(); | ||||||
|       (FD_C_DetectionResult*)malloc(sizeof(FD_C_DetectionResult)); |  | ||||||
|  |  | ||||||
|   if (!FD_C_PPYOLOEWrapperPredict(model, im, result)) { |   if (!FD_C_PPYOLOEWrapperPredict(model, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
| @@ -95,8 +94,7 @@ void GpuInfer(const char* model_dir, const char* image_file) { | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_DetectionResult* result = |   FD_C_DetectionResult* result = FD_C_CreateDetectionResult(); | ||||||
|       (FD_C_DetectionResult*)malloc(sizeof(FD_C_DetectionResult)); |  | ||||||
|  |  | ||||||
|   if (!FD_C_PPYOLOEWrapperPredict(model, im, result)) { |   if (!FD_C_PPYOLOEWrapperPredict(model, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
|   | |||||||
| @@ -39,8 +39,7 @@ void CpuInfer(const char* model_file, const char* image_file) { | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_DetectionResult* result = |   FD_C_DetectionResult* result = FD_C_CreateDetectionResult(); | ||||||
|       (FD_C_DetectionResult*)malloc(sizeof(FD_C_DetectionResult)); |  | ||||||
|  |  | ||||||
|   if (!FD_C_YOLOv5WrapperPredict(model, im, result)) { |   if (!FD_C_YOLOv5WrapperPredict(model, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
| @@ -79,8 +78,7 @@ void GpuInfer(const char* model_file, const char* image_file) { | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_DetectionResult* result = |   FD_C_DetectionResult* result = FD_C_CreateDetectionResult(); | ||||||
|       (FD_C_DetectionResult*)malloc(sizeof(FD_C_DetectionResult)); |  | ||||||
|  |  | ||||||
|   if (!FD_C_YOLOv5WrapperPredict(model, im, result)) { |   if (!FD_C_YOLOv5WrapperPredict(model, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
|   | |||||||
| @@ -96,7 +96,7 @@ void CpuInfer(const char* det_model_dir, const char* cls_model_dir, | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_OCRResult* result = (FD_C_OCRResult*)malloc(sizeof(FD_C_OCRResult)); |   FD_C_OCRResult* result = FD_C_CreateOCRResult(); | ||||||
|  |  | ||||||
|   if (!FD_C_PPOCRv2WrapperPredict(ppocr_v2, im, result)) { |   if (!FD_C_PPOCRv2WrapperPredict(ppocr_v2, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
| @@ -191,7 +191,7 @@ void GpuInfer(const char* det_model_dir, const char* cls_model_dir, | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_OCRResult* result = (FD_C_OCRResult*)malloc(sizeof(FD_C_OCRResult)); |   FD_C_OCRResult* result = FD_C_CreateOCRResult(); | ||||||
|  |  | ||||||
|   if (!FD_C_PPOCRv2WrapperPredict(ppocr_v2, im, result)) { |   if (!FD_C_PPOCRv2WrapperPredict(ppocr_v2, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
|   | |||||||
| @@ -96,7 +96,7 @@ void CpuInfer(const char* det_model_dir, const char* cls_model_dir, | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_OCRResult* result = (FD_C_OCRResult*)malloc(sizeof(FD_C_OCRResult)); |   FD_C_OCRResult* result = FD_C_CreateOCRResult(); | ||||||
|  |  | ||||||
|   if (!FD_C_PPOCRv3WrapperPredict(ppocr_v3, im, result)) { |   if (!FD_C_PPOCRv3WrapperPredict(ppocr_v3, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
| @@ -191,7 +191,7 @@ void GpuInfer(const char* det_model_dir, const char* cls_model_dir, | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_OCRResult* result = (FD_C_OCRResult*)malloc(sizeof(FD_C_OCRResult)); |   FD_C_OCRResult* result = FD_C_CreateOCRResult(); | ||||||
|  |  | ||||||
|   if (!FD_C_PPOCRv3WrapperPredict(ppocr_v3, im, result)) { |   if (!FD_C_PPOCRv3WrapperPredict(ppocr_v3, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
|   | |||||||
| @@ -47,8 +47,7 @@ void CpuInfer(const char* model_dir, const char* image_file) { | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_SegmentationResult* result = |   FD_C_SegmentationResult* result = FD_C_CreateSegmentationResult(); | ||||||
|       (FD_C_SegmentationResult*)malloc(sizeof(FD_C_SegmentationResult)); |  | ||||||
|  |  | ||||||
|   if (!FD_C_PaddleSegModelWrapperPredict(model, im, result)) { |   if (!FD_C_PaddleSegModelWrapperPredict(model, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
| @@ -99,8 +98,7 @@ void GpuInfer(const char* model_dir, const char* image_file) { | |||||||
|  |  | ||||||
|   FD_C_Mat im = FD_C_Imread(image_file); |   FD_C_Mat im = FD_C_Imread(image_file); | ||||||
|  |  | ||||||
|   FD_C_SegmentationResult* result = |   FD_C_SegmentationResult* result = FD_C_CreateSegmentationResult(); | ||||||
|       (FD_C_SegmentationResult*)malloc(sizeof(FD_C_SegmentationResult)); |  | ||||||
|  |  | ||||||
|   if (!FD_C_PaddleSegModelWrapperPredict(model, im, result)) { |   if (!FD_C_PaddleSegModelWrapperPredict(model, im, result)) { | ||||||
|     printf("Failed to predict.\n"); |     printf("Failed to predict.\n"); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 chenjian
					chenjian