ComposeTool.cpp
2.41 KB
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
#include "ComposeTool.h"
#include <algorithm>
using namespace std;
#define MAX_OVERLAP 0.01
float ComposeTool::IoU(sy_rect &bb_test, sy_rect &bb_gt)
{
bool flag = false; //判断两个矩形中心,是否位于另一个矩形中
sy_point center1{ (bb_test.left_ + bb_test.left_ + bb_test.width_) / 2 , (bb_test.top_ + bb_test.top_ + bb_test.height_) / 2 };
sy_point center2{ (bb_gt.left_ + bb_gt.width_) / 2 , (bb_gt.top_ + bb_gt.height_) / 2 };
if ((center1.x_ > bb_gt.left_ && center1.x_ < bb_gt.left_ + bb_gt.width_) && (center1.y_ > bb_gt.top_ && center1.y_ < bb_gt.top_ + bb_gt.height_))
{
flag = true;
}
if ((center2.x_ > bb_test.left_ && center2.x_ < bb_test.left_ + bb_test.width_) && (center2.y_ > bb_test.top_ && center2.y_ < bb_test.top_ + bb_test.height_))
{
flag = true;
}
if (flag == true)
{
float xx1, yy1, xx2, yy2, w, h, wh, o;
xx1 = max(bb_test.left_, bb_gt.left_);
yy1 = max(bb_test.top_, bb_gt.top_);
xx2 = min(bb_test.left_ + bb_test.width_, bb_gt.left_ + bb_gt.width_);
yy2 = min(bb_test.top_ + bb_test.height_, bb_gt.top_ + bb_gt.height_);
w = ((xx2 - xx1));
h = ((yy2 - yy1));
wh = w * h;
o = wh / ((bb_test.width_)*(bb_test.height_)
+ (bb_gt.width_)*(bb_gt.height_) - wh);
return o;
}
else
{
return 0;
}
}
void ComposeTool::compose_res(rs_result *resultCpu, rs_result *resultVpt, rs_result *result)
{
size_t unique_id = 0;
for (int j = 0; j < resultVpt->obj_count; ++j)
{
result->obj_infos[unique_id] = resultVpt->obj_infos[j];
result->obj_infos[unique_id].unique_id = resultVpt->obj_infos[j].unique_id;
result->obj_infos[unique_id].index = 0;
++unique_id;
}
for (int i = 0; i < resultCpu->obj_count; ++i)
{
int j = 0;
for (; j < resultVpt->obj_count; ++j)
{
if (IoU(resultCpu->obj_infos[i].tar_box, resultVpt->obj_infos[j].tar_box) > MAX_OVERLAP)
{
for (int k = 0; k < MAXROINUM; ++k)
{
if (resultCpu->obj_infos[i].pb_alarm_state[k] == true && resultCpu->obj_infos[i].pb_alarm_type[k][5] == 6)
{
result->obj_infos[j].pb_alarm_state[k] = true;
result->obj_infos[j].pb_alarm_type[k][5] = 6;
}
}
break;
}
}
if (j < resultVpt->obj_count)
{
continue;
}
result->obj_infos[unique_id] = resultCpu->obj_infos[i];
result->obj_infos[unique_id].unique_id = resultCpu->obj_infos[i].unique_id;
result->obj_infos[unique_id].index = 1;
++unique_id;
}
result->obj_count = ++unique_id;
}