convert.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 convert images with given parameters.
  19. */
  20. class ULTRAINFER_DECL Convert : public Processor {
  21. public:
  22. Convert(const std::vector<float> &alpha, const std::vector<float> &beta);
  23. bool ImplByOpenCV(Mat *mat);
  24. #ifdef ENABLE_FLYCV
  25. bool ImplByFlyCV(Mat *mat);
  26. #endif
  27. std::string Name() { return "Convert"; }
  28. // Compute `result = mat * alpha + beta` directly by channel.
  29. // The default behavior is the same as OpenCV's convertTo method.
  30. /** \brief Process the input images
  31. *
  32. * \param[in] mat The input image data,`result = mat * alpha + beta`
  33. * \param[in] alpha The alpha channel data
  34. * \param[in] beta The beta channel data
  35. * \param[in] lib to define OpenCV or FlyCV or CVCUDA will be used.
  36. * \return true if the process succeeded, otherwise false
  37. */
  38. static bool Run(Mat *mat, const std::vector<float> &alpha,
  39. const std::vector<float> &beta,
  40. ProcLib lib = ProcLib::DEFAULT);
  41. private:
  42. std::vector<float> alpha_;
  43. std::vector<float> beta_;
  44. };
  45. } // namespace vision
  46. } // namespace ultra_infer