hwc2chw.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/OpReformat.hpp>
  18. #include "ultra_infer/vision/common/processors/cvcuda_utils.h"
  19. #endif
  20. namespace ultra_infer {
  21. namespace vision {
  22. /*! @brief Processor for transform images from HWC to CHW.
  23. */
  24. class ULTRAINFER_DECL HWC2CHW : public Processor {
  25. public:
  26. bool ImplByOpenCV(Mat *mat);
  27. #ifdef ENABLE_FLYCV
  28. bool ImplByFlyCV(Mat *mat);
  29. #endif
  30. #ifdef ENABLE_CVCUDA
  31. bool ImplByCvCuda(FDMat *mat);
  32. #endif
  33. std::string Name() { return "HWC2CHW"; }
  34. /** \brief Process the input images
  35. *
  36. * \param[in] mat The input image data
  37. * \param[in] lib to define OpenCV or FlyCV or CVCUDA will be used.
  38. * \return true if the process succeeded, otherwise false
  39. */
  40. static bool Run(Mat *mat, ProcLib lib = ProcLib::DEFAULT);
  41. private:
  42. #ifdef ENABLE_CVCUDA
  43. cvcuda::Reformat cvcuda_reformat_op_;
  44. #endif
  45. };
  46. } // namespace vision
  47. } // namespace ultra_infer