X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=src%2FEngine.cpp;h=16a704dd19eb10a5767272c535e8ac6d5533af70;hb=a80807eb35cc0ff70a9afdd6b7db2f38cb686683;hp=49a17daee4f7ec4963e4029f0552ee472203dbb4;hpb=0e3565052ce6db176c34c448a7368b463d318558;p=trackerpp.git diff --git a/src/Engine.cpp b/src/Engine.cpp index 49a17da..16a704d 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -1,16 +1,20 @@ #include #include +#include #include "Engine.h" #include "Logger.h" +#include "PredictorWrapper.h" using namespace suanzi; +using namespace std; -const static std::string TAG = "Engine"; - +static const std::string TAG = "Engine"; static std::mutex g_mutex; static EngineWPtr g_instance; +typedef std::shared_ptr> PersonsInfoPtr; +// class Engine EnginePtr Engine::create() { LOG_DEBUG(TAG, "create"); @@ -27,22 +31,25 @@ EnginePtr Engine::create() Engine::Engine() { detector = std::make_shared(); - MetricsPtr m (new Metrics("model.pkl")); - multiTracker = std::make_shared(m); } Engine::~Engine() { + destroy(); } void Engine::destroy() { + LOG_DEBUG(TAG, "destroy"); + detector.reset(); + multiTracker.reset(); + reader.reset(); + observer_list.clear(); } void Engine::setVideoSrc(VideoSrcType type, const std::string& url) { -// videoSrc = url; reader = VideoReaderFactory::createVideoReader(type, url); } @@ -53,7 +60,6 @@ void Engine::run() Detection detections[128]; while (reader->read(frame)){ LOG_DEBUG(TAG, "Size: " << frame.cols << "x" << frame.rows); - // TODO int total = detector->detect(frame, detections); multiTracker->update(total, detections, frame); } @@ -62,6 +68,7 @@ void Engine::run() void Engine::start() { LOG_DEBUG(TAG, "start"); + multiTracker = std::make_shared(g_instance); if (!reader){ LOG_ERROR(TAG, "reader is null. exit"); return; @@ -74,3 +81,49 @@ void Engine::addObserver(EngineObserver *observer) { observer_list.insert(observer); } + + +// WorkItem class for event thread +class PersonInEventWorkItem : public WorkItem +{ +public: + PersonInEventWorkItem(std::set obs, PersonsInfoPtr info) : obs(obs), info(info){ + } + ~PersonInEventWorkItem(){} + void run (){ + for (auto o : obs){ + o->onPersonsIn(*(info.get())); + } + } +private: + std::set obs; + PersonsInfoPtr info; +}; + +class PersonOutEventWorkItem : public WorkItem +{ +public: + PersonOutEventWorkItem(std::set obs, PersonsInfoPtr info) : obs(obs), info(info){ + } + ~PersonOutEventWorkItem(){} + void run (){ + for (auto o : obs){ + o->onPersonsIn(*(info.get())); + } + } +private: + std::set obs; + PersonsInfoPtr info; +}; + +void Engine::onPersonsOut(const std::vector& p) +{ + PersonsInfoPtr pp = std::make_shared>(p); + eventThread.enqueue(new PersonOutEventWorkItem(this->observer_list, pp)); +} + +void Engine::onPersonsIn(const std::vector& p) +{ + PersonsInfoPtr pp = std::make_shared>(p); + eventThread.enqueue(new PersonInEventWorkItem(this->observer_list, pp)); +}