派生自 Algorithm/baseDetector

Scheaven
2021-09-08 9b1532d86c2cf48a63017f3460897d8d14b98b60
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
// Created by Scheaven on 2020/4/26.
//
#include "h_interface.h"
#include <iostream>
#include <fstream>
#include <json/json.h>
using namespace std;
 
string m_staticStruct::model_path = "path";
string m_staticStruct::model_cfg = "0"; // 初始化结构体静态变量值
string m_staticStruct::model_wts = "0"; // 初始化结构体静态变量值
int m_staticStruct::type = 1;
bool m_staticStruct::isTrack= true;
int m_staticStruct::max_cam_num = 0;
int m_staticStruct::wander_time = 0;
float m_staticStruct::mv_velocity = 0;
float m_staticStruct::fall_rate = 0;
 
 
API void* create(const char *conf, int *max_chan)
{
    // CLog::Initialize("/opt/vasystem/bin/models/baseDetector/log.properties");
    CLog::Initialize("../config/log4cplus.properties");
    ReadJsonFromFile(conf);
    AriManager *handle = new AriManager();
    *max_chan = m_staticStruct::max_cam_num;
    for (int i = 1; i <= m_staticStruct::max_cam_num; ++i)
    {
        handle->add_cam(i);
    }
    Timer::getInstance()->reset();
    return handle;
}
 
API void* get_result(void *handle, const void *img, const int chan)
{
    AriManager *h = (AriManager*)handle;
    TResult *t_result = (TResult*)malloc(sizeof(TResult));
    init_TResult(t_result);
 
    Timer::getInstance()->out("eveTime before yolo");
    // h->single_SDK(chan, img, *t_result);
    Timer::getInstance()->out("eveTime runing yolo");
    return t_result;
}
 
 
API void* get_result2(void *handle, const void *img, const int chan, const char* timestamp, const char* mode)
{
    DEBUG("-----------------------begin------------ ");
    AriManager *h = (AriManager*)handle;
    TResult *t_result = (TResult*)malloc(sizeof(TResult));
    init_TResult(t_result);
 
    if(!m_staticStruct::isTrack)
    {
        Timer::getInstance()->out("get_result2 before yolo");
        h->single_SDK(chan, img, t_result);
        Timer::getInstance()->out("get_result2 runing yolo");
        return t_result;
    }
 
    h->single_SDK(chan, img, t_result, const_cast<char*>(timestamp), mode);
    DEBUG("--cam id:" + to_string(chan) + "  image human_count:" + to_string(t_result->count));
    for (int i = 0; i < t_result->count; ++i)
    {
        if(mode == "video"){
            DEBUG("--human_id:" + to_string(t_result->targets[i].id)+"  human_confidence:" + to_string(t_result->targets[i].confidence) + "  human_attribute:" + std::string(t_result->targets[i].attribute) +  "  human_top:" + to_string(t_result->targets[i].rect.top)+" human_left:" + to_string(t_result->targets[i].rect.left) + "  human_right:" + to_string(t_result->targets[i].rect.right)+ "  human_bottom:" + to_string(t_result->targets[i].rect.bottom));
        }
        else{
            DEBUG("human_confidence:" + to_string(t_result->targets[i].confidence) + "  human_top:" + to_string(t_result->targets[i].rect.top)+" human_left:" + to_string(t_result->targets[i].rect.left) + "  human_right:" + to_string(t_result->targets[i].rect.right)+ "  human_bottom:" + to_string(t_result->targets[i].rect.bottom));
        }
    }
    DEBUG("---------------------end over------------------------\n\n");
    return t_result;
}
 
API void release_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);
}
 
API void release(void* handle)
{
    AriManager *h = (AriManager*)handle;
    delete h;
    h = NULL;
}
 
void ReadJsonFromFile(const char* filename)
{
    Json::Reader reader;
    Json::Value root;
    int max_cam_num;
    int wander_time;
    float mv_velocity;
    float fall_rate;
    string tmp = filename;
 
    ifstream in(filename, ios::binary);
    if( !in.is_open() )
    {
        cout << "Error opening json config file\n";
        return;
    }
    if(reader.parse(in,root))
    {
        std::string model_path = root["param"]["model_path"].asString();
        std::string model_cfg= root["param"]["model_cfg"].asString();
        std::string model_wts = root["param"]["model_wts"].asString();
        int type = root["param"]["type"].asInt();
        bool isTrack = root["param"]["isTrack"].asBool();
        int max_cam_num = root["param"]["max_cam_num"].asInt();
        int wander_time = root["param"]["wander_time"].asInt();
        int mv_velocity = root["param"]["mv_velocity"].asFloat();
        int fall_rate = root["param"]["fall_rate"].asFloat();
        m_staticStruct::model_path  = model_path;
        m_staticStruct::model_cfg  = model_cfg;
        m_staticStruct::model_wts  = model_wts;
        m_staticStruct::type  = type;
        m_staticStruct::isTrack = isTrack;
        m_staticStruct::max_cam_num  = max_cam_num;
        m_staticStruct::wander_time = wander_time;
        m_staticStruct::mv_velocity = mv_velocity;
        m_staticStruct::fall_rate = fall_rate;
 
    }
    in.close();
}
 
void init_TResult(TResult *t)
{
    t->count = 0;
    t->targets = nullptr;
}