stride_pad.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 with stride.
  23. */
  24. class ULTRAINFER_DECL StridePad : public Processor {
  25. public:
  26. // only support pad with left-top padding mode
  27. StridePad(int stride, const std::vector<float> &value) {
  28. stride_ = stride;
  29. value_ = value;
  30. }
  31. bool ImplByOpenCV(Mat *mat);
  32. #ifdef ENABLE_FLYCV
  33. bool ImplByFlyCV(Mat *mat);
  34. #endif
  35. #ifdef ENABLE_CVCUDA
  36. bool ImplByCvCuda(FDMat *mat);
  37. #endif
  38. std::string Name() { return "StridePad"; }
  39. /** \brief Process the input images
  40. *
  41. * \param[in] mat The input image data, `result = mat * alpha + beta`
  42. * \param[in] stride stride of the padding.
  43. * \param[in] value value vector used by padding of the output image.
  44. * \param[in] lib to define OpenCV or FlyCV or CVCUDA will be used.
  45. * \return true if the process succeeded, otherwise false
  46. */
  47. static bool Run(Mat *mat, int stride,
  48. const std::vector<float> &value = std::vector<float>(),
  49. ProcLib lib = ProcLib::DEFAULT);
  50. private:
  51. int stride_ = 32;
  52. std::vector<float> value_;
  53. #ifdef ENABLE_CVCUDA
  54. cvcuda::CopyMakeBorder cvcuda_pad_op_;
  55. #endif
  56. };
  57. } // namespace vision
  58. } // namespace ultra_infer