Blame view

src/reprocessing_module/snapshot_reprocessing.cpp 40 KB
09c2d08c   Hu Chunming   arm交付版
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
136
137
138
139
140
141
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
  #include "snapshot_reprocessing.h"
  
  #include "../common/logger.hpp"
  #include "../ai_platform/mvpt_process_assist.h"
  #include "../decoder/interface/DeviceMemory.hpp"
  
  
  snapshot_reprocessing::snapshot_reprocessing(int devId)
  {
  	m_task_param_manager = task_param_manager::getInstance();
  
  	algor_index_table["human"] = { (int)det_class_label_t::HUMAN };
  	algor_index_table["nonmotor_vehicle"] = { (int)det_class_label_t::BICYCLE, (int)det_class_label_t::MOTOCYCLE, (int)det_class_label_t::TRICYCLE };
  	algor_index_table["vehicle"] = { (int)det_class_label_t::SMALL_CAR, (int)det_class_label_t::LARGE_CAR, (int)det_class_label_t::TRUCK, (int)det_class_label_t::TRACTOR, (int)det_class_label_t::MEDIUM_BUS };
  }
  
  snapshot_reprocessing::~snapshot_reprocessing()
  {
  }
  
  static void box_expansion(video_object_info& obj_info, float expand_ratio, int frame_width, int frame_height){
  	int origin_width = obj_info.right - obj_info.left;
  	int origin_height = obj_info.bottom - obj_info.top;
  
  	int expansion_width = origin_width * expand_ratio;
  	int expansion_height = origin_height * expand_ratio;
  
  	obj_info.left = max(obj_info.left - expansion_width, 0);
  	obj_info.top = max(obj_info.top - expansion_height, 0);
  	obj_info.right = min(obj_info.right + expansion_width, frame_width - 1);
  	obj_info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1);
  }
  
  /* 获取人车物目标快照图 */
  vector<multi_obj_data_t> snapshot_reprocessing::get_vehicle_snapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& ol_det_result, int skip_frame)
  {
  	// 过滤出车辆
  	filter_vehicle(ol_det_result);
  
  	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();
  
  	vector<multi_obj_data_t> results;
  	int idx = 0;
  	for (auto memPtr : vec_devMem)
  	{
  		string task_id = memPtr->getId();
  		map<string, std::vector<video_object_info>> taskid_to_obj;
  		if (algor_config_param.count(task_id) && algor_config_param[task_id].vehicle_algors.count(algorithm_type_t::VEHICLE_SNAPSHOT))
  		{
  			task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algorithm_type_t::VEHICLE_SNAPSHOT];
  
  			// 同一目标间隔多少帧保存
  			int snap_frame_interval = ((algor_config_param_snapshot*)cur_task_params->algor_param)->snap_frame_interval;
  
  			onelevel_det_result &cur_task_ol_detres = ol_det_result[idx];
  
  			for (int c = 0; c < cur_task_ol_detres.obj_count; c++)
  			{
  				det_objinfo det_obj = cur_task_ol_detres.obj[c];
  				if(snap_frame_interval > 0 && det_obj.num % snap_frame_interval >= skip_frame){
  					continue;
  				}
  				int type_index = det_obj.index; 
  				if ((type_index == 4 || type_index == 5 || type_index == 6 || type_index ==7 || type_index ==8)
  					&& snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect, det_obj.left, det_obj.top, det_obj.right, det_obj.bottom))
  				{
  					video_object_info obj_info;
  					obj_info.top = det_obj.top;
  					obj_info.left = det_obj.left;
  					obj_info.right = det_obj.right;
  					obj_info.bottom = det_obj.bottom;
  					obj_info.confidence = det_obj.confidence;
  					obj_info.index = type_index;
  					obj_info.object_id = det_obj.id;
  
  					int frame_height = memPtr->getHeight();
  					int frame_width = memPtr->getWidth();
  					box_expansion(obj_info, EXPANSION_PROPORTION, frame_width, frame_height);
  
  					taskid_to_obj[task_id].emplace_back(std::move(obj_info));
  				}
  			}
  
  			if (taskid_to_obj.size() > 0)
  			{
  				static long long gid_ = 0;
  
  				multi_obj_data_t data;
  				data.memPtr = memPtr;
  				data.task_id = task_id;
  				data.objs = std::move(taskid_to_obj[task_id]);
  				data.id = gid_++;
  				results.emplace_back(std::move(data));
  				LOG_TRACE("{} {} snap_frame_interval:{}", task_id.c_str(), (int)algorithm_type_t::VEHICLE_SNAPSHOT, snap_frame_interval);
  			}
  		}
  
  		idx++;
  	}
  	return results;
  }
  
  void snapshot_reprocessing::screen_effective_snapshot(vector<onelevel_det_result> &_onelevel_det_result){
  	map<string, algor_open_config_param> algor_param = m_task_param_manager->get_task_algor_params();
  
  	for (auto det_result : _onelevel_det_result)
  	{
  		int effective_count = 0;
  		int effective_idx = 0;
  		string taskid = det_result.task_id;
  
  		det_objinfo *tmp_det_objinfo =det_result.obj;
  
  		for (int c = 0; c < det_result.obj_count; c++)
  		{
  			// if (algor_index_table["human"].find(tmp_det_objinfo[c].index) != algor_index_table["human"].end()
  			// 	&& (!algor_param[taskid].human_algors.empty() || !algor_param[taskid].human_face_algors.empty()))  // 此处行人和人脸存在耦合,若同一路任务配置了人脸没有配置行人,存抓拍图时会出错
  			if (algor_index_table["human"].find(tmp_det_objinfo[c].index) != algor_index_table["human"].end()
  				&& (!algor_param[taskid].human_algors.empty())) // modified by zsh 220714
  			{
  				tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c];
  				effective_count++;
  			}
  
  			if (algor_index_table["nonmotor_vehicle"].find(tmp_det_objinfo[c].index) != algor_index_table["nonmotor_vehicle"].end()
  				&& !algor_param[taskid].nonmotor_vehicle_algors.empty())
  			{
  				tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c];
  				effective_count++;
  			}
  
  			if (algor_index_table["vehicle"].find(tmp_det_objinfo[c].index) != algor_index_table["vehicle"].end()
  				&& !algor_param[taskid].vehicle_algors.empty())
  			{
  				tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c];
  				effective_count++;
  			}
  		}
  
  		det_result.obj_count = effective_count;
  	}
  }
  
  void snapshot_reprocessing::filter_vehicle(vector<onelevel_det_result> &_onelevel_det_result){
  	map<string, algor_open_config_param> algor_param = m_task_param_manager->get_task_algor_params();
  
  	for (auto det_result : _onelevel_det_result){
  		string taskid = det_result.task_id;
  
  		int effective_count = 0;
  		int effective_idx = 0;
  
  		det_objinfo *tmp_det_objinfo = det_result.obj;
  
  		for (int c = 0; c < det_result.obj_count; c++)
  		{
  			if (algor_index_table["vehicle"].find(tmp_det_objinfo[c].index) != algor_index_table["vehicle"].end()
  				&& !algor_param[taskid].vehicle_algors.empty())
  			{
  				tmp_det_objinfo[effective_idx++] = tmp_det_objinfo[c];
  				effective_count++;
  			}
  		}
  
  		det_result.obj_count = effective_count;
  	}
  }
  
  /* 获取人车物目标快照图 */
  void snapshot_reprocessing::update_bestsnapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &ol_det_result, vector<vector<int>>& delete_object_id){
  	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();
  
  	VPCUtil* pVpcUtil = VPCUtil::getInstance();
  
  	for (size_t i = 0; i < vec_devMem.size(); i++){
  
  		onelevel_det_result det_result = ol_det_result[i];
  		if (0 == det_result.obj_count){
  			continue;
  		}
  
  		DeviceMemory* memPtr = vec_devMem[i];
  
  		string task_id = memPtr->getId();
  		int frame_height = memPtr->getHeight();
  		int frame_width = memPtr->getWidth();
  
  		vector<video_object_info> vec_obj_info;
  		for (int c = 0; c < det_result.obj_count; c++){
  		
  			det_objinfo obj_info = det_result.obj[c];
  			OBJ_KEY new_obj = { task_id, obj_info.id };
  
  			int index = 0;
  
  			/* 投票确定目标index */
  			if (total_snapshot_info.find(new_obj) == total_snapshot_info.end()){
  				index = obj_info.index;
  			} else {
  				index = total_snapshot_info[new_obj].index.index;
  			}
  
  			int cur_real_width = (obj_info.right - obj_info.left);
  			int cur_real_height = (obj_info.bottom - obj_info.top);
  			int cur_real_index = obj_info.index;
  
  			int expansion_width = cur_real_width * EXPANSION_PROPORTION;
  			int expansion_height = cur_real_height * EXPANSION_PROPORTION;
  			// DEBUG-----------------------------------------------------------------
  			// 0-行人 1-自行车 2-摩托车 3-三轮车 4-小型车 5-大车 6-卡车 7-拖拉机 8-中巴
  			if(index ==0 || index ==1 || index ==2 || index ==3) { //行人和非机动车外扩指定像素即可
  				expansion_width = 10;
  				expansion_height = 10;
  			}
  
  			/* 若该目标第一次出现 */
  			if (total_snapshot_info.find(new_obj) == total_snapshot_info.end())
  			{
  				/* manager insert new object. */
  				/* 判断目标合法 */
  				algorithm_type_t algor_type;
  				if (index ==0) algor_type = algorithm_type_t::HUMAN_SNAPSHOT;
  				if (index ==1 || index ==2 || index ==3) algor_type = algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT;
  				if (index ==4 || index ==5 || index ==6 || index ==7 || index ==8) algor_type = algorithm_type_t::VEHICLE_SNAPSHOT;
  				if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algor_type)))
  					continue;
  				task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type];
  				if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left, obj_info.top, obj_info.right, obj_info.bottom)){
  					continue;
  				}
  					
  				if(!snapshot_legal_minarea(index, cur_real_width, cur_real_height)){
  					continue;
  				}
  
  				/* 存入当前抠图目标参数 flags用于判断目标从画面什么位置出现 方便之后排除出画面边缘的快照图 */
  				total_snapshot_info[new_obj].index.count++;
  				total_snapshot_info[new_obj].index.index = cur_real_index;
  				total_snapshot_info[new_obj].confidence = obj_info.confidence;
  				total_snapshot_info[new_obj].flags[0] = obj_info.left < minDistance[0] + SCALE_OUT ? 0 : 1;           //left
  				total_snapshot_info[new_obj].flags[1] = obj_info.top < minDistance[1] + SCALE_OUT ? 0 : 1;            //top
  				total_snapshot_info[new_obj].flags[2] = obj_info.right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1;   //right
  				total_snapshot_info[new_obj].flags[3] = obj_info.bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1;     //bottom
  
  				int cur_left = max(obj_info.left - 10, 0);
  				int cur_top = max(obj_info.top - 10, 0);
  				int cur_right = min(obj_info.right + 10, frame_width - 1);
  				int cur_bottom = min(obj_info.bottom + 10, frame_height - 1);
  				total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素
  				total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top);
  
  				video_object_info info;
  				info.left = max(obj_info.left - expansion_width, 0);
  				info.top = max(obj_info.top - expansion_height, 0);
  				info.right = min(obj_info.right + expansion_width, frame_width - 1);
  				info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1);
  				strcpy(info.task_id, task_id.c_str());
  				info.object_id = obj_info.id;
  				info.confidence = obj_info.confidence;
  				info.index = index;
  
  				vec_obj_info.push_back(info);
  			} else {
  				total_snapshot_info[new_obj].last_area = (obj_info.right - obj_info.left) * (obj_info.bottom - obj_info.top);
  
  				algorithm_type_t algor_type;
  				if (index ==0) algor_type = algorithm_type_t::HUMAN_SNAPSHOT;
  				if (index ==1 || index ==2 || index ==3) algor_type = algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT;
  				if (index ==4 || index ==5 || index ==6 || index ==7 || index ==8) algor_type = algorithm_type_t::VEHICLE_SNAPSHOT;
  				if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algor_type)))
  					continue;
  				task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type];
  				if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left, obj_info.top, obj_info.right, obj_info.bottom))
  					continue;	
  				//---------------------------------------------------------------
  				if (!best_snapshot_judge_algor(new_obj, total_snapshot_info[new_obj], obj_info.left, obj_info.top,
  					cur_real_width, cur_real_height, frame_width, frame_height))
  				{
  					continue;
  				}
  				/* 若更优于之前的快照 做快照的更新 */
  				if (total_snapshot_info[new_obj].index.count == 0)
  				{
  					total_snapshot_info[new_obj].index.count++;
  					total_snapshot_info[new_obj].index.index = cur_real_index;
  				}
  				else
  				{
  					if (total_snapshot_info[new_obj].index.index == cur_real_index)
  						total_snapshot_info[new_obj].index.count++;
  					else
  						total_snapshot_info[new_obj].index.count--;
  				}
  
  				int cur_left = max(obj_info.left - 10, 0);
  				int cur_top = max(obj_info.top - 10, 0);
  				int cur_right = min(obj_info.right + 10, frame_width - 1);
  				int cur_bottom = min(obj_info.bottom + 10, frame_height - 1);
  				total_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素
  				total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top);
  
  				video_object_info info;
  				info.left = max(obj_info.left - expansion_width, 0);
  				info.top = max(obj_info.top - expansion_height, 0);
  				info.right = min(obj_info.right + expansion_width, frame_width - 1);
  				info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1);
  				strcpy(info.task_id, task_id.c_str());
  				info.object_id = obj_info.id;
  				info.confidence = obj_info.confidence;
  				info.index = index;
  
  				vec_obj_info.push_back(info);
  			}
  		}
  
  		vector<vpc_img_info> imgList = pVpcUtil->crop_batch(memPtr, vec_obj_info);
  		vec_obj_info.clear();
  
  		for (size_t i = 0; i < imgList.size(); i++) {
  			vpc_img_info obj_info = imgList[i];
  			OBJ_KEY objKey = { obj_info.task_id, obj_info.object_id };
  			VPCUtil::vpc_img_release(total_snapshot_info[objKey].snapShot);
  			total_snapshot_info[objKey].snapShot = VPCUtil::vpc_devMem2vpcImg(memPtr);
  			VPCUtil::vpc_img_release(total_snapshot_info[objKey].snapShotLittle);
  			total_snapshot_info[objKey].snapShotLittle = obj_info;
  		}
  		imgList.clear();
  	}
  }
  
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
  
  /* 获取农村违法分析要求的目标快照图--轨迹起始 最佳 轨迹结束 */
  void snapshot_reprocessing::update_village_bestsnapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &ol_det_result, vector<vector<int>>& delete_object_id){
  	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();
  
  	VPCUtil* pVpcUtil = VPCUtil::getInstance();
  
  	for (size_t i = 0; i < vec_devMem.size(); i++){
  
  		onelevel_det_result det_result = ol_det_result[i];
  		if (0 == det_result.obj_count){
  			continue;
  		}
  
  		DeviceMemory* memPtr = vec_devMem[i];
  
  		string task_id = memPtr->getId();
  		int frame_height = memPtr->getHeight();
  		int frame_width = memPtr->getWidth();
  
  		vector<video_object_info> vec_obj_info;
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
355
  		vector<video_object_info> last_vec_obj_info;
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
356
357
358
359
360
361
362
363
364
365
366
  		for (int c = 0; c < det_result.obj_count; c++){
  		
  			det_objinfo obj_info = det_result.obj[c];
  			OBJ_KEY new_obj = { task_id, obj_info.id };
  
  			int index = 0;
  
  			/* 投票确定目标index */
  			if (total_village_snapshot_info.find(new_obj) == total_village_snapshot_info.end()){
  				index = obj_info.index;
  			} else {
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
367
  				index = total_village_snapshot_info[new_obj].snapShots[1].index.index;
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
  			}
  
  			int cur_real_width = (obj_info.right - obj_info.left);
  			int cur_real_height = (obj_info.bottom - obj_info.top);
  			int cur_real_index = obj_info.index;
  
  			int expansion_width = cur_real_width * EXPANSION_PROPORTION;
  			int expansion_height = cur_real_height * EXPANSION_PROPORTION;
  			// DEBUG-----------------------------------------------------------------
  			// 0-行人 1-自行车 2-摩托车 3-三轮车 4-小型车 5-大车 6-卡车 7-拖拉机 8-中巴
  			if(index ==0 || index ==1 || index ==2 || index ==3) { //行人和非机动车外扩指定像素即可
  				expansion_width = 10;
  				expansion_height = 10;
  			}
  
  			/* 若该目标第一次出现 */
  			if (total_village_snapshot_info.find(new_obj) == total_village_snapshot_info.end())
  			{
  				/* manager insert new object. */
  				/* 判断目标合法 */
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
388
389
390
  				if (!(algor_config_param.count(task_id) && algor_param.count(task_id)))
  					continue;
  				if (!(algor_param[task_id].count(algorithm_type_t::TRICYCLE_MANNED) || algor_param[task_id].count(algorithm_type_t::TRUCK_MANNED) || 
02e5e637   Zhao Shuaihua   增加行人/非机动车占机动车道(50...
391
392
393
394
  				algor_param[task_id].count(algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN) ||
  				algor_param[task_id].count(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) ||
  				algor_param[task_id].count(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) ||
  				algor_param[task_id].count(algorithm_type_t::PERSON_IN_VEHICLELANE) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_IN_VEHICLELANE) ||
d281e3a2   Zhao Shuaihua   -增加非机动车逆行(513)、机动...
395
  				algor_param[task_id].count(algorithm_type_t::NONMOTOR_CEOSSPARKLINE) || algor_param[task_id].count(algorithm_type_t::PERSON_CROSS) ||
b283714b   Zhao Shuaihua   增加机动车不让行功能(516)
396
397
398
  				algor_param[task_id].count(algorithm_type_t::NONMOTOR_WRONGDIRECTION) || algor_param[task_id].count(algorithm_type_t::VEHICLE_WRONGDIRECTION) ||
  				algor_param[task_id].count(algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) || algor_param[task_id].count(algorithm_type_t::VEHICLE_NOTGIVEWAY) ||
  				algor_param[task_id].count(algorithm_type_t::VEHICLE_NOTDECELERATION)))
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
399
400
  					continue;
  			
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
401
402
403
  				if(!snapshot_legal_minarea(index, cur_real_width, cur_real_height)){
  					continue;
  				}
c5fce6ce   Zhao Shuaihua   增加二轮车玩手机505、加装雨棚5...
404
405
406
407
  				// 过滤边缘位置
  				if(obj_info.left < 80 || obj_info.top < 50 || (obj_info.right > frame_width - 80) || (obj_info.bottom > frame_height - 50)){
  					continue;
  				}
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
408
  				total_village_snapshot_info[new_obj].exists[1] = true;
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
409
  				/* 存入当前抠图目标参数 flags用于判断目标从画面什么位置出现 方便之后排除出画面边缘的快照图 */
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
410
411
412
413
414
415
416
  				total_village_snapshot_info[new_obj].snapShots[1].index.count++;
  				total_village_snapshot_info[new_obj].snapShots[1].index.index = cur_real_index;
  				total_village_snapshot_info[new_obj].snapShots[1].confidence = obj_info.confidence;
  				total_village_snapshot_info[new_obj].snapShots[1].flags[0] = obj_info.left < minDistance[0] + SCALE_OUT ? 0 : 1;           //left
  				total_village_snapshot_info[new_obj].snapShots[1].flags[1] = obj_info.top < minDistance[1] + SCALE_OUT ? 0 : 1;            //top
  				total_village_snapshot_info[new_obj].snapShots[1].flags[2] = obj_info.right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1;   //right
  				total_village_snapshot_info[new_obj].snapShots[1].flags[3] = obj_info.bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1;     //bottom
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
417
418
419
420
421
  
  				int cur_left = max(obj_info.left - 10, 0);
  				int cur_top = max(obj_info.top - 10, 0);
  				int cur_right = min(obj_info.right + 10, frame_width - 1);
  				int cur_bottom = min(obj_info.bottom + 10, frame_height - 1);
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
422
423
  				total_village_snapshot_info[new_obj].snapShots[1].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素
  				total_village_snapshot_info[new_obj].snapShots[1].last_area = total_village_snapshot_info[new_obj].snapShots[1].max_area = (cur_right - cur_left) * (cur_bottom - cur_top);
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
424
425
426
427
428
429
430
431
432
433
434
  
  				video_object_info info;
  				info.left = max(obj_info.left - expansion_width, 0);
  				info.top = max(obj_info.top - expansion_height, 0);
  				info.right = min(obj_info.right + expansion_width, frame_width - 1);
  				info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1);
  				strcpy(info.task_id, task_id.c_str());
  				info.object_id = obj_info.id;
  				info.confidence = obj_info.confidence;
  				info.index = index;
  
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
435
436
437
  				vec_obj_info.push_back(info);//用于最佳抓拍图
  
  				// 首张抓拍图:切图+信息存储
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
438
439
440
441
442
  				total_village_snapshot_info[new_obj].exists[0] = true;
  				total_village_snapshot_info[new_obj].snapShots[0].index.index = cur_real_index;
  				total_village_snapshot_info[new_obj].snapShots[0].confidence = obj_info.confidence;
  				total_village_snapshot_info[new_obj].snapShots[0].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top };
  				total_village_snapshot_info[new_obj].snapShots[0].snapShot = VPCUtil::vpc_devMem2vpcImg(memPtr);
d8ebfce2   Zhao Shuaihua   调整抓拍图保存
443
444
  #if 0 /*暂不存最佳抓拍之外的小图*/
  				vpc_img_info crop_img = pVpcUtil->crop(memPtr, info);
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
445
  				total_village_snapshot_info[new_obj].snapShots[0].snapShotLittle = crop_img;
d8ebfce2   Zhao Shuaihua   调整抓拍图保存
446
  #endif
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
447
448
449
450
451
  				// 缓存末张抓拍图
  				total_village_snapshot_info[new_obj].exists[2] = true;
  				total_village_snapshot_info[new_obj].snapShots[2].index.index = cur_real_index;
  				total_village_snapshot_info[new_obj].snapShots[2].confidence = obj_info.confidence;
  				total_village_snapshot_info[new_obj].snapShots[2].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top };
d8ebfce2   Zhao Shuaihua   调整抓拍图保存
452
  #if 0 /*暂不存最佳抓拍之外的小图*/
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
453
  				last_vec_obj_info.push_back(info);
d8ebfce2   Zhao Shuaihua   调整抓拍图保存
454
455
456
  #else
  				total_village_snapshot_info[new_obj].snapShots[2].snapShot = VPCUtil::vpc_devMem2vpcImg(memPtr);
  #endif
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
457
  
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
458
  			} else {
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
459
460
461
462
463
  				total_village_snapshot_info[new_obj].snapShots[1].last_area = (obj_info.right - obj_info.left) * (obj_info.bottom - obj_info.top);
  
  				if (!(algor_config_param.count(task_id) && algor_param.count(task_id)))
  					continue;
  				if (!(algor_param[task_id].count(algorithm_type_t::TRICYCLE_MANNED) || algor_param[task_id].count(algorithm_type_t::TRUCK_MANNED) || 
02e5e637   Zhao Shuaihua   增加行人/非机动车占机动车道(50...
464
465
466
467
  				algor_param[task_id].count(algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN) ||
  				algor_param[task_id].count(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) ||
  				algor_param[task_id].count(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) ||
  				algor_param[task_id].count(algorithm_type_t::PERSON_IN_VEHICLELANE) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_IN_VEHICLELANE) ||
d281e3a2   Zhao Shuaihua   -增加非机动车逆行(513)、机动...
468
  				algor_param[task_id].count(algorithm_type_t::NONMOTOR_CEOSSPARKLINE) || algor_param[task_id].count(algorithm_type_t::PERSON_CROSS) ||
b283714b   Zhao Shuaihua   增加机动车不让行功能(516)
469
470
471
  				algor_param[task_id].count(algorithm_type_t::NONMOTOR_WRONGDIRECTION) || algor_param[task_id].count(algorithm_type_t::VEHICLE_WRONGDIRECTION) ||
  				algor_param[task_id].count(algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) || algor_param[task_id].count(algorithm_type_t::VEHICLE_NOTGIVEWAY) ||
  				algor_param[task_id].count(algorithm_type_t::VEHICLE_NOTDECELERATION)))
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
472
  					continue;
c5fce6ce   Zhao Shuaihua   增加二轮车玩手机505、加装雨棚5...
473
474
475
476
477
  				
  				// 过滤边缘位置
  				if(obj_info.left < 80 || obj_info.top < 50 || (obj_info.right > frame_width - 80) || (obj_info.bottom > frame_height - 50)){
  					continue;
  				}
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
478
479
480
481
482
  
  				int cur_left = max(obj_info.left - 10, 0);
  				int cur_top = max(obj_info.top - 10, 0);
  				int cur_right = min(obj_info.right + 10, frame_width - 1);
  				int cur_bottom = min(obj_info.bottom + 10, frame_height - 1);
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
483
  				
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
484
485
486
487
488
489
490
491
492
493
  				video_object_info info;
  				info.left = max(obj_info.left - expansion_width, 0);
  				info.top = max(obj_info.top - expansion_height, 0);
  				info.right = min(obj_info.right + expansion_width, frame_width - 1);
  				info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1);
  				strcpy(info.task_id, task_id.c_str());
  				info.object_id = obj_info.id;
  				info.confidence = obj_info.confidence;
  				info.index = index;
  
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
494
495
496
497
  				// 缓存末张抓拍图
  				total_village_snapshot_info[new_obj].snapShots[2].index.index = cur_real_index;
  				total_village_snapshot_info[new_obj].snapShots[2].confidence = obj_info.confidence;
  				total_village_snapshot_info[new_obj].snapShots[2].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top };
d8ebfce2   Zhao Shuaihua   调整抓拍图保存
498
  #if 0 /*暂不存最佳抓拍之外的小图*/
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
499
  				last_vec_obj_info.push_back(info);
d8ebfce2   Zhao Shuaihua   调整抓拍图保存
500
501
502
503
  #else
  				VPCUtil::vpc_img_release(total_village_snapshot_info[new_obj].snapShots[2].snapShot);
  				total_village_snapshot_info[new_obj].snapShots[2].snapShot = VPCUtil::vpc_devMem2vpcImg(memPtr);
  #endif
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
  				//---------------------------------------------------------------
  				if (!best_snapshot_judge_algor(new_obj, total_village_snapshot_info[new_obj].snapShots[1], obj_info.left, obj_info.top,
  					cur_real_width, cur_real_height, frame_width, frame_height))
  				{
  					continue;
  				}
  				/* 若更优于之前的快照 做快照的更新 */
  				if (total_village_snapshot_info[new_obj].snapShots[1].index.count == 0)
  				{
  					total_village_snapshot_info[new_obj].snapShots[1].index.count++;
  					total_village_snapshot_info[new_obj].snapShots[1].index.index = cur_real_index;
  				}
  				else
  				{
  					if (total_village_snapshot_info[new_obj].snapShots[1].index.index == cur_real_index)
  						total_village_snapshot_info[new_obj].snapShots[1].index.count++;
  					else
  						total_village_snapshot_info[new_obj].snapShots[1].index.count--;
  				}
  
  				total_village_snapshot_info[new_obj].snapShots[1].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素
  				total_village_snapshot_info[new_obj].snapShots[1].last_area = total_village_snapshot_info[new_obj].snapShots[1].max_area = (cur_right - cur_left) * (cur_bottom - cur_top);
  
  	
  				vec_obj_info.push_back(info);//用于最佳抓拍图
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
529
530
531
532
533
  			}
  		}
  
  		vector<vpc_img_info> imgList = pVpcUtil->crop_batch(memPtr, vec_obj_info);
  		vec_obj_info.clear();
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
534
535
536
  		for (size_t i = 0; i < imgList.size(); i++) {
  			vpc_img_info obj_info = imgList[i];
  			OBJ_KEY objKey = { obj_info.task_id, obj_info.object_id };
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
537
538
539
540
  			VPCUtil::vpc_img_release(total_village_snapshot_info[objKey].snapShots[1].snapShot);
  			total_village_snapshot_info[objKey].snapShots[1].snapShot = VPCUtil::vpc_devMem2vpcImg(memPtr);
  			VPCUtil::vpc_img_release(total_village_snapshot_info[objKey].snapShots[1].snapShotLittle);
  			total_village_snapshot_info[objKey].snapShots[1].snapShotLittle = obj_info;
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
541
542
  		}
  		imgList.clear();
d8ebfce2   Zhao Shuaihua   调整抓拍图保存
543
  #if 0 /*暂不存最佳抓拍之外的小图*/
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
544
545
546
547
548
549
550
551
552
553
554
  		vector<vpc_img_info> last_imgList = pVpcUtil->crop_batch(memPtr, last_vec_obj_info);
  		last_vec_obj_info.clear();
  		for (size_t i = 0; i < last_imgList.size(); i++) {
  			vpc_img_info obj_info = last_imgList[i];
  			OBJ_KEY objKey = { obj_info.task_id, obj_info.object_id };
  			VPCUtil::vpc_img_release(total_village_snapshot_info[objKey].snapShots[2].snapShot);
  			total_village_snapshot_info[objKey].snapShots[2].snapShot = VPCUtil::vpc_devMem2vpcImg(memPtr);
  			VPCUtil::vpc_img_release(total_village_snapshot_info[objKey].snapShots[2].snapShotLittle);
  			total_village_snapshot_info[objKey].snapShots[2].snapShotLittle = obj_info;
  		}
  		last_imgList.clear();
d8ebfce2   Zhao Shuaihua   调整抓拍图保存
555
  #endif
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
556
557
558
  	}
  }
  
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
559
  map<OBJ_KEY, OBJ_VALUES> snapshot_reprocessing::get_total_village_snapshot_info(){
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
560
561
562
  	return total_village_snapshot_info;
  }
  
09c2d08c   Hu Chunming   arm交付版
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
  bool snapshot_reprocessing::best_face_snapshot_judge_algor_v2(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height, float roll, float yaw, float pitch)
  {
  	return snapshot_legal_pos(obj_value.flags, left, top, left + width, top + height, image_width, image_height)
  		&& snapshot_legal_inarea(width, height)
  		&& snapshot_legal_area(obj_value.max_area, obj_value.last_area, left, top, left + width, top + height)
  		&& snapshot_legal_pose(obj_value.roll, obj_value.yaw, obj_value.pitch, roll, yaw, pitch);
  }
  
  //人脸快照保存更新
  int snapshot_reprocessing::update_face_bestsnapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &ol_det_result, vector<vector<int>>& delete_object_id)
  {
  	//230327added
  	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();
  
  	VPCUtil* pVpcUtil = VPCUtil::getInstance();
  	for(int idx=0; idx < vec_devMem.size(); idx++){
  
  		DeviceMemory* memPtr = vec_devMem[idx];
  		string task_id = memPtr->getId();
  		int frame_height = memPtr->getHeight();
  		int frame_width = memPtr->getWidth();
  
09c2d08c   Hu Chunming   arm交付版
586
587
588
589
  		if (0 == ol_det_result[idx].obj_count) {
  			continue;
  		}
  
b309bd27   Zhao Shuaihua   通途版本增加授权
590
591
  		LOG_DEBUG("{}: {}",task_id,ol_det_result[idx].obj_count);
  
09c2d08c   Hu Chunming   arm交付版
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
  		int copy_obj_count = 0;  //用于记录该路有多少个目标需要进行显存图像的更新
  		vector<video_object_info> vec_obj_info;
  		for (int c = 0; c < ol_det_result[idx].obj_count; c++) {
  			
  			det_objinfo obj_info = ol_det_result[idx].obj[c];
  			OBJ_KEY new_obj = { task_id, obj_info.id };
  
  			int cur_real_width = (obj_info.right - obj_info.left);
  			int cur_real_height = (obj_info.bottom - obj_info.top);
  			int cur_real_index = obj_info.index;
  			LOG_DEBUG(" {}: {} roll:{} yaw:{} pitch:{}",task_id, obj_info.id, fabs(obj_info.roll),fabs(obj_info.yaw),fabs(obj_info.pitch));
  			// 该目标的第一张
  			if (total_face_snapshot_info.find(new_obj) == total_face_snapshot_info.end()){
  
  				/* manager insert new object. */
  				// 有效区域和最小面积过滤
  				if (cur_real_width * cur_real_height < 30 * 30)
  				{
  					continue;
  				}
  				
  				// added by zsh 221024 人脸质量过滤-------------
  				if (obj_info.confidence < 0.6)
  					continue;
  				//---------------------------------------------
  				//230327 增加指定区域过滤------------------------------------------
  				if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algorithm_type_t::FACE_SNAPSHOT)))
  					continue;
  				task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algorithm_type_t::FACE_SNAPSHOT];
  				if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left,
  										   obj_info.top, obj_info.right, obj_info.bottom))
  					continue;	
  				//---------------------------------------------------------------
  				
  				LOG_DEBUG(" {}: {}",task_id, obj_info.id);
  				total_face_snapshot_info[new_obj].index.count++;
  				total_face_snapshot_info[new_obj].index.index = cur_real_index; //debug by zsh
  				total_face_snapshot_info[new_obj].confidence = obj_info.confidence;
  				// 人脸姿态角 added by zsh 220719-------------------------------------------
  				total_face_snapshot_info[new_obj].roll = obj_info.roll;
  				total_face_snapshot_info[new_obj].yaw = obj_info.yaw;
  				total_face_snapshot_info[new_obj].pitch = obj_info.pitch;
  				//-------------------------------------------------------------------------										
  
  				//判断是否有余地外扩
  				total_face_snapshot_info[new_obj].flags[0] = obj_info.left < minDistance[0] + SCALE_OUT ? 0 : 1;           //left
  				total_face_snapshot_info[new_obj].flags[1] = obj_info.top < minDistance[1] + SCALE_OUT ? 0 : 1;            //top
  				total_face_snapshot_info[new_obj].flags[2] = obj_info.right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1;   //right
  				total_face_snapshot_info[new_obj].flags[3] = obj_info.bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1;     //bottom
  
  				int cur_left = max(obj_info.left - 10, 0);
  				int cur_top = max(obj_info.top - 10, 0);
  				int cur_right = min(obj_info.right + 10, frame_width - 1);
  				int cur_bottom = min(obj_info.bottom + 10, frame_height - 1);
  				total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top);
  
  
  				//人脸 按长边2倍外扩 --modified by zsh-------------------------------------------------------
  				int cur_real_max_length = cur_real_width > cur_real_height ? cur_real_width:cur_real_height;
  				int expansion_width = cur_real_max_length * FACE_EXPANSION_PROPORTION;
  				int expansion_height = cur_real_max_length * FACE_EXPANSION_PROPORTION;
  
  				video_object_info info;
  				info.left = max(obj_info.left - expansion_width, 0);
  				info.top = max(obj_info.top - expansion_height, 0);
  				info.right = min(obj_info.right + expansion_width, frame_width - 1);
  				info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1);
  				strcpy(info.task_id, task_id.c_str());
  				info.object_id = obj_info.id;
  				info.confidence = obj_info.confidence;
  				info.index = obj_info.index;
  
  				vec_obj_info.push_back(info);
  				
  				total_face_snapshot_info[new_obj].obj_pos = { info.left , info.top ,info.right - info.left , info.bottom - info.top };
  
  				// 存人脸关键点、检测框及大图
  				memcpy(total_face_snapshot_info[new_obj].landmark_point, obj_info.landmark_point, sizeof(sy_point) * 25);
  				total_face_snapshot_info[new_obj].position = { obj_info.left, obj_info.top, obj_info.right - obj_info.left, obj_info.bottom - obj_info.top };
  			}
  			else
  			{
  				// added by zsh 221024 人脸质量过滤-------------
  				if (obj_info.confidence < 0.6)
  					continue;
  				//---------------------------------------------
  				//230327 指定区域过滤------------------------------------------
  				if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algorithm_type_t::FACE_SNAPSHOT)))
  					continue;
  				task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algorithm_type_t::FACE_SNAPSHOT];
  				if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left, obj_info.top, obj_info.right, obj_info.bottom))
  					continue;	
  			
  				// 最佳快照判断
  				if (!best_face_snapshot_judge_algor_v2(new_obj, total_face_snapshot_info[new_obj], obj_info.left, obj_info.top,
  					cur_real_width, cur_real_height, frame_width, frame_height, obj_info.roll, obj_info.yaw, obj_info.pitch ))
  					continue;
  
  				// 满足更新条件则进行更新
  				if (total_face_snapshot_info[new_obj].index.count == 0)
  				{
  					total_face_snapshot_info[new_obj].index.count++;
  					total_face_snapshot_info[new_obj].index.index = cur_real_index;
  				}
  				else
  				{
  					if (total_face_snapshot_info[new_obj].index.index == cur_real_index)
  						total_face_snapshot_info[new_obj].index.count++;
  					else
  						total_face_snapshot_info[new_obj].index.count--;
  				}
  
  				// 人脸姿态角 added by zsh 220719-------------------------------------------
  				total_face_snapshot_info[new_obj].roll = obj_info.roll;
  				total_face_snapshot_info[new_obj].yaw = obj_info.yaw;
  				total_face_snapshot_info[new_obj].pitch = obj_info.pitch;
  				//-------------------------------------------------------------------------	
  
  				int cur_left = max(obj_info.left - 10, 0);
  				int cur_top = max(obj_info.top - 10, 0);
  				int cur_right = min(obj_info.right + 10, frame_width - 1);
  				int cur_bottom = min(obj_info.bottom + 10, frame_height - 1);
  				// total_face_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素
  				total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top);
  
  				//人脸 按长边2倍外扩 --modified by zsh-------------------------------------------------------
  				int cur_real_max_length = cur_real_width > cur_real_height ? cur_real_width:cur_real_height;
  				int expansion_width = cur_real_max_length * FACE_EXPANSION_PROPORTION;
  				int expansion_height = cur_real_max_length * FACE_EXPANSION_PROPORTION;
  
  				video_object_info info;
  				info.left = max(obj_info.left - expansion_width, 0);
  				info.top = max(obj_info.top - expansion_height, 0);
  				info.right = min(obj_info.right + expansion_width, frame_width - 1);
  				info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1);
  				strcpy(info.task_id, task_id.c_str());
  				info.object_id = obj_info.id;
  				info.confidence = obj_info.confidence;
  				info.index = obj_info.index;
  
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
732
733
  				vec_obj_info.push_back(info);
  
09c2d08c   Hu Chunming   arm交付版
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
  				total_face_snapshot_info[new_obj].obj_pos = { info.left , info.top ,info.right - info.left , info.bottom - info.top };
  
  				//存人脸关键点、检测框及大图
  				memcpy(total_face_snapshot_info[new_obj].landmark_point, obj_info.landmark_point, sizeof(sy_point) * 25);
  				total_face_snapshot_info[new_obj].position = { obj_info.left, obj_info.top, obj_info.right - obj_info.left, obj_info.bottom - obj_info.top };
  			}
  		}
  
  		LOG_DEBUG("total_face_snapshot_info  size: {}", total_face_snapshot_info.size());
  
  		vector<vpc_img_info> imgList = pVpcUtil->crop_batch(memPtr, vec_obj_info);
  		vec_obj_info.clear();
  
  		for (size_t i = 0; i < imgList.size(); i++) {
  			vpc_img_info obj_info = imgList[i];
  			OBJ_KEY objKey = { obj_info.task_id, obj_info.object_id };
  			VPCUtil::vpc_img_release(total_face_snapshot_info[objKey].snapShot);
  			total_face_snapshot_info[objKey].snapShot = VPCUtil::vpc_devMem2vpcImg(memPtr);
  			VPCUtil::vpc_img_release(total_face_snapshot_info[objKey].snapShotLittle);
  			total_face_snapshot_info[objKey].snapShotLittle = obj_info;
  		}
  		imgList.clear();
  	}
  
  	return 0;
  }
  
  map<OBJ_KEY, OBJ_VALUE> snapshot_reprocessing::get_total_snapshot_info(){
  	return total_snapshot_info;
  }
  
  /* 快照判定辅助函数 */
  bool snapshot_reprocessing::best_snapshot_judge_algor(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height)
  {
  	return snapshot_legal_pos(obj_value.flags, left, top, left + width, top + height, image_width, image_height)
  		&& snapshot_legal_minarea(obj_value.index.index, width, height)
  		&& snapshot_legal_inarea(width, height)
  		&& snapshot_legal_area(obj_value.max_area, obj_value.last_area, left, top, left + width, top + height);
  	return true;
  }
  
  /* 删除指定快照 清空资源占用(使用场景:任务结束删除该路任务所有缓存快照;目标轨迹结束,分析保存完,删除该目标快照缓存)*/
  void snapshot_reprocessing::release_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease)
  { 
  	LOG_DEBUG("[info] task_id {} delete obj_id {}", taskid, obj_id); //221026
  	if (obj_id != -1)
  	{
  		OBJ_KEY cur_key = { taskid , obj_id };
  		auto it = total_snapshot_info.find(cur_key);
  		if (it == total_snapshot_info.end()){
  			return;
  		}
  
  		if (bRelease){
  			OBJ_VALUE ss = total_snapshot_info[cur_key];
  
  			VPCUtil::vpc_img_release(ss.snapShot);
  			VPCUtil::vpc_img_release(ss.snapShotLittle);
  		}
  		
  		total_snapshot_info.erase(cur_key);
  		return;
  	}
  
b5aaf53a   Zhao Shuaihua   雨棚模型升级
798
  	for(auto ss = total_snapshot_info.begin(); ss != total_snapshot_info.end();)
09c2d08c   Hu Chunming   arm交付版
799
800
801
802
803
804
805
  	{
  		if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0)
  		{
  			if (bRelease){
  				VPCUtil::vpc_img_release(ss->second.snapShot);
  				VPCUtil::vpc_img_release(ss->second.snapShotLittle);
  			}
b5aaf53a   Zhao Shuaihua   雨棚模型升级
806
  			total_snapshot_info.erase(ss++);
09c2d08c   Hu Chunming   arm交付版
807
  		}
b5aaf53a   Zhao Shuaihua   雨棚模型升级
808
  		else ss++;
09c2d08c   Hu Chunming   arm交付版
809
  	}
b5aaf53a   Zhao Shuaihua   雨棚模型升级
810
  	return;
09c2d08c   Hu Chunming   arm交付版
811
812
  }
  
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
813
814
815
816
817
818
819
820
821
822
823
824
825
  
  void snapshot_reprocessing::release_village_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease)
  { 
  	LOG_DEBUG("[info] task_id {} delete obj_id {}", taskid, obj_id); //221026
  	if (obj_id != -1)
  	{
  		OBJ_KEY cur_key = { taskid , obj_id };
  		auto it = total_village_snapshot_info.find(cur_key);
  		if (it == total_village_snapshot_info.end()){
  			return;
  		}
  
  		if (bRelease){
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
826
827
828
829
830
831
  			for (int i = 0; i < 3; i++) {
  				OBJ_VALUE ss = total_village_snapshot_info[cur_key].snapShots[i];
  				VPCUtil::vpc_img_release(ss.snapShot);
  				VPCUtil::vpc_img_release(ss.snapShotLittle);
  			}
  			
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
832
833
834
835
836
837
  		}
  		
  		total_village_snapshot_info.erase(cur_key);
  		return;
  	}
  
b5aaf53a   Zhao Shuaihua   雨棚模型升级
838
  	for(auto ss = total_village_snapshot_info.begin(); ss != total_village_snapshot_info.end();)
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
839
840
841
842
  	{
  		if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0)
  		{
  			if (bRelease){
28ca1c66   Zhao Shuaihua   代码优化
843
  				for (int i = 0; i < 3; i++) { 
e7cda3c8   Zhao Shuaihua   增加轨迹多图缓存、抓拍
844
845
846
  					VPCUtil::vpc_img_release(ss->second.snapShots[i].snapShot);
  					VPCUtil::vpc_img_release(ss->second.snapShots[i].snapShotLittle);
  				}
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
847
  			}
b5aaf53a   Zhao Shuaihua   雨棚模型升级
848
  			total_village_snapshot_info.erase(ss++);
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
849
  		}
b5aaf53a   Zhao Shuaihua   雨棚模型升级
850
  		else ss++;
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
851
  	}
b5aaf53a   Zhao Shuaihua   雨棚模型升级
852
  	return;
2c2868df   Zhao Shuaihua   结果整理,推送抓拍图
853
854
855
  }
  
  
09c2d08c   Hu Chunming   arm交付版
856
857
  map<OBJ_KEY, OBJ_VALUE> snapshot_reprocessing::get_total_face_snapshot_info(){
  	return total_face_snapshot_info;
3d1ce129   Hu Chunming   修正抠图失败还会保存原图的问题;
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
  }
  
  void snapshot_reprocessing::release_finished_face_locus_snapshot(const string taskid, const int obj_id, bool bRelease) { 
  
  	LOG_DEBUG("[info] task_id {} delete obj_id {}", taskid, obj_id); //221026
  	if (obj_id != -1) {
  		OBJ_KEY cur_key = { taskid , obj_id };
  		auto it = total_face_snapshot_info.find(cur_key);
  		if (it == total_face_snapshot_info.end()){
  			return;
  		}
  
  		if (bRelease){
  			OBJ_VALUE ss = total_face_snapshot_info[cur_key];
  
  			VPCUtil::vpc_img_release(ss.snapShot);
  			VPCUtil::vpc_img_release(ss.snapShotLittle);
  		}
  		
  		total_face_snapshot_info.erase(cur_key);
  		return;
  	}
  
b5aaf53a   Zhao Shuaihua   雨棚模型升级
881
  	for(auto ss = total_face_snapshot_info.begin(); ss != total_face_snapshot_info.end();)
3d1ce129   Hu Chunming   修正抠图失败还会保存原图的问题;
882
883
884
885
886
887
888
  	{
  		if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0)
  		{
  			if (bRelease){
  				VPCUtil::vpc_img_release(ss->second.snapShot);
  				VPCUtil::vpc_img_release(ss->second.snapShotLittle);
  			}
b5aaf53a   Zhao Shuaihua   雨棚模型升级
889
  			total_face_snapshot_info.erase(ss++);
3d1ce129   Hu Chunming   修正抠图失败还会保存原图的问题;
890
  		}
b5aaf53a   Zhao Shuaihua   雨棚模型升级
891
  		else ss++;
3d1ce129   Hu Chunming   修正抠图失败还会保存原图的问题;
892
  	}
b5aaf53a   Zhao Shuaihua   雨棚模型升级
893
  	return;
09c2d08c   Hu Chunming   arm交付版
894
  }