pad.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/base.h"
  16. #ifdef ENABLE_CVCUDA
  17. #include <cvcuda/OpCopyMakeBorder.hpp>
  18. #include "ultra_infer/vision/common/processors/cvcuda_utils.h"
  19. #endif
  20. namespace ultra_infer {
  21. namespace vision {
  22. /*! @brief Processor for padding images.
  23. */
  24. class ULTRAINFER_DECL Pad : public Processor {
  25. public:
  26. Pad(int top, int bottom, int left, int right,
  27. const std::vector<float> &value) {
  28. top_ = top;
  29. bottom_ = bottom;
  30. left_ = left;
  31. right_ = right;
  32. value_ = value;
  33. }
  34. bool ImplByOpenCV(Mat *mat);
  35. #ifdef ENABLE_FLYCV
  36. bool ImplByFlyCV(Mat *mat);
  37. #endif
  38. #ifdef ENABLE_CVCUDA
  39. bool ImplByCvCuda(FDMat *mat);
  40. #endif
  41. std::string Name() { return "Pad"; }
  42. /** \brief Process the input images
  43. *
  44. * \param[in] mat The input image data, `result = mat * alpha + beta`
  45. * \param[in] top top pad size of the output image.
  46. * \param[in] bottom bottom pad size of the output image.
  47. * \param[in] left left pad size of the output image.
  48. * \param[in] right right pad size of the output image.
  49. * \param[in] value value vector used by padding of the output image.
  50. * \param[in] lib to define OpenCV or FlyCV or CVCUDA will be used.
  51. * \return true if the process succeeded, otherwise false
  52. */
  53. static bool Run(Mat *mat, const int &top, const int &bottom, const int &left,
  54. const int &right, const std::vector<float> &value,
  55. ProcLib lib = ProcLib::DEFAULT);
  56. /** \brief Process the input images
  57. *
  58. * \param[in] top set the value of the top parameter
  59. * \param[in] bottom set the value of the bottom parameter
  60. * \param[in] left set the value of the left parameter
  61. * \param[in] right set the value of the right parameter
  62. */
  63. bool SetPaddingSize(int top, int bottom, int left, int right) {
  64. top_ = top;
  65. bottom_ = bottom;
  66. left_ = left;
  67. right_ = right;
  68. return true;
  69. }
  70. private:
  71. int top_;
  72. int bottom_;
  73. int left_;
  74. int right_;
  75. std::vector<float> value_;
  76. #ifdef ENABLE_CVCUDA
  77. cvcuda::CopyMakeBorder cvcuda_pad_op_;
  78. #endif
  79. };
  80. } // namespace vision
  81. } // namespace ultra_infer