// // Created by Scheaven on 2020/4/26. // #include "human_interface.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"; // 初始化结构体静态变量值 string m_staticStruct::tracher_model = "0"; // 初始化结构体静态变量值 string m_staticStruct::coco_path = "0"; // 初始化结构体静态变量值 int m_staticStruct::max_cam_num = 0; // 初始化结构体静态变量值 void* manager_create(const char *conf, int *max_chan) { TrackerManager *handle = new TrackerManager(); ReadJsonFromFile(conf); *max_chan = m_staticStruct::max_cam_num; for (int i = 1; i <= m_staticStruct::max_cam_num; ++i) { handle->add_cam(i); } handle->init_load_model(); 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) { 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); 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; //从文件中读取,保证当前文件有test.json文件 ifstream in(filename, 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(); std::string tracher_model = root["param"]["tracher_model"].asString(); std::string coco_path = root["param"]["coco_path"].asString(); max_cam_num = root["param"]["max_cam_num"].asInt(); m_staticStruct::cfg_path = cfg_path; m_staticStruct::weights_path = weights_path; m_staticStruct::tracher_model = tracher_model; m_staticStruct::coco_path = coco_path; m_staticStruct::max_cam_num = max_cam_num; } else { std::cout << "parse error\n" << std::endl; } in.close(); } void init_TResult(TResult *t){ t->count = 0; t->targets = nullptr; }