basic版本的yolo,在yolov3版本上增加人体跟踪
xuepengqiang
2020-05-26 5966f2b095841627d62daac0159e81f83544b85c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Created by Scheaven on 2020/4/26.
//
 
#include "human_interface.h"
#include <iostream>
#include <map>
#include <string>
#include <list>
#include <algorithm>
#include <fstream>
#include <stdint.h>
#include <vector>
#include <thread>
//#include <json/json.h>
#include <jsoncpp/json/json.h>
#include <tgmath.h>
#include  <cmath>
#include <math.h>
#include <list>
using std::__cxx11::list;//I am forced to use std-c++11 because of wxWidgets 3.0.2
#include <cstdlib>
 
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;
}