123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include "HeadCountCfg.h"
- #include "HeadCountStrategy.h"
- #include "OSTime.h"
- #include "SysUtils.h"
- NAMESPACE_MAS_BEGIN
- NAMESPACE_HEADCOUNT_BEGIN
- HeadCountStrategy::HeadCountStrategy() :
- Strategy("HeadCount", "人头计数判定策略")
- {
-
- }
- HeadCountStrategy::~HeadCountStrategy()
- {
- this->Dispose();
- }
- TZ_INT HeadCountStrategy::Initialize()
- {
- m_inited = TRUE;
- return MEC_OK;
- }
- TZ_INT HeadCountStrategy::Dispose()
- {
- m_inited = FALSE;
- return MEC_OK;
- }
- TZ_INT HeadCountStrategy::SetStrategyCfg(const std::string & param)
- {
- if (!m_inited) return MEC_NOT_INITED;
- HeadCountCfg cfg;
- HeadCountCfg::fromJson(param, cfg);
- //m_timeThreshold = cfg.TimeThreshold;
- return MEC_OK;
- }
- TZ_INT HeadCountStrategy::DoStrategy(SPtr<StreamInfo> & streamInfo)
- {
- if (!m_inited) return MEC_NOT_INITED;
- auto & detMap = streamInfo->GetAllDetRst();
- StraRst rst;
- rst.RstType = SRT_NONE;
- if (detMap.count("YoloCrowd"))
- {
- m_yoloCrowdLock.Lock();
- m_qYoloCrowdQueue.push(detMap["YoloCrowd"]->Result);
- // TZLogInfo("m_qYoloCrowdQueue %d", m_qYoloCrowdQueue.size());
- m_yoloCrowdLock.Unlock();
- }
- else
- {
- TZLogWarn("Rst not found!!!");
- streamInfo->SetStraRst(m_key, rst, streamInfo->GetMediaRsc());
- return MEC_FAILED;
- }
- m_yoloCrowdLock.Lock();
- if (m_qYoloCrowdQueue.empty())
- {
- m_yoloCrowdLock.Unlock();
- streamInfo->SetStraRst(m_key, rst, streamInfo->GetMediaRsc());
- return MEC_OK;
- }
- std::string jYoloCrowdRst = m_qYoloCrowdQueue.front();
- m_qYoloCrowdQueue.pop();
- m_yoloCrowdLock.Unlock();
- yolocrowd::YoloCrowdDetectResult yoloCrowdRst;
- yolocrowd::YoloCrowdDetectResult::fromJson(jYoloCrowdRst, yoloCrowdRst);
- /*m_headCountLock.Lock();
- m_headCountQueue.push(yoloCrowdRst.objs.size());
- if (m_headCountQueue.size() > static_cast<std::queue<int>::size_type>(m_timeThreshold * 25))
- {
- m_headCountQueue.pop();
- }
- m_headCountLock.Unlock();
- int sumHeads = 0;
- std::queue<int> tempQueue = m_headCountQueue;
- while (!tempQueue.empty())
- {
- sumHeads += tempQueue.front();
- tempQueue.pop();
- }
- int avgHeadCount = sumHeads / m_headCountQueue.size();*/
- rst.RstType = SRT_NOT_SHOW;
- std::ostringstream oss;
- oss << yoloCrowdRst.objs.size();
- rst.RstName = oss.str();
-
- streamInfo->SetStraRst(m_key, rst, streamInfo->GetMediaRsc());
- return MEC_OK;
- }
- NAMESPACE_HEADCOUNT_END
- NAMESPACE_MAS_END
|