Scheaven
2021-07-23 3f0ae58275718c03f99799182e40e9429334aac8
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
//
// Created by Scheaven on 2020/3/23.
//
 
#include "ari_manager.h"
#include "../utils/protomsg.pb.h"
 
AriManager::AriManager()
{
}
 
AriManager::~AriManager()
{
}
 
void AriManager::doInfer(const char* cam_name, const void *img, TResult *t_result, void *info, const int info_size)
{
    decode_detect(t_result, info, info_size);
 
 
    int temp = 0;
    int num = 0;
    int curr_num = 0;
    int bef_num = 0;
 
    if(t_result->count==temp){
        num=num+1;
    }else{
        temp=t_result->count;
        num=0;
    }
 
    std::string att_json = "\"{";
    if(num==m_staticStruct::times){
        cout<<"person num is constant: "<<endl;
        curr_num= t_result->count;
        if (bef_num==curr_num){
            cout<<"人数未发生变化,当前人数为:"<< curr_num<<endl;
            att_json += "isChange:" + to_string(0) + "befNum:" + to_string(bef_num) +"currNum:" + to_string(curr_num) +"}" ;
        } else{
            cout<<"人数发生了变化,当前人数为: "<<curr_num<<"变化前的人数为: "<<bef_num;
            att_json += "isChange:" + to_string(1) + "befNum:" + to_string(bef_num) +"currNum:" + to_string(curr_num) +"}";
            bef_num=curr_num;
        }
        num=0;
    }
    DEBUG(att_json);
 
    for (int i=0; i<t_result->count; i++)
    {
        if(att_json.length()>2)
        {
           t_result->targets[0].attribute = new char[strlen(att_json.c_str())+1];
           t_result->targets[0].attribute_size = strlen(att_json.c_str());
           strcpy(t_result->targets[0].attribute, att_json.c_str());
        }
        t_result->count = 1;
    }
}
void AriManager::decode_detect(TResult *t_result, void *human_info, const int human_info_size)
{
    protomsg::RuleMessage rulemsg;
    rulemsg.ParseFromArray(human_info, human_info_size);
    for(int i = 0; i < rulemsg.message_size(); ++i)
    {
        auto &sdkmsg = rulemsg.message(i);
        if(sdkmsg.sdktype() == "BaseDetector")
        {
            DEBUG( "-----yolo-human_size:" +   to_string(sdkmsg.target_size()));
            t_result->targets = (Target*)malloc(sizeof(Target) * sdkmsg.target_size()); // 绘制人脸信息的
            int w_count = 0;
            for (int j = 0; j < sdkmsg.target_size(); ++j)
            {
                Target t;
                init_target(&t);
                auto &target = sdkmsg.target(j);
                DEBUG( "------yolo target.conf: " +   std::to_string(target.confidence()));
 
                t.rect.left = target.rect().left();
                t.rect.right = target.rect().right();
                t.rect.top = target.rect().top();
                t.rect.bottom = target.rect().bottom();
                t.confidence = target.confidence();
                t_result->targets[w_count] = t;
                w_count ++;
            }
            t_result->count = w_count;
            break;
        }
    }
}
 
void AriManager::init_target(Target *t){
    t->attribute = NULL;
    t->feature = NULL;
    t->id = 0;
    t->rect = TRect{0,0,0,0};
    t->confidence = 0;
    t->attribute_size = 0;
    t->feature_size = 0;
}