base.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "opencv2/highgui/highgui.hpp"
  16. #include "opencv2/imgproc/imgproc.hpp"
  17. #include "ultra_infer/utils/utils.h"
  18. #include "ultra_infer/vision/common/processors/mat.h"
  19. #include "ultra_infer/vision/common/processors/mat_batch.h"
  20. #include <unordered_map>
  21. namespace ultra_infer {
  22. namespace vision {
  23. /*! @brief Enable using FlyCV to process image while deploy vision models.
  24. * Currently, FlyCV in only available on ARM(Linux aarch64), so will
  25. * fallback to using OpenCV in other platform
  26. */
  27. ULTRAINFER_DECL void EnableFlyCV();
  28. /// Disable using FlyCV to process image while deploy vision models.
  29. ULTRAINFER_DECL void DisableFlyCV();
  30. /*! @brief Set the cpu num threads of ProcLib.
  31. */
  32. ULTRAINFER_DECL void SetProcLibCpuNumThreads(int threads);
  33. /*! @brief Processor base class for processors in
  34. * ultra_infer/vision/common/processors
  35. */
  36. class ULTRAINFER_DECL Processor {
  37. public:
  38. // default_lib has the highest priority
  39. // all the function in `processor` will force to use
  40. // default_lib if this flag is set.
  41. // DEFAULT means this flag is not set
  42. // static ProcLib default_lib;
  43. virtual std::string Name() = 0;
  44. virtual bool ImplByOpenCV(FDMat *mat);
  45. virtual bool ImplByOpenCV(FDMatBatch *mat_batch);
  46. virtual bool ImplByFlyCV(FDMat *mat);
  47. virtual bool ImplByFlyCV(FDMatBatch *mat_batch);
  48. virtual bool ImplByCuda(FDMat *mat);
  49. virtual bool ImplByCuda(FDMatBatch *mat_batch);
  50. virtual bool ImplByCvCuda(FDMat *mat);
  51. virtual bool ImplByCvCuda(FDMatBatch *mat_batch);
  52. /*! @brief operator `()` for calling processor in this way: `processor(mat)`
  53. *
  54. * \param[in] mat: The input mat
  55. * \return true if the process succeeded, otherwise false
  56. */
  57. virtual bool operator()(FDMat *mat);
  58. /*! @brief operator `()` for calling processor in this way: `processor(mat,
  59. * lib)` This function is for backward compatibility, will be removed in the
  60. * near future, please use operator()(FDMat* mat) instead and set proc_lib in
  61. * mat.
  62. *
  63. * \param[in] mat: The input mat
  64. * \param[in] lib: The processing library, opencv, cv-cuda, flycv, etc.
  65. * \return true if the process succeeded, otherwise false
  66. */
  67. virtual bool operator()(FDMat *mat, ProcLib lib);
  68. /*! @brief operator `()` for calling processor in this way:
  69. * `processor(mat_batch)`
  70. *
  71. * \param[in] mat_batch: The input mat batch
  72. * \return true if the process succeeded, otherwise false
  73. */
  74. virtual bool operator()(FDMatBatch *mat_batch);
  75. };
  76. } // namespace vision
  77. } // namespace ultra_infer