5 #include "PredictorWrapper.h"
7 using namespace suanzi;
9 static const 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 multiTracker = std::make_shared<MultiTracker>();
39 void Engine::destroy()
41 LOG_DEBUG(TAG, "destroy");
45 observer_list.clear();
49 void Engine::setVideoSrc(VideoSrcType type, const std::string& url)
51 reader = VideoReaderFactory::createVideoReader(type, url);
56 LOG_DEBUG(TAG, "run");
58 Detection detections[128];
59 while (reader->read(frame)){
60 LOG_DEBUG(TAG, "Size: " << frame.cols << "x" << frame.rows);
61 int total = detector->detect(frame, detections);
62 multiTracker->update(total, detections, frame);
68 LOG_DEBUG(TAG, "start");
70 LOG_ERROR(TAG, "reader is null. exit");
73 std::thread t(&Engine::run, this);
77 void Engine::addObserver(EngineObserver *observer)
79 observer_list.insert(observer);