9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
1
2
3
4
5
6
7
|
#include <algorithm>
#include "./truck_manned_process.h"
#include <cmath>
#include "../decoder/interface/DeviceMemory.hpp"
#include "../common/logger.hpp"
#include "../ai_platform/mvpt_process_assist.h"
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
8
9
10
|
#include "opencv2/opencv.hpp"
#include "opencv2/imgcodecs/legacy/constants_c.h"
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
11
12
13
14
15
16
17
|
namespace ai_engine_module
{
namespace truck_manned_process
{
algorithm_type_t TruckMannedProcess::algor_type_ = algorithm_type_t::TRUCK_MANNED;
|
fa818303
Zhao Shuaihua
增加闯红灯功能(特定场景);优化货...
|
18
19
20
21
22
23
24
25
26
27
28
29
30
|
int legal_person_motocycle_inarea(const std::vector<input_data_wrap_t>& person_motocycle_data, int left, int top, int right, int bottom) {
int legal_person_motocycle_count = 0;
for (const auto& det_result : person_motocycle_data) {
int x1_intersection = std::max(det_result.box.left, left);
int y1_intersection = std::max(det_result.box.top, top);
int x2_intersection = std::min(det_result.box.right, right);
int y2_intersection = std::min(det_result.box.bottom, bottom);
if (x2_intersection <= x1_intersection || y2_intersection <= y1_intersection) continue; // 没有交集
float area_a = float(det_result.box.right - det_result.box.left) * float(det_result.box.bottom - det_result.box.top);
float area_b = float(right - left) * float(bottom - top);
float area_intersection = float(x2_intersection - x1_intersection) * float(y2_intersection - y1_intersection);
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
31
|
if (area_a > area_b || area_a <= 0) continue; //暂不考虑行人及非机动车目标比货车大的情况
|
fa818303
Zhao Shuaihua
增加闯红灯功能(特定场景);优化货...
|
32
|
// float iou = area_intersection / (area_a + area_b - area_intersection);
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
33
|
float small_overlap_ratio = area_intersection / area_a; //计算行人及非机动车目标相对于自身的重叠程度
|
fa818303
Zhao Shuaihua
增加闯红灯功能(特定场景);优化货...
|
34
35
36
37
38
39
|
if (small_overlap_ratio > 0.2) legal_person_motocycle_count ++;
}
return legal_person_motocycle_count;
}
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
void vpose_transform(float pt_x, float pt_y, float center_x, float center_y, float llength, int invert, int *res) {
//Transform pixel location to different reference.
float tmp = float(IMG_RES) / llength;
float t00 = tmp, t11 = tmp;
float t02 = IMG_RES * (-center_x / llength + .5);
float t12 = IMG_RES * (-center_y / llength + .5);
cv::Mat t = (cv::Mat_<float>(3,3) << t00,0,t02,0,t11,t12,0,0,1);
cv::Mat invt = (cv::Mat_<float>(3,3) << 0,0,0,0,0,0,0,0,0);
if (invert)
cv::invert(t, invt);
cv::Mat new_pt = (cv::Mat_<float>(3,1) << pt_x-1, pt_y-1, 1.);
cv::Mat arr_new = invt * new_pt;
for (int i = 0; i < 3-1; i++) {
res[i] = int(arr_new.at<float>(i,0));
}
}
|
d281e3a2
Zhao Shuaihua
-增加非机动车逆行(513)、机动...
|
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
|
// 计算当前位置与stop_check_frames间的最大位移
float diff_car_pos(vector<sy_point> tracker_list, int stop_check_frames, float &res_max_dist) {
float total_diff_x = 0, total_diff_y = 0, total_dist = 0;
int count = 0;
float max_dist = 0;
sy_point pos_current = tracker_list[tracker_list.size() - 1];
for (int i = tracker_list.size() - stop_check_frames; i < tracker_list.size(); i++) {
count += 1;
float temp_diff_x = 0, temp_diff_y = 0;
sy_point pos_last = tracker_list[i - 1];
temp_diff_x = pos_current.x_ - pos_last.x_;
temp_diff_y = pos_current.y_ - pos_last.y_;
float temp_dist = sqrt(temp_diff_x * temp_diff_x + temp_diff_y * temp_diff_y);
if (temp_dist > max_dist) {
max_dist = temp_dist;
}
total_diff_x += temp_diff_x;
total_diff_y += temp_diff_y;
total_dist += temp_dist;
}
res_max_dist = max_dist;
return total_dist;
}
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
86
87
88
89
90
91
92
93
|
TruckMannedProcess::TruckMannedProcess()
: task_param_manager_(nullptr)
{
}
TruckMannedProcess::~TruckMannedProcess()
{
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
94
95
96
97
98
99
100
|
if (hs_tools_) {
hs_truck_release(&hs_tools_);
hs_tools_ = nullptr;
}
if (vpose_tools_) {
vehicle_pose_release(&vpose_tools_);
vpose_tools_ = nullptr;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
101
102
103
104
105
106
|
}
if (m_algorthim_ctx) {
aclrtDestroyContext(m_algorthim_ctx);
}
}
|
15398c62
Hu Chunming
模型路径兼容
|
107
|
bool TruckMannedProcess::init(int gpu_id, string models_dir)
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
108
109
110
|
{
init_ = false;
|
d51ea997
Zhao Shuaihua
升级玩手机、雨棚模型;模型批处理;...
|
111
112
|
// string model_path = models_dir + "/models/hs/hs_truck_310p.om" ;
string model_path = models_dir + "/models/hs/hs_truck_b8_310p.om" ;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
113
|
LOG_INFO("hs_truck 版本:{} 模型路径:{}", hs_truck_getversion(), model_path);
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
114
115
|
string model_vpose_path = models_dir + "/models/village/vpose_310p.om" ;
LOG_INFO("vpose 版本:{} 模型路径:{}", vehicle_pose_get_version(), model_vpose_path);
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
116
117
118
119
|
hs_truck_param param;
char modelNames[100];
strcpy(modelNames, model_path.c_str());
|
d51ea997
Zhao Shuaihua
升级玩手机、雨棚模型;模型批处理;...
|
120
121
|
// param.modelNames = modelNames;
param.modelNames_b = modelNames;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
122
123
|
param.thresld = 0.25;
param.devId = gpu_id;
|
d51ea997
Zhao Shuaihua
升级玩手机、雨棚模型;模型批处理;...
|
124
|
param.max_batch = 8;
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
125
126
127
128
129
130
131
|
vehicle_pose_param vparam;
char vpose_modelNames[100];
strcpy(vpose_modelNames, model_vpose_path.c_str());
vparam.modelNames = vpose_modelNames;
vparam.ldmk_thres = 0.0;
vparam.devId = gpu_id;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
132
|
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
133
|
m_devId = gpu_id;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
134
135
|
ACL_CALL(aclrtSetDevice(m_devId), ACL_SUCCESS, -1);
ACL_CALL(aclrtCreateContext(&m_algorthim_ctx, m_devId), ACL_SUCCESS, -1);
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
136
|
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
137
|
int status;
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
138
|
if (!(init_ = (0 == (status = hs_truck_init(&hs_tools_, param)))))
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
139
|
LOG_ERROR("Init TruckMannedProcessSdk failed error code is {}", status);
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
140
141
|
else if (!(init_ = (0 == (status = vehicle_pose_init(&vpose_tools_, vparam)))))
LOG_ERROR("Init VehiclePoseProcessSdk failed error code is {}", status);
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
else
if (!task_param_manager_)
task_param_manager_ = task_param_manager::getInstance();
return init_;
}
bool TruckMannedProcess::check_initied()
{
if (!init_)
LOG_ERROR("[%s:%d] call init function please.", __FILE__, __LINE__);
return init_;
}
void TruckMannedProcess::force_release_result(const task_id_t& task_id) {
for (auto iter = id_to_result_.begin(); iter != id_to_result_.end();) {
const auto& key = iter->first;
if (key.task_id == task_id) {
auto& value = iter->second;
if (value.origin_img_desc != nullptr) {
VPCUtil::vpc_pic_desc_release(value.origin_img_desc);
}
if (value.roi_img_desc != nullptr) {
VPCUtil::vpc_pic_desc_release(value.roi_img_desc);
}
iter = id_to_result_.erase(iter);
}
else {
++iter;
}
}
|
d51ea997
Zhao Shuaihua
升级玩手机、雨棚模型;模型批处理;...
|
176
177
178
179
180
|
for (auto iter = id_to_mn_.begin(); iter != id_to_mn_.end();) {
const auto& key = iter->first;
if (key.task_id == task_id) { iter = id_to_mn_.erase(iter);}
else { ++iter; }
}
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
181
182
183
184
185
186
187
188
|
}
std::shared_ptr<results_data_t> TruckMannedProcess::get_result_by_objectid(const id_t& id, bool do_erase)
{
auto it = id_to_result_.find(id);
if (it == id_to_result_.end())
return std::shared_ptr<results_data_t>(nullptr);
std::shared_ptr<results_data_t> res = std::make_shared<results_data_t>(it->second);
|
d51ea997
Zhao Shuaihua
升级玩手机、雨棚模型;模型批处理;...
|
189
|
if (do_erase) {
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
190
|
id_to_result_.erase(id);
|
d51ea997
Zhao Shuaihua
升级玩手机、雨棚模型;模型批处理;...
|
191
192
|
if (id_to_mn_.count(id)) id_to_mn_.erase(id);
}
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
193
194
195
|
return res;
}
|
d281e3a2
Zhao Shuaihua
-增加非机动车逆行(513)、机动...
|
196
|
bool TruckMannedProcess::update_mstreams(const std::vector<task_id_t>& taskIds, vector<DeviceMemory*> vec_det_input_images, map<OBJ_KEY, OBJ_INDEX> &m_total_obj_info, const std::vector<onelevel_det_result> &det_results)
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
{
if (!check_initied())
return false;
if (det_results.empty())
{
LOG_DEBUG("detection result is empty.");
return false;
}
int n_images = det_results.size(); // or n_stream
unsigned flattened_idx = 0;
std::map<int, int> flattened_idx_to_batch_idx;
/* 1. Crop & keep some interest class. */
auto taskId_iter = taskIds.begin();
std::vector<sy_img> flattened_imgs(0);
std::vector<vpc_img_info> flattened_vpc_imgs(0);
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
216
217
|
std::vector<sy_img> flattened_vpose_imgs(0);
std::vector<vpc_img_info> flattened_vpc_vpose_imgs(0);
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
218
219
220
221
222
223
224
225
226
227
|
std::vector<input_data_wrap_t> flattened_interest_data(0); //
VPCUtil* pVpcUtil = VPCUtil::getInstance();
for (int n = 0; n < n_images; ++n)
{
int n_interest_obj = 0;
auto& src_img = vec_det_input_images[n];
int src_img_w = src_img->getWidth();
int src_img_h = src_img->getHeight();
auto& boxes_of_one_image = det_results[n].obj;
|
fa818303
Zhao Shuaihua
增加闯红灯功能(特定场景);优化货...
|
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
//汇总当前帧的行人/非机动车目标
std::vector<input_data_wrap_t> person_motocycle_data(0);
for (int i = 0; i < det_results[n].obj_count; ++i)
{
auto& box = boxes_of_one_image[i];
if (static_cast<det_class_label_t>(box.index) == det_class_label_t::MOTOCYCLE || static_cast<det_class_label_t>(box.index) == det_class_label_t::BICYCLE ||
static_cast<det_class_label_t>(box.index) == det_class_label_t::HUMAN || static_cast<det_class_label_t>(box.index) == det_class_label_t::TRICYCLE)
{
auto& taskId = *taskId_iter;
input_data_wrap_t data;
int top = std::max(int(box.top), 0); int left = std::max(int(box.left), 0);
int right = std::min(int(box.right), src_img_w); int bottom = std::min(int(box.bottom), src_img_h);
int width = right - left; int height = bottom - top;
if (static_cast<det_class_label_t>(box.index) == det_class_label_t::HUMAN && width >= 0.9*height) //基于载人只能看到半身的假设
continue;
data.box.top = top; data.box.left = left;
data.box.right = right; data.box.bottom = bottom;
data.box.score = box.confidence; data.box.cls = box.index;
data.taskId = taskId; data.objId = box.id;
person_motocycle_data.emplace_back(std::move(data));
}
}
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
for (int i = 0; i < det_results[n].obj_count; ++i)
{
auto& box = boxes_of_one_image[i];
if (static_cast<det_class_label_t>(box.index) == det_class_label_t::TRUCK)
{
auto& taskId = *taskId_iter;
auto algor_param_wrap = task_param_manager_->get_task_other_param(taskId, this->algor_type_);
if (!algor_param_wrap)
{
LOG_ERROR("{} is nullptr when get algor param from task_param", taskId.c_str());
continue;
}
auto algor_param = ((algor_param_type)algor_param_wrap->algor_param);
input_data_wrap_t data;
int top = std::max(int(box.top - (IMAGE_CROP_EXPAND_RATIO * box.top)), 0);
int left = std::max(int(box.left - (IMAGE_CROP_EXPAND_RATIO * box.left)), 0);
int right = std::min(int(box.right + (IMAGE_CROP_EXPAND_RATIO * box.right)), src_img_w);
int bottom = std::min(int(box.bottom + (IMAGE_CROP_EXPAND_RATIO * box.bottom)), src_img_h);
int width = right - left;
int height = bottom - top;
if ((width < algor_param->obj_min_width || height < algor_param->obj_min_height || box.confidence < algor_param->obj_confidence_threshold) ||
!snapshot_legal_inarea(algor_param_wrap->basic_param->algor_valid_rect, left, top, right, bottom))
continue;
|
fa818303
Zhao Shuaihua
增加闯红灯功能(特定场景);优化货...
|
283
284
|
//统计货车检测框内行人及非机动车的数量
int person_motocycle_inarea = legal_person_motocycle_inarea(person_motocycle_data, left, top, right, bottom);
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
//vpose=========================================================================================================
int x_center = round(float((right + left))/2);
int y_center = round(float((bottom + top))/2);
float llength = std::max(right -left, bottom - top);
// Crop image according to the supplied bounding box.
int ul[2]={0}; int br[2]={0};
vpose_transform(1, 1, x_center, y_center, llength, 1, ul); // Upper left point
vpose_transform(IMG_RES+1, IMG_RES+1, x_center, y_center, llength, 1, br); // Bottom right point
int vpose_left = std::max(-ul[0],0); int vpose_top = std::max(-ul[1],0);
int vpose_right = std::min(br[0], src_img_w) - ul[0];
int vpose_bottom = std::min(br[1], src_img_h) - ul[1];
int vpose_width = vpose_right - vpose_left;
int vpose_height = vpose_bottom - vpose_top;
if (vpose_width != vpose_height) continue; // 宽高不相等说明处于边缘位置,不处理
//=============================================================================================================
data.box.top = top; data.box.left = left;
data.box.right = right; data.box.bottom = bottom;
|
836a7b9c
Zhao Shuaihua
-不再保存非最佳抓拍图之外的抓拍小...
|
305
|
data.box.score = box.confidence; data.box.cls = box.index;
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
306
|
data.taskId = taskId; data.objId = box.id;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
307
|
data.id = obj_key_t{ box.id, taskId, algorithm_type_t::TRUCK_MANNED };
|
fa818303
Zhao Shuaihua
增加闯红灯功能(特定场景);优化货...
|
308
|
data.person_motocycle_cnt = person_motocycle_inarea;
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
309
310
311
|
data.vpose_box.top = vpose_top; data.vpose_box.left = vpose_left;
data.vpose_box.right = vpose_right; data.vpose_box.bottom = vpose_bottom;
data.x_center = x_center; data.y_center = y_center; data.llength = llength;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
312
313
314
315
316
|
// 抠图
video_object_info obj;
strcpy(obj.task_id, taskId.c_str());
obj.object_id = box.id;
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
317
|
obj.left = left; obj.top = top; obj.right = right; obj.bottom = bottom;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
318
319
320
321
|
vpc_img_info img_info = pVpcUtil->crop(src_img, obj);
sy_img img;
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
322
|
img.w_ = width; img.h_ = height; img.c_ = src_img->getChannel();
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
323
324
325
326
327
328
329
330
331
332
|
if (img_info.pic_desc != nullptr) {
void *outputDataDev = acldvppGetPicDescData(img_info.pic_desc);
img.data_ = reinterpret_cast<unsigned char*>(outputDataDev);
}
else {
LOG_ERROR("Crop image NPU failed wh is [{}, {}] ltrb is [{} {} {} {}]",
src_img_w, src_img_h, data.box.left, data.box.top, data.box.right, data.box.bottom);
continue;
}
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
// vpose抠图
video_object_info vpose_obj;
strcpy(vpose_obj.task_id, taskId.c_str());
vpose_obj.object_id = box.id;
vpose_obj.left = vpose_left; vpose_obj.top = vpose_top; vpose_obj.right = vpose_right; vpose_obj.bottom = vpose_bottom;
vpc_img_info vpose_img_info = pVpcUtil->crop(src_img, vpose_obj);
sy_img vpose_img;
vpose_img.w_ = vpose_width; vpose_img.h_ = vpose_height; vpose_img.c_ = src_img->getChannel();
if (vpose_img_info.pic_desc != nullptr) {
void *outputDataDev = acldvppGetPicDescData(vpose_img_info.pic_desc);
vpose_img.data_ = reinterpret_cast<unsigned char*>(outputDataDev);
}
else {
LOG_ERROR("Crop image NPU failed wh is [{}, {}] ltrb is [{} {} {} {}]",
src_img_w, src_img_h, data.vpose_box.left, data.vpose_box.top, data.vpose_box.right, data.vpose_box.bottom);
VPCUtil::vpc_img_release(img_info);
continue;
}
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
355
356
357
|
flattened_imgs.emplace_back(std::move(img));
flattened_vpc_imgs.emplace_back(std::move(img_info));
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
358
359
|
flattened_vpose_imgs.emplace_back(std::move(vpose_img)); //vpose
flattened_vpc_vpose_imgs.emplace_back(std::move(vpose_img_info)); //vpose
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
360
361
362
363
|
flattened_interest_data.emplace_back(std::move(data));
flattened_idx_to_batch_idx[flattened_idx++] = n;
}
}
|
fa818303
Zhao Shuaihua
增加闯红灯功能(特定场景);优化货...
|
364
|
std::vector<input_data_wrap_t>().swap(person_motocycle_data);
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
365
366
367
368
369
370
371
372
373
374
|
++taskId_iter;
}
int ret = aclrtSetCurrentContext(m_algorthim_ctx);
if (ACL_SUCCESS != ret) {
return false;
}
/* 2. collection result. */
int n_input_image = flattened_imgs.size();
hs_truck_result model_results[n_input_image];
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
375
|
vehicle_pose_result vpose_results[n_input_image];
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
376
377
378
379
380
381
|
{
int steps = (n_input_image + MAX_BATCH - 1) / MAX_BATCH;
for (int step = 0; step < steps; ++step)
{
int offset = step * MAX_BATCH;
int batch_size = (step == steps - 1) ? n_input_image - offset : MAX_BATCH;
|
d51ea997
Zhao Shuaihua
升级玩手机、雨棚模型;模型批处理;...
|
382
383
|
// hs_truck_process_batch(hs_tools_, flattened_imgs.data() + offset, batch_size, model_results + offset);
hs_truck_process_batchV2(hs_tools_, flattened_imgs.data() + offset, batch_size, model_results + offset);
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
384
|
vehicle_pose_batch(vpose_tools_, flattened_vpose_imgs.data() + offset, batch_size, vpose_results + offset);
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
385
386
387
388
389
390
391
392
393
394
395
396
397
|
}
}
/* 3. postprocess. */
{
for (int n = 0; n < n_input_image; ++n)
{
auto& det_result = flattened_interest_data[n];
auto& objId = det_result.objId;
if (id_to_result_.find(det_result.id) != id_to_result_.end())
{
VPCUtil::vpc_img_release(flattened_vpc_imgs[n]); //flattened_imgs[n].data_
flattened_imgs[n].data_ = nullptr;
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
398
399
|
VPCUtil::vpc_img_release(flattened_vpc_vpose_imgs[n]);
flattened_vpose_imgs[n].data_ = nullptr;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
400
401
402
403
404
405
406
407
408
409
410
|
continue;
}
const auto& src_img = vec_det_input_images[flattened_idx_to_batch_idx[n]];
auto algor_param_wrap = task_param_manager_->get_task_other_param(det_result.taskId, this->algor_type_);
if (!algor_param_wrap)
{
LOG_ERROR("{} nullptr when get algor param from task_param", det_result.taskId.c_str());
VPCUtil::vpc_img_release(flattened_vpc_imgs[n]); //flattened_imgs[n].data_
flattened_imgs[n].data_ = nullptr;
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
411
412
|
VPCUtil::vpc_img_release(flattened_vpc_vpose_imgs[n]);
flattened_vpose_imgs[n].data_ = nullptr;
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
413
414
415
416
417
418
419
420
421
422
423
424
|
continue;
}
auto algor_param = ((algor_param_type)algor_param_wrap->algor_param);
int hs_count = model_results[n].objcount;
obj_key_t obj_key{ det_result.objId, det_result.taskId, algorithm_type_t::TRUCK_MANNED };
auto& e = id_to_mn_[obj_key];
++e.m_frame;
|
d281e3a2
Zhao Shuaihua
-增加非机动车逆行(513)、机动...
|
425
426
427
428
429
430
431
432
433
|
// 过滤停车的货车
{
OBJ_KEY trace_obj_key = {det_result.taskId, objId};
int stop_check_frames = 30; // 6s
float stop_min_move = 25;
// 时间太短,忽略
if (m_total_obj_info[trace_obj_key].center_points.size() > stop_check_frames) {
float res_max_dist = 0;
float total_dist = diff_car_pos(m_total_obj_info[trace_obj_key].center_points, stop_check_frames, res_max_dist);
|
12fade9b
Zhao Shuaihua
修复货车载人显存泄露bug
|
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
if (res_max_dist < stop_min_move) { // 停车
VPCUtil::vpc_img_release(flattened_vpc_imgs[n]); //flattened_imgs[n].data_
flattened_imgs[n].data_ = nullptr;
VPCUtil::vpc_img_release(flattened_vpc_vpose_imgs[n]);
flattened_vpose_imgs[n].data_ = nullptr;
continue;
}
}
else {
VPCUtil::vpc_img_release(flattened_vpc_imgs[n]); //flattened_imgs[n].data_
flattened_imgs[n].data_ = nullptr;
VPCUtil::vpc_img_release(flattened_vpc_vpose_imgs[n]);
flattened_vpose_imgs[n].data_ = nullptr;
continue;
|
d281e3a2
Zhao Shuaihua
-增加非机动车逆行(513)、机动...
|
448
|
}
|
d281e3a2
Zhao Shuaihua
-增加非机动车逆行(513)、机动...
|
449
450
|
}
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
//vpose===========================================================
auto &vpose_result = vpose_results[n]; // vpose
int ldmk_x1 = src_img->getWidth(), ldmk_y1 = src_img->getHeight(), ldmk_x2 = 0, ldmk_y2 = 0;
for (int p = 0; p < LDMK_COUNT; p++) {
int ul[2]={0};
// 映射到大图
vpose_transform(vpose_result.vehicle_ldmk[p].x_-1, vpose_result.vehicle_ldmk[p].y_-1, det_result.x_center, det_result.y_center, det_result.llength, 1, ul);
ldmk_x1 = std::min(ul[0] + 1, ldmk_x1);
ldmk_y1 = std::min(ul[1] + 1, ldmk_y1);
ldmk_x2 = std::max(ul[0] + 1, ldmk_x2);
ldmk_y2 = std::max(ul[1] + 1, ldmk_y2);
}
// 统计关键点映射出的四边形中的头肩数量
int hs_inpose_count = 0;
if (ldmk_x2 > ldmk_x1 && ldmk_y2 > ldmk_y1) {
for (int i = 0; i < model_results[n].objcount; i++) {
int x1_intersection = std::max(det_result.box.left + model_results[n].objinfo[i].left, ldmk_x1);
int y1_intersection = std::max(det_result.box.top + model_results[n].objinfo[i].top, ldmk_y1);
int x2_intersection = std::min(det_result.box.left + model_results[n].objinfo[i].right, ldmk_x2);
int y2_intersection = std::min(det_result.box.top + model_results[n].objinfo[i].bottom, ldmk_y2);
if (x2_intersection <= x1_intersection || y2_intersection <= y1_intersection) continue; // 没有交集
hs_inpose_count ++;
}
}
//=================================================================
|
d281e3a2
Zhao Shuaihua
-增加非机动车逆行(513)、机动...
|
478
|
|
fa818303
Zhao Shuaihua
增加闯红灯功能(特定场景);优化货...
|
479
|
// if (hs_count >= algor_param->hs_count_threshold)
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
480
481
|
LOG_INFO("hs_count:{} hs_inpose_count: {} person_motocycle_cnt:{} threshold: {}", hs_count, hs_inpose_count, det_result.person_motocycle_cnt, algor_param->hs_count_threshold);
// if (hs_count - det_result.person_motocycle_cnt >= algor_param->hs_count_threshold) //头肩数量去除包含的行人和非机动车数量
|
02e5e637
Zhao Shuaihua
增加行人/非机动车占机动车道(50...
|
482
483
484
|
// if (hs_count - det_result.person_motocycle_cnt >= algor_param->hs_count_threshold || hs_inpose_count >= algor_param->hs_count_threshold)
if (hs_inpose_count >= algor_param->hs_count_threshold) //1025
{
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
485
486
487
488
489
490
491
|
if (++e.n_frame == algor_param->n)
{
results_data_t result;
{
result.box = det_result.box;
result.taskId = det_result.taskId;
result.objId = det_result.objId;
|
d1221b31
Zhao Shuaihua
优化显存占用,暂不缓存报警时刻的抓拍图
|
492
|
#if 0 /*暂不保存报警时刻的抓拍图,有需要再启用*/
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
493
494
495
496
497
|
// 原图
vpc_img_info src_img_info = VPCUtil::vpc_devMem2vpcImg(src_img);
result.origin_img_desc = src_img_info.pic_desc;
// 抠图
result.roi_img_desc = flattened_vpc_imgs[n].pic_desc;
|
d1221b31
Zhao Shuaihua
优化显存占用,暂不缓存报警时刻的抓拍图
|
498
499
500
|
#else
VPCUtil::vpc_img_release(flattened_vpc_imgs[n]);
#endif
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
501
502
503
504
505
506
507
508
509
510
511
512
|
}
id_to_result_.emplace(obj_key, std::move(result));
goto _continue;
}
}
if (e.m_frame == algor_param->m)
e.reset();
VPCUtil::vpc_img_release(flattened_vpc_imgs[n]); //flattened_imgs[n].data_
_continue:
{
|
27f0a463
Zhao Shuaihua
玩手机模型升级 货车载人增加关键点辅助
|
513
|
VPCUtil::vpc_img_release(flattened_vpc_vpose_imgs[n]);
|
9c03cbe4
Zhao Shuaihua
增加三轮车/货车载人 二轮车超员/...
|
514
515
516
517
518
519
520
521
522
523
524
525
|
}
}
}
return true;
}
} // namespace truck_manned_process
} // namespace ai_engine_module
|