Blame view

tsl_aiplatform/reprocessing_module/snapshot_reprocessing.cpp 30.1 KB
85cc8cb9   Hu Chunming   原版代码
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
  #include "snapshot_reprocessing.h"
  #include "ImageSaveGPU.h"
  
  #include "opencv2/opencv.hpp"
  #include "opencv2/highgui/highgui.hpp"
  
  #include "helpers/logger.hpp"
  
  
  snapshot_reprocessing::snapshot_reprocessing()
  {
  	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 };
  }
  
  /* 获取人车物目标快照图 */
  map<OBJ_KEY, OBJ_VALUE> * snapshot_reprocessing::get_total_snapshot_info()
  {
  	return &total_snapshot_info;
  }
  
  /* 获取所有人脸目标快照图 */
  map<OBJ_KEY, OBJ_VALUE> * snapshot_reprocessing::get_total_face_snapshot_info()
  {
  	return &total_face_snapshot_info;
  }
  
  /* 获取人车物目标快照图 */
  int snapshot_reprocessing::update_bestsnapshot(set<string>& task_in_play_id, sy_img* images,
  											   vector<onelevel_det_result> &ol_det_result,
  											   vector<vector<int>>& delete_object_id)
  {
  	int idx = 0;
  	for (auto iter: task_in_play_id)
  	{
  		if (0 == ol_det_result[idx].obj_count)
  		{
  #ifdef MTASK_DEBUG_
  			LOG_DEBUG("task_id {} ckpt:0", iter);
  #endif
  			++idx;
  			continue;
  		}
  
  		int frame_height = images[idx].h_;
  		int frame_width = images[idx].w_;
  
  		int copy_obj_count = 0;  // 用于记录该路有多少个目标需要进行显存图像的更新
  		for (int c = 0; c < ol_det_result[idx].obj_count; c++)
  		{
  			int index = 0;
  			OBJ_KEY new_obj = { iter, ol_det_result[idx].obj[c].id };
  
  			/* 投票确定目标index */
  			if (total_snapshot_info.find(new_obj) == total_snapshot_info.end())
  			{
  				index = ol_det_result[idx].obj[c].index;
  			}
  			else
  			{
  				index = total_snapshot_info[new_obj].index.index;
  			}
  
  			int cur_real_width = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left);
  			int cur_real_height = (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top);
  			int cur_real_index = ol_det_result[idx].obj[c].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;
  			}
  			// DEBUG END-------------------------------------------------------------
  
  			/* 若该目标第一次出现 */
  			if (total_snapshot_info.find(new_obj) == total_snapshot_info.end())
  			{
  				/* manager insert new object. */
  				/* 判断目标合法 */
  				if (!snapshot_judge_algor(index, cur_real_width, cur_real_height))
  				{
  #ifdef MTASK_DEBUG_
  					LOG_DEBUG("task_id {} ckpt:1", iter);
  #endif
  					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 = ol_det_result[idx].obj[c].confidence;
  				total_snapshot_info[new_obj].flags[0] = ol_det_result[idx].obj[c].left < minDistance[0] + SCALE_OUT ? 0 : 1;           //left
  				total_snapshot_info[new_obj].flags[1] = ol_det_result[idx].obj[c].top < minDistance[1] + SCALE_OUT ? 0 : 1;            //top
  				total_snapshot_info[new_obj].flags[2] = ol_det_result[idx].obj[c].right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1;   //right
  				total_snapshot_info[new_obj].flags[3] = ol_det_result[idx].obj[c].bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1;     //bottom
  
  				/* 存入抠图参数 */
  				snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0);
  				snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0);
  				snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1);
  				snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1);
  				snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count];
  				snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count];
  
  				// total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count];
  				CHECK(cudaMalloc((void**)&total_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char)));
  				total_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count];
  				total_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count];
  				//DEBUG-------modified by zsh-----------------------------------------------------------------------------------------------------------------
  				// total_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; // 推出的坐标随抓拍图外扩
  				int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0);
  				int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0);
  				int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1);
  				int cur_bottom = min(ol_det_result[idx].obj[c].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);
  				// total_snapshot_info[new_obj].obj_pos = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; // 推出的坐标不外扩,只存在本地的快照外扩
  				//DEBUG END-----------------------------------------------------------------------------------------------------------------------------------
  				snapshot_image_data[copy_obj_count++] = (unsigned char*)total_snapshot_info[new_obj].snapShotLittle.frame;
  
  				CHECK(cudaMalloc((void**)&total_snapshot_info[new_obj].snapShot.frame, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char)));
  				CHECK(cudaMemcpy(total_snapshot_info[new_obj].snapShot.frame, (unsigned char*)images[idx].data_, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char), cudaMemcpyDeviceToDevice));
  				total_snapshot_info[new_obj].snapShot.height = frame_height;
  				total_snapshot_info[new_obj].snapShot.width = frame_width;
  				total_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS;
  			}
  			else   /* 若目标不是第一次出现 */
  			{
  				total_snapshot_info[new_obj].last_area = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left) * (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top);
  
  				/* 判断该目标是否优于之前的目标(判断策略可以自定义) */
  				if (!best_snapshot_judge_algor(new_obj, total_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].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--;
  				}
  
  				snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0);
  				snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0);
  				snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1);
  				snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1);
  				snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count];
  				snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count];
  
  				// total_snapshot_info[new_obj].last_area = total_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count];
  				//DEBUG--------------------------------------------------------------------------------------------------------------------------------------
  				// total_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] }; // 推出的坐标随抓拍图外扩
  				int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0);
  				int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0);
  				int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1);
  				int cur_bottom = min(ol_det_result[idx].obj[c].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);
  				// total_snapshot_info[new_obj].obj_pos = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top }; //debug by zsh 推出的坐标不外扩,只存在本地的快照外扩
  				//DEBUG END----------------------------------------------------------------------------------------------------------------------------------
  				if (total_snapshot_info[new_obj].snapShotLittle.frame != nullptr)
  				{
  					CHECK(cudaFree(total_snapshot_info[new_obj].snapShotLittle.frame));
  					CHECK(cudaMalloc((void**)&total_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char)));
  				}
  
  				total_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count];
  				total_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count];
  
  				snapshot_image_data[copy_obj_count++] = (unsigned char*)total_snapshot_info[new_obj].snapShotLittle.frame;
  				CHECK(cudaMemcpy(total_snapshot_info[new_obj].snapShot.frame, (unsigned char*)images[idx].data_, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char), cudaMemcpyDeviceToDevice));
  				total_snapshot_info[new_obj].snapShot.height = frame_height;
  				total_snapshot_info[new_obj].snapShot.width = frame_width;
  				total_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS;
  			}
  		}
  
  		/* 根据上面对目标的依次判断 存在需要抠图的目标 进行批量的抠图 同时做resize操作 */
  		if (0 != copy_obj_count)
  		{
  			PartMemResizeBatch((unsigned char*)images[idx].data_, frame_width, frame_height,
  				snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1);
  		}
  		idx++;
  	}
  	return 0;
  }
  
  //人脸快照保存更新
  int snapshot_reprocessing::update_face_bestsnapshot(set<string>& task_in_play_id, sy_img* images, vector<onelevel_det_result> &ol_det_result, vector<vector<int>>& delete_object_id)
  {
  	int idx = 0;
  	for (auto iter : task_in_play_id)
  	{
  		LOG_TRACE("[info]: {}: {}",iter,ol_det_result[idx].obj_count);
  		if (0 == ol_det_result[idx].obj_count) {
  			++idx;
  			continue;
  		}
  		int frame_height = images[idx].h_;
  		int frame_width = images[idx].w_;
  		int copy_obj_count = 0;  //用于记录该路有多少个目标需要进行显存图像的更新
  
  		for (int c = 0; c < ol_det_result[idx].obj_count; c++)
  		{
  			OBJ_KEY new_obj = { iter, ol_det_result[idx].obj[c].id };
  
  			int index = 1;
  			// 分类判断,人脸不需要
  
  			int cur_real_width = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left);
  			int cur_real_height = (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top);
  			int cur_real_index = ol_det_result[idx].obj[c].index;
  			LOG_TRACE("[info]00000: {}: {} roll:{} yaw:{} pitch:{}",iter,ol_det_result[idx].obj[c].id, fabs(ol_det_result[idx].obj[c].roll),fabs(ol_det_result[idx].obj[c].yaw),fabs(ol_det_result[idx].obj[c].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;
  				}
  				LOG_TRACE("[info]11111: {}: {}",iter,ol_det_result[idx].obj[c].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 = ol_det_result[idx].obj[c].confidence;
  				// 人脸姿态角 added by zsh 220719-------------------------------------------
  				total_face_snapshot_info[new_obj].roll = ol_det_result[idx].obj[c].roll;
  				total_face_snapshot_info[new_obj].yaw = ol_det_result[idx].obj[c].yaw;
  				total_face_snapshot_info[new_obj].pitch = ol_det_result[idx].obj[c].pitch;
  				//-------------------------------------------------------------------------										
  
  				//判断是否有余地外扩
  				total_face_snapshot_info[new_obj].flags[0] = ol_det_result[idx].obj[c].left < minDistance[0] + SCALE_OUT ? 0 : 1;           //left
  				total_face_snapshot_info[new_obj].flags[1] = ol_det_result[idx].obj[c].top < minDistance[1] + SCALE_OUT ? 0 : 1;            //top
  				total_face_snapshot_info[new_obj].flags[2] = ol_det_result[idx].obj[c].right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1;   //right
  				total_face_snapshot_info[new_obj].flags[3] = ol_det_result[idx].obj[c].bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1;     //bottom
  
  																																					   // 外扩
  				//人脸 按长边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;
  				//------------------------------------------------------------------------------------------
  				// int expansion_width = cur_real_width * FACE_EXPANSION_PROPORTION;
  				// int expansion_height = cur_real_height * FACE_EXPANSION_PROPORTION;
  
  				snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0);
  				snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0);
  				snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1);
  				snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1);
  				snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count];
  				snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count];
  
  				// 存参数
  				//DEBUG-------modified by zsh-----------------------------------------------------------------------------------------------------------------
  				int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0);
  				int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0);
  				int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1);
  				int cur_bottom = min(ol_det_result[idx].obj[c].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);
  				//DEBUG END-----------------------------------------------------------------------------------------------------------------------------------
  				// total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count];
  				CHECK(cudaMalloc((void**)&total_face_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char)));
  				total_face_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count];
  				total_face_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count];
  				total_face_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] };
  				snapshot_image_data[copy_obj_count++] = (unsigned char*)total_face_snapshot_info[new_obj].snapShotLittle.frame;
  
  
  				// 存人脸关键点、检测框及大图
  				memcpy(total_face_snapshot_info[new_obj].landmark_point, ol_det_result[idx].obj[c].landmark_point, sizeof(sy_point) * 25);
  				total_face_snapshot_info[new_obj].position = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top };
  
  				total_face_snapshot_info[new_obj].snapShot.height = frame_height;
  				total_face_snapshot_info[new_obj].snapShot.width = frame_width;
  				total_face_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS;
  				const unsigned nbytes = total_face_snapshot_info[new_obj].snapShot.size * sizeof(unsigned char);
  				CHECK(cudaMalloc(&total_face_snapshot_info[new_obj].snapShot.frame, nbytes)); ////
  				CHECK(cudaMemcpy(total_face_snapshot_info[new_obj].snapShot.frame, images[idx].data_, nbytes, cudaMemcpyDeviceToDevice));////
  			}
  			else
  			{
  				// 该目标非第一张
  				total_face_snapshot_info[new_obj].last_area = (ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left) * (ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top);
  
  				// 最佳快照判断
  				// if (!best_snapshot_judge_algor(new_obj, total_face_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top,
  				// 	cur_real_width, cur_real_height, frame_width, frame_height)) 
  				// modified by zsh
  				// if (!best_face_snapshot_judge_algor(new_obj, total_face_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top,
  				// 	cur_real_width, cur_real_height, frame_width, frame_height))
  				// modified by zsh 220719 加入姿态角
  				if (!best_face_snapshot_judge_algor_v2(new_obj, total_face_snapshot_info[new_obj], ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top,
  					cur_real_width, cur_real_height, frame_width, frame_height, ol_det_result[idx].obj[c].roll, ol_det_result[idx].obj[c].yaw, ol_det_result[idx].obj[c].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 = ol_det_result[idx].obj[c].roll;
  				total_face_snapshot_info[new_obj].yaw = ol_det_result[idx].obj[c].yaw;
  				total_face_snapshot_info[new_obj].pitch = ol_det_result[idx].obj[c].pitch;
  				//-------------------------------------------------------------------------	
  				//人脸 按长边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;
  				//------------------------------------------------------------------------------------------
  				// int expansion_width = cur_real_width * FACE_EXPANSION_PROPORTION;
  				// int expansion_height = cur_real_height * FACE_EXPANSION_PROPORTION;
  
  				snapshot_left[copy_obj_count] = max(ol_det_result[idx].obj[c].left - expansion_width, 0);
  				snapshot_top[copy_obj_count] = max(ol_det_result[idx].obj[c].top - expansion_height, 0);
  				snapshot_right[copy_obj_count] = min(ol_det_result[idx].obj[c].right + expansion_width, frame_width - 1);
  				snapshot_bottom[copy_obj_count] = min(ol_det_result[idx].obj[c].bottom + expansion_height, frame_height - 1);
  				snapshot_dst_width[copy_obj_count] = snapshot_right[copy_obj_count] - snapshot_left[copy_obj_count];
  				snapshot_dst_height[copy_obj_count] = snapshot_bottom[copy_obj_count] - snapshot_top[copy_obj_count];
  
  				//DEBUG-------modified by zsh-----------------------------------------------------------------------------------------------------------------
  				int cur_left = max(ol_det_result[idx].obj[c].left - 10, 0);
  				int cur_top = max(ol_det_result[idx].obj[c].top - 10, 0);
  				int cur_right = min(ol_det_result[idx].obj[c].right + 10, frame_width - 1);
  				int cur_bottom = min(ol_det_result[idx].obj[c].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);
  				//DEBUG END-----------------------------------------------------------------------------------------------------------------------------------
  				// total_face_snapshot_info[new_obj].last_area = total_face_snapshot_info[new_obj].max_area = snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count];
  				total_face_snapshot_info[new_obj].obj_pos = { snapshot_left[copy_obj_count] , snapshot_top[copy_obj_count] , snapshot_dst_width[copy_obj_count] , snapshot_dst_height[copy_obj_count] };
  
  				if (total_face_snapshot_info[new_obj].snapShotLittle.frame != nullptr)
  				{
  					CHECK(cudaFree(total_face_snapshot_info[new_obj].snapShotLittle.frame));      //释放显存
  					CHECK(cudaMalloc((void**)&total_face_snapshot_info[new_obj].snapShotLittle.frame, IMG_CHANNELS * snapshot_dst_width[copy_obj_count] * snapshot_dst_height[copy_obj_count] * sizeof(unsigned char)));
  				}
  
  				total_face_snapshot_info[new_obj].snapShotLittle.height = snapshot_dst_height[copy_obj_count];
  				total_face_snapshot_info[new_obj].snapShotLittle.width = snapshot_dst_width[copy_obj_count];
  
  
  				snapshot_image_data[copy_obj_count++] = (unsigned char*)total_face_snapshot_info[new_obj].snapShotLittle.frame;
  
  				//存人脸关键点、检测框及大图
  				memcpy(total_face_snapshot_info[new_obj].landmark_point, ol_det_result[idx].obj[c].landmark_point, sizeof(sy_point) * 25);
  				total_face_snapshot_info[new_obj].position = { ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].top, ol_det_result[idx].obj[c].right - ol_det_result[idx].obj[c].left, ol_det_result[idx].obj[c].bottom - ol_det_result[idx].obj[c].top };
  				CHECK(cudaMemcpy(total_face_snapshot_info[new_obj].snapShot.frame, (unsigned char*)images[idx].data_, IMG_CHANNELS * frame_width * frame_height * sizeof(unsigned char), cudaMemcpyDeviceToDevice));
  				total_face_snapshot_info[new_obj].snapShot.height = frame_height;
  				total_face_snapshot_info[new_obj].snapShot.width = frame_width;
  				total_face_snapshot_info[new_obj].snapShot.size = frame_width * frame_height * IMG_CHANNELS;
  
  
  			}
  		}
  
  		//对一张图片统一抠图
  		if (0 != copy_obj_count)
  		{
  			PartMemResizeBatch((unsigned char*)images[idx].data_, frame_width, frame_height,
  				snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1);
  		}
  		++idx;
  	}
  
  	return 0;
  }
  
  /* 过滤不感兴趣的目标 */
  void snapshot_reprocessing::screen_effective_snapshot(const set<string> &taskid_inplay, vector<onelevel_det_result> &_onelevel_det_result)
  {
  	map<string, algor_open_config_param> algor_param = m_task_param_manager->get_task_algor_params();
  
  	int task_count = _onelevel_det_result.size();
  
  	int task_idx = 0;
  
  	for (auto taskid : taskid_inplay)
  	{
  		int effective_count = 0;
  		int effective_idx = 0;
  
  		det_objinfo *tmp_det_objinfo = _onelevel_det_result[task_idx].obj;
  
  		for (int c = 0; c < _onelevel_det_result[task_idx].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++;
  			}
  		}
  
  		_onelevel_det_result[task_idx++].obj_count = effective_count;
  	}
  }
  
  /* 快照判定辅助函数 */
  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;
  }
  
  bool snapshot_reprocessing::best_face_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;
  }
  
  // added by zsh 220719
  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_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)
  		&& snapshot_legal_pose(obj_value.roll, obj_value.yaw, obj_value.pitch, roll, yaw, pitch);
  	return true;
  }
  
  bool snapshot_reprocessing::snapshot_judge_algor(int index, int width, int height)
  {
  	return snapshot_legal_minarea(index, width, height) //判断最小面积
  		&& snapshot_legal_inarea(width, height);     //判断在有效区域
  													 //&& snapshot_algor_open_config(obj_key);   //判断算法开启,调整不用在此处判断,检测出来会进行过滤
  }
  
  /* 删除指定快照 清空资源占用(使用场景:任务结束删除该路任务所有缓存快照;目标轨迹结束,分析保存完,删除该目标快照缓存)*/
  void snapshot_reprocessing::delete_finishtask_snapshot(const string taskid, const int objid)
  {
  	if (objid != -1)
  	{
  		OBJ_KEY cur_key = { taskid , objid };
  		auto &ss = total_snapshot_info[cur_key];
  
  		if (ss.snapShot.frame != nullptr) { cudaFree(ss.snapShot.frame);  ss.snapShot.frame = nullptr; }
  		if (ss.snapShotLittle.frame != nullptr) { cudaFree(ss.snapShotLittle.frame);  ss.snapShotLittle.frame = nullptr; }
  		total_snapshot_info.erase(cur_key);
  		return;
  	}
  	for(auto ss = total_snapshot_info.begin(); ss != total_snapshot_info.end(); )
  	{
  		if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0)
  		{
  			if (ss->second.snapShot.frame != nullptr){ CHECK(cudaFree(ss->second.snapShot.frame));  ss->second.snapShot.frame = nullptr; }
  			if (ss->second.snapShotLittle.frame != nullptr) { CHECK(cudaFree(ss->second.snapShotLittle.frame));  ss->second.snapShotLittle.frame = nullptr; }
  			total_snapshot_info.erase(ss++);
  		}
  		else ss++;
  	}
  
  	for (auto f_ss = total_face_snapshot_info.begin(); f_ss != total_face_snapshot_info.end(); )
  	{
  		if (strcmp(f_ss->first.video_id.c_str(), taskid.c_str()) == 0)
  		{
  			if (f_ss->second.snapShot.frame != nullptr)
  			{
  				CHECK(cudaFree(f_ss->second.snapShot.frame));
  				f_ss->second.snapShot.frame = nullptr;
  			}
  			if (f_ss->second.snapShotLittle.frame != nullptr)
  			{
  				CHECK(cudaFree(f_ss->second.snapShotLittle.frame));
  				f_ss->second.snapShotLittle.frame = nullptr;
  			}
  			total_face_snapshot_info.erase(f_ss++);
  		}
  		else f_ss++;
  	}
  }
  
  void snapshot_reprocessing::snapshot_reprocessing_release()
  {
  
  }