5 #include "PredictorWrapper.h"
7 using namespace suanzi;
9 const static std::string TAG = "Engine";
11 static std::mutex g_mutex;
12 static EngineWPtr g_instance;
15 EnginePtr Engine::create()
17 LOG_DEBUG(TAG, "create");
18 std::lock_guard<std::mutex> lock(g_mutex);
19 if (g_instance.lock()){
20 LOG_ERROR(TAG, "already exists");
21 return EnginePtr(); // nullptr
23 EnginePtr instance (new Engine());
24 g_instance = instance;
30 detector = std::make_shared<Detector>();
31 MetricsPtr m (new Metrics("model.pkl"));
32 multiTracker = std::make_shared<MultiTracker>(m);
39 void Engine::destroy()
44 void Engine::setVideoSrc(VideoSrcType type, const std::string& url)
46 PredictorWrapperPtr pp = PredictorWrapper::create("./python/model.pkl");
51 //reader = VideoReaderFactory::createVideoReader(type, url);
57 LOG_DEBUG(TAG, "run");
59 Detection detections[128];
60 while (reader->read(frame)){
61 LOG_DEBUG(TAG, "Size: " << frame.cols << "x" << frame.rows);
63 int total = detector->detect(frame, detections);
64 multiTracker->update(total, detections, frame);
70 LOG_DEBUG(TAG, "start");
72 LOG_ERROR(TAG, "reader is null. exit");
75 std::thread t(&Engine::run, this);
79 void Engine::addObserver(EngineObserver *observer)
81 observer_list.insert(observer);