xuepengqiang
2020-05-26 48bf06c1cadadcfb93faa8df63db71e59b534f55
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
//
// Created by Scheaven on 2020/5/20.
//
 
#include "coord_interface.h"
#include "switcher_util.h"
#include "json_util.h"
 
CoordSwitcher switcher;
CoordManager::CoordManager(const char *json_document)
{
 
}
 
CoordManager::CoordManager(CamVec *CV_Reg)
{
    this->CV_Reg = CV_Reg;
    switcher.initHomography(CV_Reg);
//    this->init_flag = false;
//    CoordSwitcher switcher(CV_Reg);
 
}
 
CoordManager::~CoordManager() {}
 
float confidence =0.0;
 
 
char* CoordManager::get_result(MulCam* curr_Human, MulCam* last_Human)
{
    // 创建获取结果的结构体
    STarget* target = new STarget();
//    stemtarget->temcamResult = (TemCamResult*)malloc(sizeof(TemCamResult)*(mulCam->cam_count-1));
    target->camResult = new CamResult[curr_Human->cam_count-1];
    group_compare(curr_Human, last_Human , target);// 批量匹配区域中的人
 
 
//    //    //遍历结果
//    for (int i = 0; i < curr_Human->cam_count-1; ++i) {
//        map<string,float>::iterator iter;
//        for (iter=target->camResult[i].confidence_map.begin() ;iter!=target->camResult[i].confidence_map.end();iter++) {
//            std::cout<< iter->first << "  confidence   " << iter->second << std::endl;
//        }
//    }
//
//    std::cout<< " ----------   " <<  std::endl;
//    map<int,int>::iterator direction_iter;
//    for (direction_iter=target->direction_map.begin();direction_iter!=target->direction_map.end();direction_iter++) {
//        std::cout<< direction_iter->first << "  direction   " << direction_iter->second << std::endl;
//    }
 
 
    string result_json = "{\"confidence\":\n\t{";
    for (int i = 0; i < curr_Human->cam_count-1; ++i) {
        string c_json = map_json(target->camResult[i].confidence_map);
        result_json += "\t\"" + target->camResult[i].cam_pair + "\":[" + c_json.substr(0,c_json.length()-1) + "],\n";
    }
    result_json = result_json.substr(0,result_json.length()-2)+"\n\t},\n";
    result_json += "\"direction\":[";
    string d_json = map_json(target->direction_map);
    result_json += d_json.substr(0,d_json.length()-1) + "]\n}\n";
 
 
//    string json = to_json_string(target);
    char *result = (char*)result_json.c_str();
//    cout << result << endl;
    return result;
 
 
 
}
 
 
void CoordManager::group_compare(MulCam* curr_Human, MulCam* last_Human, STarget* target)
{
 
    map<int,float> global_min_points_map; 
 
    for (int k = 1; k < curr_Human->cam_count; ++k) {
        for (int i = 0; i < curr_Human->matchHuman[0].count; ++i) {
            int curr_direction = -1;
            float local_min_distance = 100000.0;
 
            target->camResult[k-1].cam_pair = to_string(1)+":"+to_string(k+1);
 
            for (int j = 0; j < curr_Human->matchHuman[k].count; ++j) {
                confidence = switcher.compare(curr_Human->matchHuman[0].humanInfo[i].point, curr_Human->matchHuman[k].humanInfo[j].point, k - 1);
                if(local_min_distance>confidence){
                    local_min_distance = confidence;
                }
                target->camResult[k-1].confidence_map.insert(pair<string,float >(to_string(curr_Human->matchHuman[0].humanInfo[i].human_id)+ ":" +to_string( curr_Human->matchHuman[k].humanInfo[j].human_id), confidence));
            }
 
            if(global_min_points_map.count(curr_Human->matchHuman[0].humanInfo[i].human_id)>0)
            {
                if (global_min_points_map[curr_Human->matchHuman[0].humanInfo[i].human_id]>local_min_distance)
                {
                    global_min_points_map[curr_Human->matchHuman[0].humanInfo[i].human_id] = local_min_distance; //更新方向
                    curr_direction = k+1;
                }
            }else
            {
                curr_direction = k+1;
                global_min_points_map.insert(pair<int, float>(curr_Human->matchHuman[0].humanInfo[i].human_id, local_min_distance)); // 首次添加方向
            }
 
 
            if(target->direction_map.count(curr_Human->matchHuman[0].humanInfo[i].human_id)>0)
            {
                if (curr_direction!=-1)
                    target->direction_map[curr_Human->matchHuman[0].humanInfo[i].human_id] =curr_direction; //更新方向
            }else
            {
                target->direction_map.insert(pair<int, int>(curr_Human->matchHuman[0].humanInfo[i].human_id,  curr_direction)); // 首次添加方向
            }
 
        }
    }
 
 
//    map<string,float> confidence_map;
//    for (int i = 0; i < A_Human->count; ++i) {
//        for (int j = 0; j < B_Human->count; ++j) {
//            confidence = switcher.compare(A_Human->humanInfo[i].point, B_Human->humanInfo[j].point);
//            confidence_map.insert(pair<string,float >(to_string(A_Human->humanInfo[i].human_id)+ ":" +to_string(B_Human->humanInfo[j].human_id), confidence));
//        }
//    }
//    return confidence_map;
}
 
void CoordManager::init_Target(STarget *target)
{
    target->direction_map[0] = 10000;
    target->camResult = nullptr;
}