// // Created by Scheaven on 2020/4/26. // #include "human_interface.h" //#include "utils/type_utils.h" #include #include #include #include #include #include #include #include #include #include //#include #include #include #include #include using std::__cxx11::list;//I am forced to use std-c++11 because of wxWidgets 3.0.2 #include using namespace std; string m_staticStruct::cfg_path = "0"; // 初始化结构体静态变量值 string m_staticStruct::weights_path = "0"; // 初始化结构体静态变量值 //创建/并初始化tracker和线程 void* manager_create(const char *conf, int *max_chan) { TrackerManager *handle = new TrackerManager(); ReadJsonFromFile(conf); handle->init_load_model(); //初始化时加载YOLO模型 return handle; } //释放句柄 void manager_release(void* handle) { TrackerManager *h = (TrackerManager*)handle; h->release(); delete h; h = NULL; cout << "release success" << endl; } //返回检测结果 void* frame_result(void *handle, const void *img, const int chan) { SLOG::getInstance()->addLog(0, "----frame_result start---------"); TrackerManager *h = (TrackerManager*)handle; // TResult *t_result = new TResult(); TResult *t_result = (TResult*)malloc(sizeof(TResult)); init_TResult(t_result); h->single_SDK(chan, img, *t_result); SLOG::getInstance()->addLog(0, "----frame_result end---------"); return t_result; } // 释放结果结构 void manager_result(void *res) { if (!res) return; TResult *cres = (TResult*)res; // delete cres; for (int i = 0; i < cres->count; i++){ Target t = cres->targets[i]; if (t.feature) free(t.feature); if (t.attribute) free(t.attribute); } free(cres->targets); free(cres); } // 读取Json文件 void ReadJsonFromFile(const char* filename) { Json::Reader reader; Json::Value root; int max_cam_num; int wander_time; float mv_velocity; float fall_rate; //从文件中读取,保证当前文件有test.json文件 ifstream in(filename, ios::binary); //in.open("test.json", ios::binary); if( !in.is_open() ) { cout << "Error opening json config file\n"; return; } if(reader.parse(in,root)) { //读取子节点信息 std::string cfg_path = root["param"]["cfg_path"].asString(); std::string weights_path = root["param"]["weights_path"].asString(); m_staticStruct::cfg_path = cfg_path; m_staticStruct::weights_path = weights_path; } else { SLOG::getInstance()->addLog(0, "--Enter the correct .json JSON format!!\n"); } in.close(); } void init_TResult(TResult *t) { t->count = 0; t->targets = nullptr; }