structurev2_layout.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include "ultra_infer/ultra_infer_model.h"
  16. #include "ultra_infer/utils/unique_ptr.h"
  17. #include "ultra_infer/vision/common/processors/transform.h"
  18. #include "ultra_infer/vision/common/result.h"
  19. #include "ultra_infer/vision/ocr/ppocr/structurev2_layout_postprocessor.h"
  20. #include "ultra_infer/vision/ocr/ppocr/structurev2_layout_preprocessor.h"
  21. #include "ultra_infer/vision/ocr/ppocr/utils/ocr_postprocess_op.h"
  22. namespace ultra_infer {
  23. namespace vision {
  24. namespace ocr {
  25. /*! @brief StructureV2Layout object is used to load the PP-StructureV2-Layout
  26. * detection model.
  27. */
  28. class ULTRAINFER_DECL StructureV2Layout : public UltraInferModel {
  29. public:
  30. StructureV2Layout();
  31. /** \brief Set path of model file, and the configuration of runtime
  32. *
  33. * \param[in] model_file Path of model file, e.g
  34. * ./picodet_lcnet_x1_0_fgd_layout_cdla_infer/model.pdmodel. \param[in]
  35. * params_file Path of parameter file, e.g
  36. * ./picodet_lcnet_x1_0_fgd_layout_cdla_infer/model.pdiparams, if the model
  37. * format is ONNX, this parameter will be ignored. \param[in] custom_option
  38. * RuntimeOption for inference, the default will use cpu, and choose the
  39. * backend defined in `valid_cpu_backends`. \param[in] model_format Model
  40. * format of the loaded model, default is Paddle format.
  41. */
  42. StructureV2Layout(const std::string &model_file,
  43. const std::string &params_file = "",
  44. const RuntimeOption &custom_option = RuntimeOption(),
  45. const ModelFormat &model_format = ModelFormat::PADDLE);
  46. /** \brief Clone a new StructureV2Layout with less memory usage when multiple
  47. * instances of the same model are created
  48. *
  49. * \return newStructureV2Layout* type unique pointer
  50. */
  51. virtual std::unique_ptr<StructureV2Layout> Clone() const;
  52. /// Get model's name
  53. std::string ModelName() const { return "pp-structurev2-layout"; }
  54. /** \brief DEPRECATED Predict the detection result for an input image
  55. *
  56. * \param[in] im The input image data, comes from cv::imread(), is a 3-D array
  57. * with layout HWC, BGR format \param[in] result The output detection result
  58. * \return true if the prediction succeeded, otherwise false
  59. */
  60. virtual bool Predict(cv::Mat *im, DetectionResult *result);
  61. /** \brief Predict the detection result for an input image
  62. * \param[in] im The input image data, comes from cv::imread(), is a 3-D array
  63. * with layout HWC, BGR format \param[in] result The output detection result
  64. * \return true if the prediction succeeded, otherwise false
  65. */
  66. virtual bool Predict(const cv::Mat &im, DetectionResult *result);
  67. /** \brief Predict the detection result for an input image list
  68. * \param[in] im The input image list, all the elements come from
  69. * cv::imread(), is a 3-D array with layout HWC, BGR format \param[in] results
  70. * The output detection result list \return true if the prediction succeeded,
  71. * otherwise false
  72. */
  73. virtual bool BatchPredict(const std::vector<cv::Mat> &imgs,
  74. std::vector<DetectionResult> *results);
  75. /// Get preprocessor reference ofStructureV2LayoutPreprocessor
  76. virtual StructureV2LayoutPreprocessor &GetPreprocessor() {
  77. return preprocessor_;
  78. }
  79. /// Get postprocessor reference ofStructureV2LayoutPostprocessor
  80. virtual StructureV2LayoutPostprocessor &GetPostprocessor() {
  81. return postprocessor_;
  82. }
  83. private:
  84. bool Initialize();
  85. StructureV2LayoutPreprocessor preprocessor_;
  86. StructureV2LayoutPostprocessor postprocessor_;
  87. };
  88. } // namespace ocr
  89. } // namespace vision
  90. } // namespace ultra_infer