warp_affine.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. namespace ultra_infer {
  17. namespace vision {
  18. class WarpAffine : public Processor {
  19. public:
  20. WarpAffine(const cv::Mat &trans_matrix, int width, int height, int interp = 1,
  21. int border_mode = 0,
  22. const cv::Scalar &borderValue = cv::Scalar()) {
  23. trans_matrix_ = trans_matrix;
  24. width_ = width;
  25. height_ = height;
  26. interp_ = interp;
  27. border_mode_ = border_mode;
  28. borderValue_ = borderValue;
  29. }
  30. bool ImplByOpenCV(Mat *mat);
  31. std::string Name() { return "WarpAffine"; }
  32. bool SetTransformMatrix(const cv::Mat &trans_matrix) {
  33. trans_matrix_ = trans_matrix;
  34. return true;
  35. }
  36. std::tuple<int, int> GetWidthAndHeight() {
  37. return std::make_tuple(width_, height_);
  38. }
  39. static bool Run(Mat *mat, const cv::Mat &trans_matrix, int width, int height,
  40. int interp = 1, int border_mode = 0,
  41. const cv::Scalar &borderValue = cv::Scalar(),
  42. ProcLib lib = ProcLib::DEFAULT);
  43. private:
  44. cv::Mat trans_matrix_;
  45. int width_;
  46. int height_;
  47. int interp_;
  48. int border_mode_;
  49. cv::Scalar borderValue_;
  50. };
  51. } // namespace vision
  52. } // namespace ultra_infer