InfineFilter.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-03-09 10:55:43
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-08-23 16:04:10
  8. */
  9. #ifndef __INFINEFILTER_H_
  10. #define __INFINEFILTER_H_
  11. #include <iostream>
  12. #include "Notices.h"
  13. #include "Util/util.h"
  14. #include "Util/logger.h"
  15. #include "Network/Socket.h"
  16. #include "Util/TimeTicker.h"
  17. #include "Util/NoticeCenter.h"
  18. #include "Poller/Timer.h"
  19. #include "CNStreamInferData.h"
  20. #include "config.hpp"
  21. #include <cmath>
  22. using namespace std;
  23. using namespace toolkit;
  24. namespace gsd
  25. {
  26. // 推理过滤器
  27. class InfineFilter
  28. {
  29. private:
  30. struct HistoryData
  31. {
  32. std::shared_ptr<Ticker> ticker = nullptr;
  33. std::shared_ptr<CNStreamInferData> CnStreamInferData = nullptr;
  34. };
  35. private:
  36. InfineFilter(){
  37. }
  38. InfineFilter(InfineFilter&) = delete;
  39. InfineFilter& operator=(const InfineFilter&) = delete;
  40. // 灵敏度 0,1,2,3
  41. // 0 - 不过滤
  42. // 1 - 参考上一个坐标、大小、数量, 如果类似则过滤
  43. // 2 - 在1的基础上加入 时间间隔,如每2秒取一次结果
  44. // 3 - 记录每一个结果,并设置超时机制,未超时时:判断当前推理结果与过去的坐标、大小、数量是否类似,类似则过滤
  45. // 超时时:舍弃历史记录
  46. int sensitivity = 2; // 灵敏度
  47. // 0 - 不过滤
  48. // 1 - 参考上一个坐标、大小、数量, 如果类似则过滤
  49. // 2 - 在1的基础上加入 时间间隔,如每2秒取一次结果
  50. // 3 - 记录每一个结果,并设置超时机制,未超时时:判断当前推理结果与过去的坐标、大小、数量是否类似,类似则过滤
  51. // 超时时:舍弃历史记录
  52. int filterLevel = 2; // 过滤器等级
  53. int interval = 2000; // 时间间隔
  54. vector<HistoryData> HistoryDatas;
  55. int TimeOut = 10 * 60 * 1000;
  56. Timer::Ptr timer = nullptr;
  57. private:
  58. /**
  59. * @description: 跟上一次的判断结果
  60. * @param {*}
  61. * @return {*}
  62. */
  63. int8_t LastOneJudgment(std::shared_ptr<CNStreamInferData>& cnStreamInferData);
  64. /**
  65. * @description:时间间隔
  66. * @param {*}
  67. * @return {*}
  68. */
  69. int8_t IntervalJudgment();
  70. /**
  71. * @description: 历史判定
  72. * @param {*}
  73. * @return {*}
  74. */
  75. int8_t HistoricalJudgment(std::shared_ptr<CNStreamInferData>& cnStreamInferData);
  76. /**
  77. * @description: 历史数据检查
  78. * @param {*}
  79. * @return {*}
  80. */
  81. void HistoricalCheck();
  82. public:
  83. using Ptr = std::shared_ptr<InfineFilter>;
  84. ~InfineFilter(){}
  85. /**
  86. * @description: 小目标过滤器
  87. * @return {*}
  88. */
  89. int8_t MinBBoxFilter(std::shared_ptr<CNStreamInferData>& cnStreamInferData);
  90. /**
  91. * @description: 判定结果
  92. * @param {*}
  93. * @return {*}
  94. */
  95. int8_t judgementResult(std::shared_ptr<CNStreamInferData>& cnStreamInferData);
  96. /**
  97. * @description: 判定是否相识
  98. * @param {InferInfo&} infer1
  99. * @param {InferInfo&} infer2
  100. * @return {*}
  101. */
  102. int8_t CalculateSimilarity(InferInfo& infer1, InferInfo& infer2);
  103. /**
  104. * @description: 获取ptr
  105. * @param {*}
  106. * @return {*}
  107. */
  108. static std::shared_ptr<InfineFilter> getPtr();
  109. /**
  110. * @description: 设置等级
  111. * @param {int} FilterLevel
  112. * @return {*}
  113. */
  114. int8_t setFilterLevel(int FilterLevel);
  115. /**
  116. * @description: 设置时间间隔
  117. * @param {int} Interval
  118. * @return {*}
  119. */
  120. int8_t setInterval(int Interval);
  121. /**
  122. * @description: 设置超时时间
  123. * @param {int} timeOut
  124. * @return {*}
  125. */
  126. int8_t setTimeOut(int timeOut);
  127. public:
  128. double bboxSize = 0.0;
  129. };
  130. } // namespace gsd
  131. #endif