6 using namespace suanzi;
8 const static std::string TAG = "Engine";
10 static std::mutex g_mutex;
11 static EngineWPtr g_instance;
14 EnginePtr Engine::create()
16 LOG_DEBUG(TAG, "create");
17 std::lock_guard<std::mutex> lock(g_mutex);
18 if (g_instance.lock()){
19 LOG_ERROR(TAG, "already exists");
20 return EnginePtr(); // nullptr
22 EnginePtr instance (new Engine());
23 g_instance = instance;
29 detector = std::make_shared<Detector>();
30 MetricsPtr m (new Metrics("model.pkl"));
31 multiTracker = std::make_shared<MultiTracker>(m);
38 void Engine::destroy()
43 void Engine::setVideoSrc(VideoSrcType type, const std::string& url)
46 reader = VideoReaderFactory::createVideoReader(type, url);
51 LOG_DEBUG(TAG, "run");
53 Detection detections[128];
54 while (reader->read(frame)){
55 LOG_DEBUG(TAG, "Size: " << frame.cols << "x" << frame.rows);
57 int total = detector->detect(frame, detections);
58 multiTracker->update(total, detections, frame);
64 LOG_DEBUG(TAG, "start");
66 LOG_ERROR(TAG, "reader is null. exit");
69 std::thread t(&Engine::run, this);
73 void Engine::addObserver(EngineObserver *observer)
75 observer_list.insert(observer);