派生自 Algorithm/baseDetector

mo
Scheaven
2021-07-28 828d98a058038e953603ffebc25d029830a75d80
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
//
// 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";
int m_staticStruct::type = 1;
 
// 创建
API void* create(const char *conf, int *max_chan)
{
    CLog::Initialize("../config/log4cplus.properties");
    ReadJsonFromFile(conf);
    AriManager *handle = new AriManager();
    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);
    h->single_SDK(chan, img, *t_result);
    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;
}
 
// 读取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;
    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();
        int type = root["param"]["type"].asInt();
        m_staticStruct::model_path  = model_path;
        m_staticStruct::type  = type;
    }
    in.close();
}
 
void init_TResult(TResult *t)
{
    t->count = 0;
    t->targets = nullptr;
}