center_crop.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/OpCustomCrop.hpp>
  18. #include "ultra_infer/vision/common/processors/cvcuda_utils.h"
  19. #endif
  20. namespace ultra_infer {
  21. namespace vision {
  22. /*! @brief Processor for crop images in center with given type default is
  23. * float.
  24. */
  25. class ULTRAINFER_DECL CenterCrop : public Processor {
  26. public:
  27. CenterCrop(int width, int height) : height_(height), width_(width) {}
  28. bool ImplByOpenCV(FDMat *mat);
  29. #ifdef ENABLE_FLYCV
  30. bool ImplByFlyCV(FDMat *mat);
  31. #endif
  32. #ifdef ENABLE_CVCUDA
  33. bool ImplByCvCuda(FDMat *mat);
  34. bool ImplByCvCuda(FDMatBatch *mat_batch);
  35. #endif
  36. std::string Name() { return "CenterCrop"; }
  37. /** \brief Process the input images
  38. *
  39. * \param[in] mat The input image data
  40. * \param[in] width width of data will be croped to
  41. * \param[in] height height of data will be croped to
  42. * \param[in] lib to define OpenCV or FlyCV or CVCUDA will be used.
  43. * \return true if the process succeeded, otherwise false
  44. */
  45. static bool Run(FDMat *mat, const int &width, const int &height,
  46. ProcLib lib = ProcLib::DEFAULT);
  47. private:
  48. int height_;
  49. int width_;
  50. #ifdef ENABLE_CVCUDA
  51. cvcuda::CustomCrop cvcuda_crop_op_;
  52. #endif
  53. };
  54. } // namespace vision
  55. } // namespace ultra_infer