a
suntianyu
2021-07-29 b186a5ae8097bf8f9796bf44b8a299e52b72918c
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
//
// Created by Scheaven on 2020/4/26.
//
#include "h_interface.h"
#include "utils/config.h"
#include <iostream>
#include <fstream>
#include <json/json.h>
using namespace std;
 
int m_staticStruct::times = 10;
 
// 创建
YOLOTRACK_API void* create(const char *conf, int *max_chan)
{
    CLog::Initialize("/opt/vasystem/bin/models/humanCount/log.properties");
    AriManager *handle = new AriManager();
    ReadJsonFromFile(conf);
    return handle;
}
 
// 原查找结果接口
YOLOTRACK_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->doInfer(*t_result);
    return t_result;
}
 
// 传递人脸结果并查找信息
YOLOTRACK_API void* get_result_face(void *handle, const void *img, const char* arg_json, const int arg_len, void *face_info, const int face_info_size)
{
    Json::Reader reader;
    Json::Value root;
    AriManager *h = (AriManager*)handle;
//    TResult *t_result = new TResult();
    TResult *t_result = (TResult*)malloc(sizeof(TResult));
    init_TResult(t_result);
    DEBUG( "------yolo before  ");
    h->doInfer("", img, t_result, face_info, face_info_size);
    DEBUG( "------yolo back  " );
 
    return t_result;
}
 
YOLOTRACK_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);
}
 
YOLOTRACK_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;
 
    ifstream in(filename, ios::binary);
    if( !in.is_open() )
    {
        cout << "Error opening json config file\n";
        return;
    }
 
    if(reader.parse(in,root))
    {
        int times = root["param"]["model_path"].asInt();
        m_staticStruct::times  = times;
    }
    in.close();
}
 
void init_TResult(TResult *t)
{
    t->count = 0;
    t->targets = nullptr;
}