HeadCountStrategy.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "HeadCountCfg.h"
  2. #include "HeadCountStrategy.h"
  3. #include "OSTime.h"
  4. #include "SysUtils.h"
  5. NAMESPACE_MAS_BEGIN
  6. NAMESPACE_HEADCOUNT_BEGIN
  7. HeadCountStrategy::HeadCountStrategy() :
  8. Strategy("HeadCount", "人头计数判定策略")
  9. {
  10. }
  11. HeadCountStrategy::~HeadCountStrategy()
  12. {
  13. this->Dispose();
  14. }
  15. TZ_INT HeadCountStrategy::Initialize()
  16. {
  17. m_inited = TRUE;
  18. return MEC_OK;
  19. }
  20. TZ_INT HeadCountStrategy::Dispose()
  21. {
  22. m_inited = FALSE;
  23. return MEC_OK;
  24. }
  25. TZ_INT HeadCountStrategy::SetStrategyCfg(const std::string & param)
  26. {
  27. if (!m_inited) return MEC_NOT_INITED;
  28. HeadCountCfg cfg;
  29. HeadCountCfg::fromJson(param, cfg);
  30. //m_timeThreshold = cfg.TimeThreshold;
  31. return MEC_OK;
  32. }
  33. TZ_INT HeadCountStrategy::DoStrategy(SPtr<StreamInfo> & streamInfo)
  34. {
  35. if (!m_inited) return MEC_NOT_INITED;
  36. auto & detMap = streamInfo->GetAllDetRst();
  37. StraRst rst;
  38. rst.RstType = SRT_NONE;
  39. if (detMap.count("YoloCrowd"))
  40. {
  41. m_yoloCrowdLock.Lock();
  42. m_qYoloCrowdQueue.push(detMap["YoloCrowd"]->Result);
  43. // TZLogInfo("m_qYoloCrowdQueue %d", m_qYoloCrowdQueue.size());
  44. m_yoloCrowdLock.Unlock();
  45. }
  46. else
  47. {
  48. TZLogWarn("Rst not found!!!");
  49. streamInfo->SetStraRst(m_key, rst, streamInfo->GetMediaRsc());
  50. return MEC_FAILED;
  51. }
  52. m_yoloCrowdLock.Lock();
  53. if (m_qYoloCrowdQueue.empty())
  54. {
  55. m_yoloCrowdLock.Unlock();
  56. streamInfo->SetStraRst(m_key, rst, streamInfo->GetMediaRsc());
  57. return MEC_OK;
  58. }
  59. std::string jYoloCrowdRst = m_qYoloCrowdQueue.front();
  60. m_qYoloCrowdQueue.pop();
  61. m_yoloCrowdLock.Unlock();
  62. yolocrowd::YoloCrowdDetectResult yoloCrowdRst;
  63. yolocrowd::YoloCrowdDetectResult::fromJson(jYoloCrowdRst, yoloCrowdRst);
  64. /*m_headCountLock.Lock();
  65. m_headCountQueue.push(yoloCrowdRst.objs.size());
  66. if (m_headCountQueue.size() > static_cast<std::queue<int>::size_type>(m_timeThreshold * 25))
  67. {
  68. m_headCountQueue.pop();
  69. }
  70. m_headCountLock.Unlock();
  71. int sumHeads = 0;
  72. std::queue<int> tempQueue = m_headCountQueue;
  73. while (!tempQueue.empty())
  74. {
  75. sumHeads += tempQueue.front();
  76. tempQueue.pop();
  77. }
  78. int avgHeadCount = sumHeads / m_headCountQueue.size();*/
  79. rst.RstType = SRT_NOT_SHOW;
  80. std::ostringstream oss;
  81. oss << yoloCrowdRst.objs.size();
  82. rst.RstName = oss.str();
  83. streamInfo->SetStraRst(m_key, rst, streamInfo->GetMediaRsc());
  84. return MEC_OK;
  85. }
  86. NAMESPACE_HEADCOUNT_END
  87. NAMESPACE_MAS_END