diff --git a/3rdparty/bin/ON.dll b/3rdparty/bin/ON.dll new file mode 100644 index 0000000000..5b53df82ae Binary files /dev/null and b/3rdparty/bin/ON.dll differ diff --git a/3rdparty/bin/onnxruntime.dll b/3rdparty/bin/onnxruntime.dll new file mode 100644 index 0000000000..ac89344ab3 Binary files /dev/null and b/3rdparty/bin/onnxruntime.dll differ diff --git a/3rdparty/bin/onnxruntime_providers_shared.dll b/3rdparty/bin/onnxruntime_providers_shared.dll new file mode 100644 index 0000000000..0891d54e9a Binary files /dev/null and b/3rdparty/bin/onnxruntime_providers_shared.dll differ diff --git a/3rdparty/bin/paddle2onnx.dll b/3rdparty/bin/paddle2onnx.dll new file mode 100644 index 0000000000..7753c14713 Binary files /dev/null and b/3rdparty/bin/paddle2onnx.dll differ diff --git a/3rdparty/bin/yaml-cpp.dll b/3rdparty/bin/yaml-cpp.dll new file mode 100644 index 0000000000..5feb9aba87 Binary files /dev/null and b/3rdparty/bin/yaml-cpp.dll differ diff --git a/3rdparty/include/fastdeploy/core/config.h b/3rdparty/include/fastdeploy/core/config.h index e587d97df8..c872e37ddc 100644 --- a/3rdparty/include/fastdeploy/core/config.h +++ b/3rdparty/include/fastdeploy/core/config.h @@ -26,7 +26,7 @@ #endif #ifndef ENABLE_PADDLE_BACKEND -#define ENABLE_PADDLE_BACKEND +/* #undef ENABLE_PADDLE_BACKEND */ #endif #ifndef ENABLE_POROS_BACKEND @@ -34,7 +34,7 @@ #endif #ifndef ENABLE_OPENVINO_BACKEND -#define ENABLE_OPENVINO_BACKEND +/* #undef ENABLE_OPENVINO_BACKEND */ #endif #ifndef WITH_GPU @@ -54,7 +54,7 @@ #endif #ifndef ENABLE_TEXT -#define ENABLE_TEXT +/* #undef ENABLE_TEXT */ #endif #ifndef ENABLE_OPENCV_CUDA @@ -68,5 +68,5 @@ #endif #ifndef ENABLE_FDTENSOR_FUNC -#define ENABLE_FDTENSOR_FUNC +/* #undef ENABLE_FDTENSOR_FUNC */ #endif diff --git a/3rdparty/include/fastdeploy/core/fd_tensor.h b/3rdparty/include/fastdeploy/core/fd_tensor.h index 7deb482298..6a86bba1b7 100644 --- a/3rdparty/include/fastdeploy/core/fd_tensor.h +++ b/3rdparty/include/fastdeploy/core/fd_tensor.h @@ -57,9 +57,7 @@ struct FASTDEPLOY_DECL FDTensor { void* Data(); - bool IsShared() { - return external_data_ptr != nullptr; - } + bool IsShared() { return external_data_ptr != nullptr; } void StopSharing(); @@ -116,6 +114,7 @@ struct FASTDEPLOY_DECL FDTensor { const FDDataType& data_type, const std::string& tensor_name = "", const Device& new_device = Device::CPU); + bool Reshape(const std::vector& new_shape); // Debug function // Use this function to print shape, dtype, mean, max, min // prefix will also be printed as tag @@ -141,7 +140,7 @@ struct FASTDEPLOY_DECL FDTensor { static void CopyBuffer(void* dst, const void* src, size_t nbytes, const Device& device = Device::CPU, - bool is_pinned_memory = false); + bool is_pinned_memory = false); }; } // namespace fastdeploy diff --git a/3rdparty/include/fastdeploy/runtime.h b/3rdparty/include/fastdeploy/runtime.h index 8822308ec7..6ea5840268 100644 --- a/3rdparty/include/fastdeploy/runtime.h +++ b/3rdparty/include/fastdeploy/runtime.h @@ -168,6 +168,26 @@ struct FASTDEPLOY_DECL RuntimeOption { */ void SetPaddleMKLDNNCacheSize(int size); + /** + * @brief Set device name for OpenVINO, default 'CPU', can also be 'AUTO', 'GPU', 'GPU.1'.... + */ + void SetOpenVINODevice(const std::string& name = "CPU"); + + /** + * @brief Set shape info for OpenVINO + */ + void SetOpenVINOShapeInfo( + const std::map>& shape_info) { + ov_shape_infos = shape_info; + } + + /** + * @brief While use OpenVINO backend with intel GPU, use this interface to specify operators run on CPU + */ + void SetOpenVINOCpuOperators(const std::vector& operators) { + ov_cpu_operators = operators; + } + /** * @brief Set optimzed model dir for Paddle Lite backend. */ @@ -352,7 +372,10 @@ struct FASTDEPLOY_DECL RuntimeOption { std::string poros_file = ""; // ======Only for OpenVINO Backend======= - int ov_num_streams = 1; + int ov_num_streams = 0; + std::string openvino_device = "CPU"; + std::map> ov_shape_infos; + std::vector ov_cpu_operators; // ======Only for RKNPU2 Backend======= fastdeploy::rknpu2::CpuName rknpu2_cpu_name_ diff --git a/3rdparty/include/fastdeploy/utils/utils.h b/3rdparty/include/fastdeploy/utils/utils.h index 2c72697634..9e41c6e250 100644 --- a/3rdparty/include/fastdeploy/utils/utils.h +++ b/3rdparty/include/fastdeploy/utils/utils.h @@ -14,15 +14,21 @@ #pragma once -#include #include +#include #include #include +#include #include #include +#include #include +#ifdef __ANDROID__ +#include // NOLINT +#endif + #if defined(_WIN32) #ifdef FASTDEPLOY_LIB #define FASTDEPLOY_DECL __declspec(dllexport) @@ -44,8 +50,7 @@ class FASTDEPLOY_DECL FDLogger { } explicit FDLogger(bool verbose, const std::string& prefix = "[FastDeploy]"); - template - FDLogger& operator<<(const T& val) { + template FDLogger& operator<<(const T& val) { if (!verbose_) { return *this; } @@ -54,10 +59,15 @@ class FASTDEPLOY_DECL FDLogger { line_ += ss.str(); return *this; } + FDLogger& operator<<(std::ostream& (*os)(std::ostream&)); + ~FDLogger() { if (!verbose_ && line_ != "") { std::cout << line_ << std::endl; +#ifdef __ANDROID__ + __android_log_print(ANDROID_LOG_INFO, prefix_.c_str(), "%s", line_.c_str()); +#endif } } @@ -74,37 +84,37 @@ FASTDEPLOY_DECL bool ReadBinaryFromFile(const std::string& file, #define __REL_FILE__ __FILE__ #endif -#define FDERROR \ - FDLogger(true, "[ERROR]") << __REL_FILE__ << "(" << __LINE__ \ - << ")::" << __FUNCTION__ << "\t" +#define FDERROR \ + FDLogger(true, "[ERROR]") \ + << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t" -#define FDWARNING \ - FDLogger(true, "[WARNING]") << __REL_FILE__ << "(" << __LINE__ \ - << ")::" << __FUNCTION__ << "\t" +#define FDWARNING \ + FDLogger(true, "[WARNING]") \ + << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t" -#define FDINFO \ - FDLogger(true, "[INFO]") << __REL_FILE__ << "(" << __LINE__ \ +#define FDINFO \ + FDLogger(true, "[INFO]") << __REL_FILE__ << "(" << __LINE__ \ << ")::" << __FUNCTION__ << "\t" -#define FDASSERT(condition, format, ...) \ - if (!(condition)) { \ - int n = std::snprintf(nullptr, 0, format, ##__VA_ARGS__); \ - std::vector buffer(n + 1); \ - std::snprintf(buffer.data(), n + 1, format, ##__VA_ARGS__); \ - FDERROR << buffer.data() << std::endl; \ - std::abort(); \ +#define FDASSERT(condition, format, ...) \ + if (!(condition)) { \ + int n = std::snprintf(nullptr, 0, format, ##__VA_ARGS__); \ + std::vector buffer(n + 1); \ + std::snprintf(buffer.data(), n + 1, format, ##__VA_ARGS__); \ + FDERROR << buffer.data() << std::endl; \ + std::abort(); \ } ///////// Basic Marco /////////// -#define FD_PRIVATE_CASE_TYPE_USING_HINT(NAME, enum_type, type, HINT, ...) \ - case enum_type: { \ - using HINT = type; \ - __VA_ARGS__(); \ - break; \ +#define FD_PRIVATE_CASE_TYPE_USING_HINT(NAME, enum_type, type, HINT, ...) \ + case enum_type: { \ + using HINT = type; \ + __VA_ARGS__(); \ + break; \ } -#define FD_PRIVATE_CASE_TYPE(NAME, enum_type, type, ...) \ +#define FD_PRIVATE_CASE_TYPE(NAME, enum_type, type, ...) \ FD_PRIVATE_CASE_TYPE_USING_HINT(NAME, enum_type, type, data_t, __VA_ARGS__) // Visit different data type to match the corresponding function of FDTensor @@ -122,68 +132,80 @@ FASTDEPLOY_DECL bool ReadBinaryFromFile(const std::string& file, __VA_ARGS__) \ FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \ __VA_ARGS__) \ - default: \ - FDASSERT( \ - false, \ - "Invalid enum data type. Expect to accept data type BOOL, INT32, " \ - "INT64, FP32, FP64, but receive type %s.", \ - Str(__dtype__).c_str()); \ + default: \ + FDASSERT(false, \ + "Invalid enum data type. Expect to accept data " \ + "type BOOL, INT32, " \ + "INT64, FP32, FP64, but receive type %s.", \ + Str(__dtype__).c_str()); \ } \ }() -#define FD_VISIT_INT_FLOAT_TYPES(TYPE, NAME, ...) \ - [&] { \ - const auto& __dtype__ = TYPE; \ - switch (__dtype__) { \ - FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT32, int32_t, \ - __VA_ARGS__) \ - FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT64, int64_t, \ - __VA_ARGS__) \ - FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP32, float, \ - __VA_ARGS__) \ - FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \ - __VA_ARGS__) \ - default: \ - FDASSERT(false, \ - "Invalid enum data type. Expect to accept data type INT32, " \ - "INT64, FP32, FP64, but receive type %s.", \ - Str(__dtype__).c_str()); \ - } \ +#define FD_VISIT_INT_FLOAT_TYPES(TYPE, NAME, ...) \ + [&] { \ + const auto& __dtype__ = TYPE; \ + switch (__dtype__) { \ + FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT32, int32_t, \ + __VA_ARGS__) \ + FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT64, int64_t, \ + __VA_ARGS__) \ + FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP32, float, \ + __VA_ARGS__) \ + FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \ + __VA_ARGS__) \ + default: \ + FDASSERT(false, \ + "Invalid enum data type. Expect to accept data type INT32, " \ + "INT64, FP32, FP64, but receive type %s.", \ + Str(__dtype__).c_str()); \ + } \ }() -#define FD_VISIT_FLOAT_TYPES(TYPE, NAME, ...) \ - [&] { \ - const auto& __dtype__ = TYPE; \ - switch (__dtype__) { \ - FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP32, float, \ - __VA_ARGS__) \ - FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \ - __VA_ARGS__) \ - default: \ - FDASSERT(false, \ - "Invalid enum data type. Expect to accept data type FP32, " \ - "FP64, but receive type %s.", \ - Str(__dtype__).c_str()); \ - } \ +#define FD_VISIT_FLOAT_TYPES(TYPE, NAME, ...) \ + [&] { \ + const auto& __dtype__ = TYPE; \ + switch (__dtype__) { \ + FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP32, float, \ + __VA_ARGS__) \ + FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \ + __VA_ARGS__) \ + default: \ + FDASSERT(false, \ + "Invalid enum data type. Expect to accept data type FP32, " \ + "FP64, but receive type %s.", \ + Str(__dtype__).c_str()); \ + } \ }() -#define FD_VISIT_INT_TYPES(TYPE, NAME, ...) \ - [&] { \ - const auto& __dtype__ = TYPE; \ - switch (__dtype__) { \ - FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT32, int32_t, \ - __VA_ARGS__) \ - FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT64, int64_t, \ - __VA_ARGS__) \ - default: \ - FDASSERT(false, \ - "Invalid enum data type. Expect to accept data type INT32, " \ - "INT64, but receive type %s.", \ - Str(__dtype__).c_str()); \ - } \ +#define FD_VISIT_INT_TYPES(TYPE, NAME, ...) \ + [&] { \ + const auto& __dtype__ = TYPE; \ + switch (__dtype__) { \ + FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT32, int32_t, \ + __VA_ARGS__) \ + FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT64, int64_t, \ + __VA_ARGS__) \ + default: \ + FDASSERT(false, \ + "Invalid enum data type. Expect to accept data type INT32, " \ + "INT64, but receive type %s.", \ + Str(__dtype__).c_str()); \ + } \ }() -FASTDEPLOY_DECL std::vector GetStride( - const std::vector& dims); +FASTDEPLOY_DECL std::vector +GetStride(const std::vector& dims); + +template ::value, + bool>::type = true> +std::string Str(const std::vector& shape) { + std::ostringstream oss; + oss << "[ " << shape[0]; + for (int i = 1; i < shape.size(); ++i) { + oss << " ," << shape[i]; + } + oss << " ]"; + return oss.str(); +} } // namespace fastdeploy diff --git a/3rdparty/include/fastdeploy/vision.h b/3rdparty/include/fastdeploy/vision.h index 2f8c706613..9bea1550e4 100644 --- a/3rdparty/include/fastdeploy/vision.h +++ b/3rdparty/include/fastdeploy/vision.h @@ -15,31 +15,34 @@ #include "fastdeploy/core/config.h" #ifdef ENABLE_VISION +#include "fastdeploy/vision/classification/contrib/resnet.h" #include "fastdeploy/vision/classification/contrib/yolov5cls.h" #include "fastdeploy/vision/classification/ppcls/model.h" -#include "fastdeploy/vision/classification/contrib/resnet.h" #include "fastdeploy/vision/detection/contrib/nanodet_plus.h" #include "fastdeploy/vision/detection/contrib/scaledyolov4.h" #include "fastdeploy/vision/detection/contrib/yolor.h" #include "fastdeploy/vision/detection/contrib/yolov5/yolov5.h" #include "fastdeploy/vision/detection/contrib/yolov5lite.h" #include "fastdeploy/vision/detection/contrib/yolov6.h" -#include "fastdeploy/vision/detection/contrib/yolov7.h" +#include "fastdeploy/vision/detection/contrib/yolov7/yolov7.h" #include "fastdeploy/vision/detection/contrib/yolov7end2end_ort.h" #include "fastdeploy/vision/detection/contrib/yolov7end2end_trt.h" #include "fastdeploy/vision/detection/contrib/yolox.h" #include "fastdeploy/vision/detection/ppdet/model.h" +#include "fastdeploy/vision/facealign/contrib/face_landmark_1000.h" +#include "fastdeploy/vision/facealign/contrib/pfld.h" +#include "fastdeploy/vision/facealign/contrib/pipnet.h" #include "fastdeploy/vision/facedet/contrib/retinaface.h" #include "fastdeploy/vision/facedet/contrib/scrfd.h" #include "fastdeploy/vision/facedet/contrib/ultraface.h" #include "fastdeploy/vision/facedet/contrib/yolov5face.h" -#include "fastdeploy/vision/facealign/contrib/pfld.h" #include "fastdeploy/vision/faceid/contrib/adaface.h" #include "fastdeploy/vision/faceid/contrib/arcface.h" #include "fastdeploy/vision/faceid/contrib/cosface.h" #include "fastdeploy/vision/faceid/contrib/insightface_rec.h" #include "fastdeploy/vision/faceid/contrib/partial_fc.h" #include "fastdeploy/vision/faceid/contrib/vpl.h" +#include "fastdeploy/vision/headpose/contrib/fsanet.h" #include "fastdeploy/vision/keypointdet/pptinypose/pptinypose.h" #include "fastdeploy/vision/matting/contrib/modnet.h" #include "fastdeploy/vision/matting/contrib/rvm.h" @@ -49,9 +52,11 @@ #include "fastdeploy/vision/ocr/ppocr/ppocr_v2.h" #include "fastdeploy/vision/ocr/ppocr/ppocr_v3.h" #include "fastdeploy/vision/ocr/ppocr/recognizer.h" +#include "fastdeploy/vision/ocr/ppocr/utils/ocr_utils.h" #include "fastdeploy/vision/segmentation/ppseg/model.h" +#include "fastdeploy/vision/sr/ppsr/model.h" #include "fastdeploy/vision/tracking/pptracking/model.h" -#include "fastdeploy/vision/headpose/contrib/fsanet.h" + #endif #include "fastdeploy/vision/visualize/visualize.h" diff --git a/3rdparty/include/fastdeploy/vision/common/processors/base.h b/3rdparty/include/fastdeploy/vision/common/processors/base.h index c833ef8a37..00bd9c82ff 100644 --- a/3rdparty/include/fastdeploy/vision/common/processors/base.h +++ b/3rdparty/include/fastdeploy/vision/common/processors/base.h @@ -32,8 +32,7 @@ FASTDEPLOY_DECL void EnableFlyCV(); /// Disable using FlyCV to process image while deploy vision models. FASTDEPLOY_DECL void DisableFlyCV(); -/*! @brief Set the cpu num threads of ProcLib. The cpu num threads - * of FlyCV and OpenCV is 2 by default. +/*! @brief Set the cpu num threads of ProcLib. */ FASTDEPLOY_DECL void SetProcLibCpuNumThreads(int threads); diff --git a/3rdparty/include/fastdeploy/vision/common/processors/color_space_convert.h b/3rdparty/include/fastdeploy/vision/common/processors/color_space_convert.h index e090bc62d5..490034868f 100644 --- a/3rdparty/include/fastdeploy/vision/common/processors/color_space_convert.h +++ b/3rdparty/include/fastdeploy/vision/common/processors/color_space_convert.h @@ -21,24 +21,48 @@ namespace vision { class FASTDEPLOY_DECL BGR2RGB : public Processor { public: - bool ImplByOpenCV(Mat* mat); + bool ImplByOpenCV(FDMat* mat); #ifdef ENABLE_FLYCV - bool ImplByFlyCV(Mat* mat); + bool ImplByFlyCV(FDMat* mat); #endif virtual std::string Name() { return "BGR2RGB"; } - static bool Run(Mat* mat, ProcLib lib = ProcLib::DEFAULT); + static bool Run(FDMat* mat, ProcLib lib = ProcLib::DEFAULT); }; class FASTDEPLOY_DECL RGB2BGR : public Processor { public: - bool ImplByOpenCV(Mat* mat); + bool ImplByOpenCV(FDMat* mat); #ifdef ENABLE_FLYCV - bool ImplByFlyCV(Mat* mat); + bool ImplByFlyCV(FDMat* mat); #endif std::string Name() { return "RGB2BGR"; } - static bool Run(Mat* mat, ProcLib lib = ProcLib::DEFAULT); + static bool Run(FDMat* mat, ProcLib lib = ProcLib::DEFAULT); }; + +class FASTDEPLOY_DECL BGR2GRAY : public Processor { + public: + bool ImplByOpenCV(FDMat* mat); +#ifdef ENABLE_FLYCV + bool ImplByFlyCV(FDMat* mat); +#endif + virtual std::string Name() { return "BGR2GRAY"; } + + static bool Run(FDMat* mat, ProcLib lib = ProcLib::DEFAULT); +}; + +class FASTDEPLOY_DECL RGB2GRAY : public Processor { + public: + bool ImplByOpenCV(FDMat* mat); +#ifdef ENABLE_FLYCV + bool ImplByFlyCV(FDMat* mat); +#endif + std::string Name() { return "RGB2GRAY"; } + + static bool Run(FDMat* mat, ProcLib lib = ProcLib::DEFAULT); +}; + + } // namespace vision } // namespace fastdeploy diff --git a/3rdparty/include/fastdeploy/vision/common/processors/transform.h b/3rdparty/include/fastdeploy/vision/common/processors/transform.h index e3f7146365..ce7612a378 100644 --- a/3rdparty/include/fastdeploy/vision/common/processors/transform.h +++ b/3rdparty/include/fastdeploy/vision/common/processors/transform.h @@ -37,7 +37,6 @@ namespace fastdeploy { namespace vision { void FuseTransforms(std::vector>* processors); - // Fuse Normalize + Cast(Float) to Normalize void FuseNormalizeCast(std::vector>* processors); // Fuse Normalize + HWC2CHW to NormalizeAndPermute diff --git a/3rdparty/include/fastdeploy/vision/common/result.h b/3rdparty/include/fastdeploy/vision/common/result.h index 59690ab6d8..2fd3d72dd9 100644 --- a/3rdparty/include/fastdeploy/vision/common/result.h +++ b/3rdparty/include/fastdeploy/vision/common/result.h @@ -95,6 +95,7 @@ struct FASTDEPLOY_DECL Mask : public BaseResult { /*! @brief Detection result structure for all the object detection models and instance segmentation models */ struct FASTDEPLOY_DECL DetectionResult : public BaseResult { + DetectionResult() = default; /** \brief All the detected object boxes for an input image, the size of `boxes` is the number of detected objects, and the element of `boxes` is a array of 4 float values, means [xmin, ymin, xmax, ymax] */ std::vector> boxes; @@ -111,8 +112,10 @@ struct FASTDEPLOY_DECL DetectionResult : public BaseResult { ResultType type = ResultType::DETECTION; - DetectionResult() {} + /// Copy constructor DetectionResult(const DetectionResult& res); + /// Move assignment + DetectionResult& operator=(DetectionResult&& other); /// Clear detection result void Clear(); @@ -313,9 +316,12 @@ struct FASTDEPLOY_DECL MattingResult : public BaseResult { MattingResult() {} MattingResult(const MattingResult& res); - /// Clear detection result + /// Clear matting result void Clear(); + /// Free matting result + void Free(); + void Reserve(int size); void Resize(int size); diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/classifier.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/classifier.h index d87fec6fa6..d3430e4e02 100644 --- a/3rdparty/include/fastdeploy/vision/ocr/ppocr/classifier.h +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/classifier.h @@ -17,6 +17,8 @@ #include "fastdeploy/vision/common/processors/transform.h" #include "fastdeploy/vision/common/result.h" #include "fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h" +#include "fastdeploy/vision/ocr/ppocr/cls_postprocessor.h" +#include "fastdeploy/vision/ocr/ppocr/cls_preprocessor.h" namespace fastdeploy { namespace vision { @@ -41,29 +43,22 @@ class FASTDEPLOY_DECL Classifier : public FastDeployModel { const ModelFormat& model_format = ModelFormat::PADDLE); /// Get model's name std::string ModelName() const { return "ppocr/ocr_cls"; } - /** \brief Predict the input image and get OCR classification model result. + + /** \brief BatchPredict the input image and get OCR classification model cls_result. * - * \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 output of OCR classification model result will be writen to this structure. + * \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. + * \param[in] cls_results The output of OCR classification model cls_result will be writen to this structure. * \return true if the prediction is successed, otherwise false. */ - virtual bool Predict(cv::Mat* img, std::tuple* result); + virtual bool BatchPredict(const std::vector& images, + std::vector* cls_labels, + std::vector* cls_scores); - // Pre & Post parameters - float cls_thresh; - std::vector cls_image_shape; - int cls_batch_num; - - std::vector mean; - std::vector scale; - bool is_scale; + ClassifierPreprocessor preprocessor_; + ClassifierPostprocessor postprocessor_; private: bool Initialize(); - /// Preprocess the input data, and set the preprocessed results to `outputs` - bool Preprocess(Mat* img, FDTensor* output); - /// Postprocess the inferenced results, and set the final result to `result` - bool Postprocess(FDTensor& infer_result, std::tuple* result); }; } // namespace ocr diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h new file mode 100644 index 0000000000..15bf098c70 --- /dev/null +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/cls_postprocessor.h @@ -0,0 +1,51 @@ +// Copyright (c) 2022 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 +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" +#include "fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h" + +namespace fastdeploy { +namespace vision { + +namespace ocr { +/*! @brief Postprocessor object for Classifier serials model. + */ +class FASTDEPLOY_DECL ClassifierPostprocessor { + public: + /** \brief Create a postprocessor instance for Classifier serials model + * + */ + ClassifierPostprocessor(); + + /** \brief Process the result of runtime and fill to ClassifyResult structure + * + * \param[in] tensors The inference result from runtime + * \param[in] cls_labels The output result of classification + * \param[in] cls_scores The output result of classification + * \return true if the postprocess successed, otherwise false + */ + bool Run(const std::vector& tensors, + std::vector* cls_labels, std::vector* cls_scores); + + float cls_thresh_ = 0.9; + + private: + bool initialized_ = false; +}; + +} // namespace ocr +} // namespace vision +} // namespace fastdeploy diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h new file mode 100644 index 0000000000..a701e7e3ae --- /dev/null +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/cls_preprocessor.h @@ -0,0 +1,51 @@ +// Copyright (c) 2022 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 +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" + +namespace fastdeploy { +namespace vision { + +namespace ocr { +/*! @brief Preprocessor object for Classifier serials model. + */ +class FASTDEPLOY_DECL ClassifierPreprocessor { + public: + /** \brief Create a preprocessor instance for Classifier serials model + * + */ + ClassifierPreprocessor(); + + /** \brief Process the input image and prepare input tensors for runtime + * + * \param[in] images The input image data list, all the elements are returned by cv::imread() + * \param[in] outputs The output tensors which will feed in runtime + * \return true if the preprocess successed, otherwise false + */ + bool Run(std::vector* images, std::vector* outputs); + + std::vector mean_ = {0.5f, 0.5f, 0.5f}; + std::vector scale_ = {0.5f, 0.5f, 0.5f}; + bool is_scale_ = true; + std::vector cls_image_shape_ = {3, 48, 192}; + + private: + bool initialized_ = false; +}; + +} // namespace ocr +} // namespace vision +} // namespace fastdeploy diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/dbdetector.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/dbdetector.h index e0baf319cb..d3b99d598f 100644 --- a/3rdparty/include/fastdeploy/vision/ocr/ppocr/dbdetector.h +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/dbdetector.h @@ -17,6 +17,8 @@ #include "fastdeploy/vision/common/processors/transform.h" #include "fastdeploy/vision/common/result.h" #include "fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h" +#include "fastdeploy/vision/ocr/ppocr/det_postprocessor.h" +#include "fastdeploy/vision/ocr/ppocr/det_preprocessor.h" namespace fastdeploy { namespace vision { @@ -44,40 +46,34 @@ class FASTDEPLOY_DECL DBDetector : public FastDeployModel { std::string ModelName() const { return "ppocr/ocr_det"; } /** \brief Predict the input image and get OCR detection model result. * - * \param[in] im The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. + * \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. * \param[in] boxes_result The output of OCR detection model result will be writen to this structure. * \return true if the prediction is successed, otherwise false. */ - virtual bool Predict(cv::Mat* im, + virtual bool Predict(cv::Mat* img, std::vector>* boxes_result); + /** \brief Predict the input image and get OCR detection model result. + * + * \param[in] img The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. + * \param[in] boxes_result The output of OCR detection model result will be writen to this structure. + * \return true if the prediction is successed, otherwise false. + */ + virtual bool Predict(const cv::Mat& img, + std::vector>* boxes_result); + /** \brief BatchPredict the input image and get OCR detection model result. + * + * \param[in] images The list input of image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. + * \param[in] det_results The output of OCR detection model result will be writen to this structure. + * \return true if the prediction is successed, otherwise false. + */ + virtual bool BatchPredict(const std::vector& images, + std::vector>>* det_results); - // Pre & Post process parameters - int max_side_len; - - float ratio_h{}; - float ratio_w{}; - - double det_db_thresh; - double det_db_box_thresh; - double det_db_unclip_ratio; - std::string det_db_score_mode; - bool use_dilation; - - std::vector mean; - std::vector scale; - bool is_scale; + DBDetectorPreprocessor preprocessor_; + DBDetectorPostprocessor postprocessor_; private: bool Initialize(); - /// Preprocess the input data, and set the preprocessed results to `outputs` - bool Preprocess(Mat* mat, FDTensor* outputs, - std::map>* im_info); - /*! @brief Postprocess the inferenced results, and set the final result to `boxes_result` - */ - bool Postprocess(FDTensor& infer_result, - std::vector>* boxes_result, - const std::map>& im_info); - PostProcessor post_processor_; }; } // namespace ocr diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/det_postprocessor.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/det_postprocessor.h new file mode 100644 index 0000000000..f98b89b028 --- /dev/null +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/det_postprocessor.h @@ -0,0 +1,62 @@ +// Copyright (c) 2022 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 +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" +#include "fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h" + +namespace fastdeploy { +namespace vision { + +namespace ocr { +/*! @brief Postprocessor object for DBDetector serials model. + */ +class FASTDEPLOY_DECL DBDetectorPostprocessor { + public: + /** \brief Create a postprocessor instance for DBDetector serials model + * + */ + DBDetectorPostprocessor(); + + /** \brief Process the result of runtime and fill to results structure + * + * \param[in] tensors The inference result from runtime + * \param[in] results The output result of detector + * \param[in] batch_det_img_info The detector_preprocess result + * \return true if the postprocess successed, otherwise false + */ + bool Run(const std::vector& tensors, + std::vector>>* results, + const std::vector>& batch_det_img_info); + + double det_db_thresh_ = 0.3; + double det_db_box_thresh_ = 0.6; + double det_db_unclip_ratio_ = 1.5; + std::string det_db_score_mode_ = "slow"; + bool use_dilation_ = false; + + private: + bool initialized_ = false; + PostProcessor post_processor_; + bool SingleBatchPostprocessor(const float* out_data, + int n2, + int n3, + const std::array& det_img_info, + std::vector>* boxes_result); +}; + +} // namespace ocr +} // namespace vision +} // namespace fastdeploy diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/det_preprocessor.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/det_preprocessor.h new file mode 100644 index 0000000000..39c48691d7 --- /dev/null +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/det_preprocessor.h @@ -0,0 +1,54 @@ +// Copyright (c) 2022 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 +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" + +namespace fastdeploy { +namespace vision { + +namespace ocr { +/*! @brief Preprocessor object for DBDetector serials model. + */ +class FASTDEPLOY_DECL DBDetectorPreprocessor { + public: + /** \brief Create a preprocessor instance for DBDetector serials model + * + */ + DBDetectorPreprocessor(); + + /** \brief Process the input image and prepare input tensors for runtime + * + * \param[in] images The input image data list, all the elements are returned by cv::imread() + * \param[in] outputs The output tensors which will feed in runtime + * \param[in] batch_det_img_info_ptr The output of preprocess + * \return true if the preprocess successed, otherwise false + */ + bool Run(std::vector* images, + std::vector* outputs, + std::vector>* batch_det_img_info_ptr); + + int max_side_len_ = 960; + std::vector mean_ = {0.485f, 0.456f, 0.406f}; + std::vector scale_ = {0.229f, 0.224f, 0.225f}; + bool is_scale_ = true; + + private: + bool initialized_ = false; +}; + +} // namespace ocr +} // namespace vision +} // namespace fastdeploy diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/ppocr_v2.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/ppocr_v2.h index bf53000202..d021d6c32d 100644 --- a/3rdparty/include/fastdeploy/vision/ocr/ppocr/ppocr_v2.h +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/ppocr_v2.h @@ -59,6 +59,14 @@ class FASTDEPLOY_DECL PPOCRv2 : public FastDeployModel { * \return true if the prediction successed, otherwise false. */ virtual bool Predict(cv::Mat* img, fastdeploy::vision::OCRResult* result); + /** \brief BatchPredict the input image and get OCR result. + * + * \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. + * \param[in] batch_result The output list of OCR result will be writen to this structure. + * \return true if the prediction successed, otherwise false. + */ + virtual bool BatchPredict(const std::vector& images, + std::vector* batch_result); bool Initialized() const override; protected: @@ -66,11 +74,6 @@ class FASTDEPLOY_DECL PPOCRv2 : public FastDeployModel { fastdeploy::vision::ocr::Classifier* classifier_ = nullptr; fastdeploy::vision::ocr::Recognizer* recognizer_ = nullptr; /// Launch the detection process in OCR. - virtual bool Detect(cv::Mat* img, fastdeploy::vision::OCRResult* result); - /// Launch the recognition process in OCR. - virtual bool Recognize(cv::Mat* img, fastdeploy::vision::OCRResult* result); - /// Launch the classification process in OCR. - virtual bool Classify(cv::Mat* img, fastdeploy::vision::OCRResult* result); }; namespace application { diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/ppocr_v3.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/ppocr_v3.h index e248eca75e..ed9177d923 100644 --- a/3rdparty/include/fastdeploy/vision/ocr/ppocr/ppocr_v3.h +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/ppocr_v3.h @@ -36,7 +36,7 @@ class FASTDEPLOY_DECL PPOCRv3 : public PPOCRv2 { fastdeploy::vision::ocr::Recognizer* rec_model) : PPOCRv2(det_model, cls_model, rec_model) { // The only difference between v2 and v3 - recognizer_->rec_image_shape[1] = 48; + recognizer_->preprocessor_.rec_image_shape_[1] = 48; } /** \brief Classification model is optional, so this function is set up the detection model path and recognition model path respectively. * @@ -47,7 +47,7 @@ class FASTDEPLOY_DECL PPOCRv3 : public PPOCRv2 { fastdeploy::vision::ocr::Recognizer* rec_model) : PPOCRv2(det_model, rec_model) { // The only difference between v2 and v3 - recognizer_->rec_image_shape[1] = 48; + recognizer_->preprocessor_.rec_image_shape_[1] = 48; } }; diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h new file mode 100644 index 0000000000..d1aa0124b4 --- /dev/null +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/rec_postprocessor.h @@ -0,0 +1,55 @@ +// Copyright (c) 2022 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 +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" +#include "fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h" + +namespace fastdeploy { +namespace vision { + +namespace ocr { +/*! @brief Postprocessor object for Recognizer serials model. + */ +class FASTDEPLOY_DECL RecognizerPostprocessor { + public: + RecognizerPostprocessor(); + /** \brief Create a postprocessor instance for Recognizer serials model + * + * \param[in] label_path The path of label_dict + */ + explicit RecognizerPostprocessor(const std::string& label_path); + + /** \brief Process the result of runtime and fill to ClassifyResult structure + * + * \param[in] tensors The inference result from runtime + * \param[in] texts The output result of recognizer + * \param[in] rec_scores The output result of recognizer + * \return true if the postprocess successed, otherwise false + */ + bool Run(const std::vector& tensors, + std::vector* texts, std::vector* rec_scores); + + private: + bool SingleBatchPostprocessor(const float* out_data, + const std::vector& output_shape, + std::string* text, float* rec_score); + bool initialized_ = false; + std::vector label_list_; +}; + +} // namespace ocr +} // namespace vision +} // namespace fastdeploy diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h new file mode 100644 index 0000000000..3e5c7de824 --- /dev/null +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/rec_preprocessor.h @@ -0,0 +1,52 @@ +// Copyright (c) 2022 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 +#include "fastdeploy/vision/common/processors/transform.h" +#include "fastdeploy/vision/common/result.h" + +namespace fastdeploy { +namespace vision { + +namespace ocr { +/*! @brief Preprocessor object for PaddleClas serials model. + */ +class FASTDEPLOY_DECL RecognizerPreprocessor { + public: + /** \brief Create a preprocessor instance for PaddleClas serials model + * + * \param[in] config_file Path of configuration file for deployment, e.g resnet/infer_cfg.yml + */ + RecognizerPreprocessor(); + + /** \brief Process the input image and prepare input tensors for runtime + * + * \param[in] images The input image data list, all the elements are returned by cv::imread() + * \param[in] outputs The output tensors which will feed in runtime + * \return true if the preprocess successed, otherwise false + */ + bool Run(std::vector* images, std::vector* outputs); + + std::vector rec_image_shape_ = {3, 48, 320}; + std::vector mean_ = {0.5f, 0.5f, 0.5f}; + std::vector scale_ = {0.5f, 0.5f, 0.5f}; + bool is_scale_ = true; + + private: + bool initialized_ = false; +}; + +} // namespace ocr +} // namespace vision +} // namespace fastdeploy diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/recognizer.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/recognizer.h index d3c5fcc9d4..1cd841eb45 100644 --- a/3rdparty/include/fastdeploy/vision/ocr/ppocr/recognizer.h +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/recognizer.h @@ -17,6 +17,8 @@ #include "fastdeploy/vision/common/processors/transform.h" #include "fastdeploy/vision/common/result.h" #include "fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h" +#include "fastdeploy/vision/ocr/ppocr/rec_preprocessor.h" +#include "fastdeploy/vision/ocr/ppocr/rec_postprocessor.h" namespace fastdeploy { namespace vision { @@ -43,35 +45,20 @@ class FASTDEPLOY_DECL Recognizer : public FastDeployModel { const ModelFormat& model_format = ModelFormat::PADDLE); /// Get model's name std::string ModelName() const { return "ppocr/ocr_rec"; } - /** \brief Predict the input image and get OCR recognition model result. + /** \brief BatchPredict the input image and get OCR recognition model result. * - * \param[in] im The input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. - * \param[in] rec_result The output of OCR recognition model result will be writen to this structure. + * \param[in] images The list of input image data, comes from cv::imread(), is a 3-D array with layout HWC, BGR format. + * \param[in] rec_results The output of OCR recognition model result will be writen to this structure. * \return true if the prediction is successed, otherwise false. */ - virtual bool Predict(cv::Mat* img, - std::tuple* rec_result); + virtual bool BatchPredict(const std::vector& images, + std::vector* texts, std::vector* rec_scores); - // Pre & Post parameters - std::vector label_list; - int rec_batch_num; - int rec_img_h; - int rec_img_w; - std::vector rec_image_shape; - - std::vector mean; - std::vector scale; - bool is_scale; + RecognizerPreprocessor preprocessor_; + RecognizerPostprocessor postprocessor_; private: bool Initialize(); - /// Preprocess the input data, and set the preprocessed results to `outputs` - bool Preprocess(Mat* img, FDTensor* outputs, - const std::vector& rec_image_shape); - /*! @brief Postprocess the inferenced results, and set the final result to `rec_result` - */ - bool Postprocess(FDTensor& infer_result, - std::tuple* rec_result); }; } // namespace ocr diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h index 8422704fd5..5900daea2b 100644 --- a/3rdparty/include/fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/utils/ocr_postprocess_op.h @@ -57,9 +57,8 @@ class PostProcessor { const float &det_db_unclip_ratio, const std::string &det_db_score_mode); std::vector>> FilterTagDetRes( - std::vector>> boxes, float ratio_h, - float ratio_w, - const std::map> &im_info); + std::vector>> boxes, + const std::array& det_img_info); private: static bool XsortInt(std::vector a, std::vector b); diff --git a/3rdparty/include/fastdeploy/vision/ocr/ppocr/utils/ocr_utils.h b/3rdparty/include/fastdeploy/vision/ocr/ppocr/utils/ocr_utils.h index 36994389ba..0e5c040eb8 100644 --- a/3rdparty/include/fastdeploy/vision/ocr/ppocr/utils/ocr_utils.h +++ b/3rdparty/include/fastdeploy/vision/ocr/ppocr/utils/ocr_utils.h @@ -28,10 +28,10 @@ namespace fastdeploy { namespace vision { namespace ocr { -cv::Mat GetRotateCropImage(const cv::Mat& srcimage, +FASTDEPLOY_DECL cv::Mat GetRotateCropImage(const cv::Mat& srcimage, const std::array& box); -void SortBoxes(OCRResult* result); +FASTDEPLOY_DECL void SortBoxes(std::vector>* boxes); } // namespace ocr } // namespace vision diff --git a/3rdparty/lib/ON.lib b/3rdparty/lib/ON.lib new file mode 100644 index 0000000000..ec1d844cac Binary files /dev/null and b/3rdparty/lib/ON.lib differ diff --git a/src/MeoAssistant/MeoAssistant.vcxproj b/src/MeoAssistant/MeoAssistant.vcxproj index d2fe8ce28a..bf220d38ff 100644 --- a/src/MeoAssistant/MeoAssistant.vcxproj +++ b/src/MeoAssistant/MeoAssistant.vcxproj @@ -294,7 +294,7 @@ true true true - fastdeploy.lib;opencv_world453.lib;zlibstatic.lib;ws2_32.lib;%(AdditionalDependencies) + ON.lib;opencv_world453.lib;zlibstatic.lib;ws2_32.lib;%(AdditionalDependencies) RequireAdministrator @@ -347,7 +347,7 @@ true true true - fastdeploy.lib;opencv_world453.lib;zlibstatic.lib;ws2_32.lib;%(AdditionalDependencies) + ON.lib;opencv_world453.lib;zlibstatic.lib;ws2_32.lib;%(AdditionalDependencies) RequireAdministrator diff --git a/src/MeoAssistant/Resource/Miscellaneous/OcrPack.cpp b/src/MeoAssistant/Resource/Miscellaneous/OcrPack.cpp index 297fb92b53..561b373e3c 100644 --- a/src/MeoAssistant/Resource/Miscellaneous/OcrPack.cpp +++ b/src/MeoAssistant/Resource/Miscellaneous/OcrPack.cpp @@ -112,12 +112,17 @@ std::vector asst::OcrPack::recognize(const cv::Mat& image, const else { LogTraceScope("Ocr Rec with " + class_type); - std::tuple rec_result; - m_rec->Predict(&copied, &rec_result); + std::vector rec_imgs = { std::move(copied) }; + std::vector rec_texts; + std::vector rec_scores; + m_rec->BatchPredict(rec_imgs, &rec_texts, &rec_scores); - auto& [text, score] = rec_result; - ocr_result.text.emplace_back(std::move(text)); - ocr_result.rec_scores.emplace_back(score); + if (!rec_texts.empty()) { + ocr_result.text.emplace_back(std::move(rec_texts.front())); + } + if (!rec_scores.empty()) { + ocr_result.rec_scores.emplace_back(rec_scores.front()); + } } #ifdef ASST_DEBUG @@ -217,4 +222,4 @@ static std::filesystem::path prepare_paddle_dir(const std::filesystem::path& dir } } -#endif \ No newline at end of file +#endif