派生自 Algorithm/baseDetector

Scheaven
2021-06-03 168af40fe9a3cc81c6ee16b3e81f154780c36bdb
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
//
// Created by Scheaven on 2020/4/26.
//
 
#include "human_interface.h"
//#include "utils/type_utils.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"; // 初始化结构体静态变量值
 
//创建/并初始化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;
}