image_decoder.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/utils/utils.h"
  16. #include "ultra_infer/vision/common/image_decoder/nvjpeg_decoder.h"
  17. #include "ultra_infer/vision/common/processors/mat.h"
  18. namespace ultra_infer {
  19. namespace vision {
  20. enum class ULTRAINFER_DECL ImageDecoderLib { OPENCV, NVJPEG };
  21. class ULTRAINFER_DECL ImageDecoder {
  22. public:
  23. explicit ImageDecoder(ImageDecoderLib lib = ImageDecoderLib::OPENCV);
  24. ~ImageDecoder();
  25. bool Decode(const std::string &img_name, FDMat *mat);
  26. bool BatchDecode(const std::vector<std::string> &img_names,
  27. std::vector<FDMat> *mats);
  28. private:
  29. bool ImplByOpenCV(const std::vector<std::string> &img_names,
  30. std::vector<FDMat> *mats);
  31. bool ImplByNvJpeg(const std::vector<std::string> &img_names,
  32. std::vector<FDMat> *mats);
  33. ImageDecoderLib lib_ = ImageDecoderLib::OPENCV;
  34. #ifdef ENABLE_NVJPEG
  35. nvjpeg::decode_params_t nvjpeg_params_;
  36. #endif
  37. };
  38. } // namespace vision
  39. } // namespace ultra_infer