crop.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. /*! @brief Processor for crop images with given parameters.
  19. */
  20. class ULTRAINFER_DECL Crop : public Processor {
  21. public:
  22. Crop(int offset_w, int offset_h, int width, int height) {
  23. offset_w_ = offset_w;
  24. offset_h_ = offset_h;
  25. width_ = width;
  26. height_ = height;
  27. }
  28. bool ImplByOpenCV(Mat *mat);
  29. #ifdef ENABLE_FLYCV
  30. bool ImplByFlyCV(Mat *mat);
  31. #endif
  32. std::string Name() { return "Crop"; }
  33. /** \brief Process the input images
  34. *
  35. * \param[in] mat The input image data
  36. * \param[in] offset_w The offset of width.
  37. * \param[in] offset_h The offset of height.
  38. * \param[in] width The width of the output image.
  39. * \param[in] height The height of the output image.
  40. * \param[in] lib to define OpenCV or FlyCV or CVCUDA will be used.
  41. * \return true if the process succeeded, otherwise false
  42. */
  43. static bool Run(Mat *mat, int offset_w, int offset_h, int width, int height,
  44. ProcLib lib = ProcLib::DEFAULT);
  45. private:
  46. int offset_w_;
  47. int offset_h_;
  48. int height_;
  49. int width_;
  50. };
  51. } // namespace vision
  52. } // namespace ultra_infer