GatherDetect.cpp
3.48 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
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* @Author: yangzilong
* @Date: 2021-12-16 14:25:13
* @Last Modified by: yangzilong
* @Email: yangzilong@objecteye.com
* @Description:
*/
#include "GatherDetect.h"
#include "../helpers/img_util.h"
GatherDetect::GatherDetect()
{
m_task_param_manager = task_param_manager::getInstance();
}
void GatherDetect::init(algorithm_type_t eType)
{
m_eType = eType;
}
std::vector<GatherResult> GatherDetect::process(vector<DeviceMemory*> vec_vptMem, vector<onelevel_det_result> &ol_det_result) {
std::vector<GatherResult> results;
map<string, algor_open_config_param> && algor_config_param = m_task_param_manager->get_task_algor_params();
map<string, map<algo_type, task_param_manager::algo_param_type_t_*>> && algor_param = m_task_param_manager->get_task_other_params();
for (size_t idx = 0; idx < vec_vptMem.size(); idx++)
{
DeviceMemory* cur_vptMem = vec_vptMem[idx];
string task_id = cur_vptMem->getId();
auto it_algor = algor_param.find(task_id);
if (it_algor == algor_param.end()) {
continue;
}
task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][m_eType];
if (nullptr == cur_task_params) {
continue;
}
algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)cur_task_params->basic_param;
if (basic_param == nullptr || basic_param->adapt_param == nullptr) {
continue;
}
universal_algor_adapt_param *adapt_param = basic_param->adapt_param;
map<string, std::vector<box_t>> taskid_to_boxes;
onelevel_det_result &cur_task_ol_detres = ol_det_result[idx];
for (int c = 0; c < cur_task_ol_detres.obj_count; c++)
{
auto& obj_c = cur_task_ol_detres.obj[c];
bool bHuman = m_eType == algorithm_type_t::HUMAN_GATHER || m_eType == algorithm_type_t::HUMAN_DENSITY || m_eType == algorithm_type_t::HUMAN_REGION_GATHER;
bool bCount = false;
if(bHuman && obj_c.index == (int)det_class_label_t::HUMAN) {
bCount = true;
} else if (m_eType == algorithm_type_t::VEHICLE_GATHER && obj_c.index >= 4 && obj_c.index <= 8) {
bCount = true;
}
sy_point center;
center.x_ = (obj_c.right + obj_c.left)/ 2 ;
center.y_ = (obj_c.bottom + obj_c.top) / 2;
// vec_pt.push_back(center);
if (bCount && common::isInPolygon(adapt_param->points, adapt_param->points_count, center)) {
box_t box;
box.top = obj_c.top;
box.left = obj_c.left;
box.right = obj_c.right;
box.bottom = obj_c.bottom;
box.score = obj_c.confidence;
taskid_to_boxes[task_id].emplace_back(std::move(box));
}
}
int count_threshold = ((algor_config_param_human_gather*)cur_task_params->algor_param)->human_count_threshold;
int frame_stride = ((algor_config_param_human_gather*)cur_task_params->algor_param)->frame_stride;
if (taskid_to_boxes[task_id].size() > count_threshold && cur_vptMem->getFrameNb() % frame_stride == 0)
{
GatherResult data;
data.origin_img = VPCUtil::vpc_devMem2vpcImg(vec_vptMem[idx]);
data.task_id = task_id;
data.boxes = std::move(taskid_to_boxes[task_id]);
data.id = gid_++;
results.emplace_back(std::move(data));
}
}
return results;
}