cast.h 1.8 KB

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