warp_affine.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include "ultra_infer/vision/common/processors/warp_affine.h"
  15. namespace ultra_infer {
  16. namespace vision {
  17. bool WarpAffine::ImplByOpenCV(Mat *mat) {
  18. if (mat->layout != Layout::HWC) {
  19. FDERROR << "WarpAffine: The format of input is not HWC." << std::endl;
  20. return false;
  21. }
  22. cv::Mat *im = mat->GetOpenCVMat();
  23. if (width_ > 0 && height_ > 0) {
  24. cv::warpAffine(*im, *im, trans_matrix_, cv::Size(width_, height_), interp_,
  25. border_mode_, borderValue_);
  26. } else {
  27. FDERROR
  28. << "WarpAffine: the parameters must satisfy (width > 0 && height > 0) ."
  29. << std::endl;
  30. return false;
  31. }
  32. mat->SetWidth(im->cols);
  33. mat->SetHeight(im->rows);
  34. return true;
  35. }
  36. bool WarpAffine::Run(Mat *mat, const cv::Mat &trans_matrix, int width,
  37. int height, int interp, int border_mode,
  38. const cv::Scalar &borderValue, ProcLib lib) {
  39. auto r =
  40. WarpAffine(trans_matrix, width, height, interp, border_mode, borderValue);
  41. return r(mat, lib);
  42. }
  43. } // namespace vision
  44. } // namespace ultra_infer