osd.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*************************************************************************
  2. * Copyright (C) [2019] by Cambricon, Inc. All rights reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. #ifndef MODULES_OSD_HPP_
  21. #define MODULES_OSD_HPP_
  22. /**
  23. * @file osd.hpp
  24. *
  25. * This file contains a declaration of class Osd
  26. */
  27. #include <memory>
  28. #include <string>
  29. #include <unordered_map>
  30. #include <vector>
  31. #include "opencv2/highgui/highgui.hpp"
  32. #include "opencv2/imgproc/imgproc.hpp"
  33. #include "cnstream_module.hpp"
  34. namespace cnstream {
  35. class CnOsd;
  36. /**
  37. * @brief Draw objects on image,output is bgr24 images
  38. */
  39. class Osd : public Module, public ModuleCreator<Osd> {
  40. public:
  41. /**
  42. * @brief Generate osd
  43. *
  44. * @param Name : Module name
  45. *
  46. * @return None
  47. */
  48. explicit Osd(const std::string& name);
  49. /**
  50. * @brief Release osd
  51. * @param None
  52. * @return None
  53. */
  54. ~Osd();
  55. /**
  56. * @brief Called by pipeline when pipeline start.
  57. *
  58. * @param paramSet :
  59. * @verbatim
  60. * label_path: label path
  61. * @endverbatim
  62. *
  63. * @return if module open succeed
  64. */
  65. bool Open(cnstream::ModuleParamSet paramSet) override;
  66. /**
  67. * @brief Called by pipeline when pipeline stop
  68. *
  69. * @param None
  70. *
  71. * @return None
  72. */
  73. void Close() override;
  74. /**
  75. * @brief Do for each frame
  76. *
  77. * @param data : Pointer to the frame info
  78. *
  79. * @return whether process succeed
  80. * @retval 0: succeed and do no intercept data
  81. * @retval <0: failed
  82. *
  83. */
  84. int Process(std::shared_ptr<CNFrameInfo> data) override;
  85. /**
  86. * @brief Check ParamSet for a module.
  87. *
  88. * @param paramSet Parameters for this module.
  89. *
  90. * @return Returns true if this API run successfully. Otherwise, returns false.
  91. */
  92. bool CheckParamSet(const ModuleParamSet& paramSet) const override;
  93. private:
  94. std::shared_ptr<CnOsd> GetOsdContext();
  95. std::unordered_map<std::thread::id, std::shared_ptr<CnOsd>> osd_ctxs_;
  96. RwLock ctx_lock_;
  97. std::vector<std::string> labels_;
  98. std::vector<std::string> secondary_labels_;
  99. std::vector<std::string> attr_keys_;
  100. std::string font_path_ = "";
  101. std::string logo_ = "";
  102. float text_scale_ = 1;
  103. float text_thickness_ = 1;
  104. float box_thickness_ = 1;
  105. float label_size_ = 1;
  106. }; // class Osd
  107. } // namespace cnstream
  108. #endif // MODULES_OSD_HPP_