det_postprocessor.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/vision/common/processors/transform.h"
  16. #include "ultra_infer/vision/common/result.h"
  17. #include "ultra_infer/vision/ocr/ppocr/utils/ocr_postprocess_op.h"
  18. namespace ultra_infer {
  19. namespace vision {
  20. namespace ocr {
  21. /*! @brief Postprocessor object for DBDetector serials model.
  22. */
  23. class ULTRAINFER_DECL DBDetectorPostprocessor {
  24. public:
  25. /** \brief Process the result of runtime and fill to results structure
  26. *
  27. * \param[in] tensors The inference result from runtime
  28. * \param[in] results The output result of detector
  29. * \param[in] batch_det_img_info The detector_preprocess result
  30. * \return true if the postprocess succeeded, otherwise false
  31. */
  32. bool Run(const std::vector<FDTensor> &tensors,
  33. std::vector<std::vector<std::array<int, 8>>> *results,
  34. const std::vector<std::array<int, 4>> &batch_det_img_info);
  35. /// Set det_db_thresh for the detection postprocess, default is 0.3
  36. void SetDetDBThresh(double det_db_thresh) { det_db_thresh_ = det_db_thresh; }
  37. /// Get det_db_thresh of the detection postprocess
  38. double GetDetDBThresh() const { return det_db_thresh_; }
  39. /// Set det_db_box_thresh for the detection postprocess, default is 0.6
  40. void SetDetDBBoxThresh(double det_db_box_thresh) {
  41. det_db_box_thresh_ = det_db_box_thresh;
  42. }
  43. /// Get det_db_box_thresh of the detection postprocess
  44. double GetDetDBBoxThresh() const { return det_db_box_thresh_; }
  45. /// Set det_db_unclip_ratio for the detection postprocess, default is 1.5
  46. void SetDetDBUnclipRatio(double det_db_unclip_ratio) {
  47. det_db_unclip_ratio_ = det_db_unclip_ratio;
  48. }
  49. /// Get det_db_unclip_ratio_ of the detection postprocess
  50. double GetDetDBUnclipRatio() const { return det_db_unclip_ratio_; }
  51. /// Set det_db_score_mode for the detection postprocess, default is 'slow'
  52. void SetDetDBScoreMode(const std::string &det_db_score_mode) {
  53. det_db_score_mode_ = det_db_score_mode;
  54. }
  55. /// Get det_db_score_mode_ of the detection postprocess
  56. std::string GetDetDBScoreMode() const { return det_db_score_mode_; }
  57. /// Set use_dilation for the detection postprocess, default is false
  58. void SetUseDilation(int use_dilation) { use_dilation_ = use_dilation; }
  59. /// Get use_dilation of the detection postprocess
  60. int GetUseDilation() const { return use_dilation_; }
  61. private:
  62. double det_db_thresh_ = 0.3;
  63. double det_db_box_thresh_ = 0.6;
  64. double det_db_unclip_ratio_ = 1.5;
  65. std::string det_db_score_mode_ = "slow";
  66. bool use_dilation_ = false;
  67. PostProcessor util_post_processor_;
  68. bool SingleBatchPostprocessor(const float *out_data, int n2, int n3,
  69. const std::array<int, 4> &det_img_info,
  70. std::vector<std::array<int, 8>> *boxes_result);
  71. };
  72. } // namespace ocr
  73. } // namespace vision
  74. } // namespace ultra_infer