Commit 5e9071740a5c86ccb7d7fd3c9c9713bb7b2e02d0

Authored by Hu Chunming
1 parent be893a22

代码优化,改动较大,但是未改变代码逻辑

vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/ImageSaveGPU.cpp
1   -#include "cuda_kernels.h"
  1 +#include "ImageSaveGPU.h"
2 2  
  3 +#include "cuda_kernels.h"
3 4 #include "logger.hpp"
4 5  
5 6  
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp
... ... @@ -290,9 +290,6 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN
290 290 if (tObjInfoCallbackFunc != nullptr)
291 291 taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1);
292 292  
293   - minDistance[0] = minDistance[2] = 35; //left right
294   - minDistance[1] = minDistance[3] = 50; //top bottom
295   -
296 293 m_hp_analysis_config = vptParam.hp_analysis_config;
297 294 m_hcp_analysis_config = vptParam.hcp_analysis_config;
298 295 m_vehicle_analysis_config = vptParam.vehicle_analysis_config;
... ... @@ -1075,15 +1072,15 @@ void CMutliSourceVideoProcess::algorthim_process()
1075 1072 {
1076 1073 OBJ_KEY newObj = { (*iter), VPTResult[i].obj[c].id };
1077 1074  
1078   - int index = 0;
1079   - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end())
1080   - index = VPTResult[i].obj[c].index;
1081   - else
1082   - index = m_snaphot_helper.snapShotInfo[newObj].index.index;
1083   -
1084 1075 //实时查看模块 绘制目标框到画面上
1085 1076 if (view)
1086 1077 {
  1078 + int index = 0;
  1079 + if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end())
  1080 + index = VPTResult[i].obj[c].index;
  1081 + else
  1082 + index = m_snaphot_helper.snapShotInfo[newObj].index.index;
  1083 +
1087 1084 //cout << "---- vew ---- ";
1088 1085 int p1 = VPTResult[i].obj[c].left - 10 > 0 ? VPTResult[i].obj[c].left - 10 : 0;
1089 1086 int p2 = VPTResult[i].obj[c].top - 15 > 0 ? VPTResult[i].obj[c].top - 15 : 0;
... ... @@ -1100,284 +1097,24 @@ void CMutliSourceVideoProcess::algorthim_process()
1100 1097 #endif
1101 1098 }
1102 1099  
1103   - //逐个目标更新快照
1104   - int boundary = 10;
1105   - int boundaryLittle = 4;
1106   -
1107   - int cur_real_width = (VPTResult[i].obj[c].right - VPTResult[i].obj[c].left);
1108   - int cur_real_height = (VPTResult[i].obj[c].bottom - VPTResult[i].obj[c].top);
1109   - int cur_real_index = VPTResult[i].obj[c].index;
1110   -
1111   - //第一次添加快照
1112   - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end())
1113   - {
1114   - //DxAppendLog(DxLOG_INFO, "30");
1115   - if (LegalMinArea(cur_real_width, cur_real_height, tasks[*iter].task_min_boxsize[cur_real_index]))
1116   - {
1117   - //DxAppendLog(DxLOG_INFO, "31");
1118   - //--------------------- 保存快照视频截图 -----------------------------//
1119   -
1120   - int left = max(0, (int)(VPTResult[i].obj[c].left - boundaryLittle));
1121   - int top = max(0, (int)(VPTResult[i].obj[c].top - boundaryLittle));
1122   - int right = min({ frameWidth - 1, (int)(VPTResult[i].obj[c].right + boundaryLittle) });
1123   - int bottom = min({ frameHeight - 1, (int)(VPTResult[i].obj[c].bottom + boundaryLittle) });
1124   - m_snaphot_helper.snapShotInfo[newObj].frameCount = tasks[*iter].taskFrameCount;
1125   - m_snaphot_helper.snapShotInfo[newObj].isupdate = true;
1126   - m_snaphot_helper.snapShotInfo[newObj].lost = 0;
1127   -
1128   - m_snaphot_helper.snapShotInfo[newObj].index.count++;
1129   - m_snaphot_helper.snapShotInfo[newObj].index.index = VPTResult[i].obj[c].index;
1130   -
1131   - m_snaphot_helper.snapShotInfo[newObj].confidence = VPTResult[i].obj[c].confidence;
1132   -
1133   - m_snaphot_helper.snapShotInfo[newObj].box.left = left;
1134   - m_snaphot_helper.snapShotInfo[newObj].box.top = top;
1135   - m_snaphot_helper.snapShotInfo[newObj].box.right = right;
1136   - m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom;
1137   - m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left);
1138   -
1139   - m_snaphot_helper.snapShotInfo[newObj].flags[0] = left < minDistance[0] + SCALE_OUT ? 0 : 1; //left
1140   - m_snaphot_helper.snapShotInfo[newObj].flags[1] = top < minDistance[1] + SCALE_OUT ? 0 : 1; //top
1141   - m_snaphot_helper.snapShotInfo[newObj].flags[2] = right > frameWidth - minDistance[2] - SCALE_OUT ? 0 : 1; //right
1142   - m_snaphot_helper.snapShotInfo[newObj].flags[3] = bottom > frameHeight - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom
1143   -
1144   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame = NULL;
1145   - m_snaphot_helper.snapShotInfo[newObj].snapShot.frame = NULL;
1146   -
1147   - if (tasks[*iter].folderName != NULL)
1148   - {
1149   - //DxAppendLog(DxLOG_INFO, "32");
1150   - FRAME_KEY frame_id = { (*iter),tasks[*iter].taskFrameCount };
1151   - m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, tasks[*iter].task_algorithm_data);
1152   -
1153   - m_snaphot_helper.snapShotInfo[newObj].snapShot.height = frameHeight;
1154   - m_snaphot_helper.snapShotInfo[newObj].snapShot.width = frameWidth;
1155   - }
1156   -
1157   -
1158   - //--------------------- 保存快照抠图 -----------------------------/
1159   - int vLeft = 0;
1160   - int vTop = 0;
1161   - int vRight = 0;
1162   - int vBottom = 0;
1163   -
1164   - vLeft = max(0, VPTResult[i].obj[c].left - boundary);
1165   - vTop = max(0, VPTResult[i].obj[c].top - boundary);
1166   - vRight = min({ frameWidth - 1, VPTResult[i].obj[c].right + boundary });
1167   - vBottom = min({ frameHeight - 1, VPTResult[i].obj[c].bottom + boundary });
1168   - //DxAppendLog(DxLOG_INFO, "34");
1169   - if (tasks[*iter].folderNameLittle != NULL)
1170   - {
1171   - //DxAppendLog(DxLOG_INFO, "35");
1172   - int cur_width = 0;
1173   - int cur_height = 0;
1174   -
1175   - if (0 == m_snaphot_helper.snapShotInfo[newObj].index.index)
1176   - {
1177   - cur_width = HP_WIDTH;
1178   - cur_height = HP_HEIGHT;
1179   -
1180   - human_idx.emplace_back(copy_obj_count);
1181   - human_obj_keys.emplace_back (newObj);
1182   - }
1183   - else if (1 == m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == m_snaphot_helper.snapShotInfo[newObj].index.index)
1184   - {
1185   - cur_width = HCP_WIDTH;
1186   - cur_height = HCP_HEIGHT;
1187   - }
1188   - else if (8 == m_snaphot_helper.snapShotInfo[newObj].index.index || (m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && m_snaphot_helper.snapShotInfo[newObj].index.index <= 6))
1189   - {
1190   - cur_width = VEHICLE_WIDTH;
1191   - cur_height = VEHICLE_HEIGHT;
1192   - }
1193   - else //其余类别
1194   - {
1195   - cur_width = vRight - vLeft;
1196   - cur_height = vBottom - vTop;
1197   - }
1198   -
1199   - if (cur_width != 0 && cur_height != 0)
1200   - {
1201   - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, IMG_CHANNELS * cur_width * cur_height * sizeof(unsigned char));
1202   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = cur_height;
1203   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = cur_width;
1204   -
1205   - snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame;
1206   - snapshot_left[copy_obj_count] = vLeft;
1207   - snapshot_top[copy_obj_count] = vTop;
1208   - snapshot_right[copy_obj_count] = vRight;
1209   - snapshot_bottom[copy_obj_count] = vBottom;
1210   -
1211   - snapshot_dst_width[copy_obj_count] = cur_width;
1212   - snapshot_dst_height[copy_obj_count++] = cur_height;
1213   - }
1214   - }
1215   - }
1216   - }
1217   - else
1218   - {
1219   - //DxAppendLog(DxLOG_INFO, "36");
1220   - bool updateShotInfo = false;
1221   - int oldIndex = m_snaphot_helper.snapShotInfo[newObj].index.index;
1222   - m_snaphot_helper.snapShotInfo[newObj].frameCount = tasks[*iter].taskFrameCount;
1223   - m_snaphot_helper.snapShotInfo[newObj].isupdate = true;
1224   - m_snaphot_helper.snapShotInfo[newObj].lost = 0;
1225   -
1226   - if (m_snaphot_helper.snapShotInfo[newObj].index.count == 0)
1227   - {
1228   - m_snaphot_helper.snapShotInfo[newObj].index.count++;
1229   - m_snaphot_helper.snapShotInfo[newObj].index.index = VPTResult[i].obj[c].index;
1230   - }
1231   - else
1232   - {
1233   - if (m_snaphot_helper.snapShotInfo[newObj].index.index == VPTResult[i].obj[c].index)
1234   - m_snaphot_helper.snapShotInfo[newObj].index.count++;
1235   - else
1236   - m_snaphot_helper.snapShotInfo[newObj].index.count--;
  1100 + CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, VPTResult[i].obj[c], tasks[*iter]);
  1101 + if(crop_info.bCrop){
  1102 + snapshot_image_data[copy_obj_count] = crop_info.snapshot_image_data;
  1103 + snapshot_left[copy_obj_count] = crop_info.snapshot_left;
  1104 + snapshot_top[copy_obj_count] = crop_info.snapshot_top;
  1105 + snapshot_right[copy_obj_count] = crop_info.snapshot_right;
  1106 + snapshot_bottom[copy_obj_count] = crop_info.snapshot_bottom;
  1107 + snapshot_dst_width[copy_obj_count] = crop_info.snapshot_dst_width;
  1108 + snapshot_dst_height[copy_obj_count] = crop_info.snapshot_dst_height;
  1109 +
  1110 + int index = m_snaphot_helper.getIndexByKey(newObj);
  1111 + if(0 == index) {
  1112 + human_idx.push_back(copy_obj_count);
  1113 + human_obj_keys.emplace_back(newObj);
1237 1114 }
1238   - if (oldIndex != m_snaphot_helper.snapShotInfo[newObj].index.index)
1239   - {
1240   - updateShotInfo = true;
1241   - }
1242   -
1243   - int left = max(0, (int)(VPTResult[i].obj[c].left - boundaryLittle));
1244   - int top = max(0, (int)(VPTResult[i].obj[c].top - boundaryLittle));
1245   - int right = min(frameWidth - 1, (int)(VPTResult[i].obj[c].right + boundaryLittle));
1246   - int bottom = min(frameHeight - 1, (int)(VPTResult[i].obj[c].bottom + boundaryLittle));
1247   -
1248   - int maxArea = (m_snaphot_helper.snapShotInfo[newObj].box.right - m_snaphot_helper.snapShotInfo[newObj].box.left)*(m_snaphot_helper.snapShotInfo[newObj].box.bottom - m_snaphot_helper.snapShotInfo[newObj].box.top);
1249   -
1250   - if ((LegalArea(maxArea, m_snaphot_helper.snapShotInfo[newObj].lastArea, left, top, right, bottom)
1251   - && LegalPos(m_snaphot_helper.snapShotInfo[newObj].flags, left, top, right, bottom, frameHeight, frameWidth)
1252   - && LegalMinArea(cur_real_width, cur_real_height, tasks[*iter].task_min_boxsize[cur_real_index])) || updateShotInfo)
1253   - {
1254   - //DxAppendLog(DxLOG_INFO, "37");
1255   - int boundary_w = (VPTResult[i].obj[c].right - VPTResult[i].obj[c].left) * 0.1;
1256   - int boundary_h = (VPTResult[i].obj[c].bottom - VPTResult[i].obj[c].top)* 0.1;
1257   -
1258   - int boundary_left = boundary_w, boundary_right = boundary_w, boundary_top = boundary_h, boundary_bottom = boundary_h;
1259   -
1260   - ExpandMargin((left - m_snaphot_helper.snapShotInfo[newObj].box.left),
1261   - (bottom - m_snaphot_helper.snapShotInfo[newObj].box.bottom),
1262   - boundary_w, boundary_h, boundary_left, boundary_right, boundary_top, boundary_bottom);
1263   -
1264   - m_snaphot_helper.snapShotInfo[newObj].box.left = left;
1265   - m_snaphot_helper.snapShotInfo[newObj].box.top = top;
1266   - m_snaphot_helper.snapShotInfo[newObj].box.right = right;
1267   - m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom;
1268   - //printf("ori: %d %d %d %d\n", left, top, right - left, bottom - top);
1269   - m_snaphot_helper.snapShotInfo[newObj].confidence = VPTResult[i].obj[c].confidence;
1270   - if (tasks[*iter].folderName != NULL)
1271   - {
1272   - FRAME_KEY frame_id = { (*iter),tasks[*iter].taskFrameCount };
1273   - m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, tasks[*iter].task_algorithm_data);
1274   - }
1275 1115  
1276   -
1277   - //--------------------- 保存快照抠图 -----------------------------//
1278   - int vLeft = 0;
1279   - int vTop = 0;
1280   - int vRight = 0;
1281   - int vBottom = 0;
1282   -
1283   - vLeft = max(0, VPTResult[i].obj[c].left - boundary_left);
1284   - vTop = max(0, VPTResult[i].obj[c].top - boundary_top);
1285   - vRight = min(frameWidth - 1, VPTResult[i].obj[c].right + boundary_right);
1286   - vBottom = min(frameHeight - 1, VPTResult[i].obj[c].bottom + boundary_bottom);
1287   - if (tasks[*iter].folderNameLittle != NULL)
1288   - {
1289   -
1290   - if (0 == m_snaphot_helper.snapShotInfo[newObj].index.index)
1291   - {
1292   - if (m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT)
1293   - {
1294   - cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存
1295   - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char));
1296   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH;
1297   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT;
1298   - }
1299   -
1300   - human_idx.push_back(copy_obj_count);
1301   - human_obj_keys.emplace_back(newObj);
1302   -
1303   - snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame;
1304   - snapshot_left[copy_obj_count] = vLeft;
1305   - snapshot_top[copy_obj_count] = vTop;
1306   - snapshot_right[copy_obj_count] = vRight;
1307   - snapshot_bottom[copy_obj_count] = vBottom;
1308   - //printf("crop: %d %d %d %d\n", vLeft, vTop, vRight - vLeft, vBottom - vTop);
1309   - snapshot_dst_width[copy_obj_count] = HP_WIDTH;
1310   - snapshot_dst_height[copy_obj_count++] = HP_HEIGHT;
1311   -
1312   - }
1313   - else if (1 == m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == m_snaphot_helper.snapShotInfo[newObj].index.index)
1314   - {
1315   - //DxAppendLog(DxLOG_INFO, "42");
1316   - if (m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT)
1317   - {
1318   - //DxAppendLog(DxLOG_INFO, "43");
1319   - cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存
1320   - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char));
1321   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH;
1322   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT;
1323   - }
1324   -
1325   - snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame;
1326   - snapshot_left[copy_obj_count] = vLeft;
1327   - snapshot_top[copy_obj_count] = vTop;
1328   - snapshot_right[copy_obj_count] = vRight;
1329   - snapshot_bottom[copy_obj_count] = vBottom;
1330   -
1331   - snapshot_dst_width[copy_obj_count] = HCP_WIDTH;
1332   - snapshot_dst_height[copy_obj_count++] = HCP_HEIGHT;
1333   -
1334   - }
1335   - else if (8 == m_snaphot_helper.snapShotInfo[newObj].index.index || (m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && m_snaphot_helper.snapShotInfo[newObj].index.index <= 6))
1336   - {
1337   - //DxAppendLog(DxLOG_INFO, "43.1");
1338   - if (m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT)
1339   - {
1340   - //DxAppendLog(DxLOG_INFO, "44");
1341   - cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存
1342   - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char));
1343   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH;
1344   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = VEHICLE_HEIGHT;
1345   - }
1346   -
1347   - snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame;
1348   - snapshot_left[copy_obj_count] = vLeft;
1349   - snapshot_top[copy_obj_count] = vTop;
1350   - snapshot_right[copy_obj_count] = vRight;
1351   - snapshot_bottom[copy_obj_count] = vBottom;
1352   -
1353   - snapshot_dst_width[copy_obj_count] = VEHICLE_WIDTH;
1354   - snapshot_dst_height[copy_obj_count++] = VEHICLE_HEIGHT;
1355   -
1356   - }
1357   - else
1358   - {
1359   - //DxAppendLog(DxLOG_INFO, "45");
1360   - // modified by zsh 220614----------------------------
1361   - int cur_width = vRight - vLeft;
1362   - int cur_height = vBottom - vTop;
1363   - if (cur_width != 0 && cur_height != 0) {
1364   - //----------------------------------------
1365   - cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存
1366   - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char));
1367   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = vBottom - vTop;
1368   - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = vRight - vLeft;
1369   -
1370   - //printf("begin partMemCopy: %d %d %d %d %d %d\n", vLeft, vTop, vRight, vBottom, frameWidth, frameHeight);
1371   - partMemCopy((unsigned char*)tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight,
1372   - (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom);
1373   - }
1374   - }
1375   -
1376   - }
1377   - }
1378   - m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left);
  1116 + copy_obj_count++;
1379 1117 }
1380   -
1381 1118 }
1382 1119  
1383 1120 //若待抠图的快照数不为0 则进行批量抠图
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h
... ... @@ -5,7 +5,7 @@
5 5 #include <stdlib.h>
6 6 #include <iostream>
7 7  
8   -#include "../FFNvDecoder/DxDecoderWrap.h"
  8 +
9 9 #include "nvml.h"
10 10 #include "time.h"
11 11 #include "opencv2/opencv.hpp"
... ... @@ -68,27 +68,9 @@ using namespace std;
68 68 #define SNAPSHOTFRAME 15
69 69 #define LOSTMAXFRAMECCOUNT 4
70 70  
71   -#define SCALE_OUT 10 //锟叫讹拷目锟斤拷锟斤拷始位锟斤拷时锟斤拷锟斤拷锟斤拷小锟斤拷锟斤拷幕锟斤拷锟斤拷锟斤拷实锟斤拷锟斤拷锟
72   -
73 71  
74 72 #define MAX_BATCH 10
75 73  
76   -extern int minDistance[];
77   -
78   -enum TaskState
79   -{
80   - PLAY,
81   - PAUSE,
82   - FINISH,
83   - DECODEERROR //锟斤拷锟斤拷锟竭程匡拷锟杰憋拷锟斤拷锟斤拷锟斤拷锟斤拷之锟斤拷直锟接斤拷锟斤拷锟斤拷锟斤拷路锟斤拷锟斤拷
84   -};
85   -
86   -
87   -
88   -struct VideoHeightWidth{
89   - double height;
90   - double width;
91   -};
92 74  
93 75 struct VideoObjectSS
94 76 {
... ... @@ -98,67 +80,7 @@ struct VideoObjectSS
98 80  
99 81 VideoObjectSS() : obj_person(NULL), obj_bike(NULL), obj_car(NULL){}
100 82 };
101   -template <typename T> class MyAtomic;
102   -template<typename T>
103   -bool operator == (MyAtomic<T> & d1, T &d2);
104   -
105   -template<typename T>
106   -bool operator == (MyAtomic<T> & d1, MyAtomic<T> &d2);
107   -template <typename T>
108   -class MyAtomic
109   -{
110   -public:
111   - MyAtomic() {};
112   - MyAtomic(const T & d) { data.store(d); };
113   - MyAtomic(const MyAtomic & d) { data.store(d.data.load()); };
114   - MyAtomic& operator =(T d) { data.store(d); return *this; };
115   - MyAtomic& operator =(MyAtomic & d) { data.store(d.data.load()); return *this; };
116   - MyAtomic& operator +=(T d) { data.fetch_add(d); return *this; };
117   - MyAtomic& operator +=(MyAtomic & d) { data.fetch_add(d); return *this; };
118   - operator int() { return data.load(); }
119   - friend bool operator ==<T> (MyAtomic<T> &d1, T &d2);
120   - friend bool operator ==<T> (MyAtomic<T> &d1, MyAtomic<T> &d2);
121   -private:
122   - std::atomic<T> data;
123   -};
124   -template<typename T>
125   -bool operator == (MyAtomic<T> & d1, T &d2)
126   -{
127   - if (d1.data.load() == d2)
128   - return true;
129   - else
130   - return false;
131   -}
132   -
133   -template<typename T>
134   -bool operator == (MyAtomic<T> & d1, MyAtomic<T> & d2)
135   -{
136   - if (d1.data.load() == d2.load())
137   - return true;
138   - else
139   - return false;
140   -}
141   -
142   -struct Task{
143   - int taskID;
144   - const char *taskFileSource;
145   - TaskState taskState;
146   - DxDecoderWrap *taskTcuvid;
147   - DxGPUFrame task_algorithm_data; //锟斤拷锟斤拷驴锟杰诧拷锟斤拷resize锟侥达拷锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷backup锟斤拷原图锟斤拷小锟斤拷图片锟酵斤拷锟姐法锟斤拷锟斤拷锟斤拷锟
148   - bool taskHasBackup;
149   - //VideoHeightWidth taskHeightWidthRatio;
150   - VideoHeightWidth taskHeightWidth;
151   - MyAtomic<int> taskFrameCount;
152   - MyAtomic<int> taskLastFrameCount;
153   - int taskTotalFrameCount;
154   - SNAPSHOT_CALLBACK taskObjCallbackFunc;
155   - REALTIME_CALLBACK taskRealTimeCallbackFunc;
156   - cv::Mat frameImage;
157   - char* folderNameLittle;
158   - char* folderName;
159   - char* folderNameFace;
160   - sy_rect task_min_boxsize[DETECTTYPE];
161   -};
  83 +
162 84  
163 85 enum TaskOperator
164 86 {
... ... @@ -183,24 +105,7 @@ struct Operator{
183 105 VIDEO_REALTIME_CALLBACK taskRealTimeCallbackFunc;
184 106 sy_rect minBoxsize[DETECTTYPE];
185 107 };
186   -
187   -struct CUVID_USERDATA{
188   - int id;
189   - void *opaque;
190   -};
191   -
192   -struct CUVID_DATA{
193   - float* pData;
194   - int nWidth;
195   - int nHeight;
196   - int nDatasize;
197   -};
198 108  
199   -struct SNAPSHOT_PROCESS_UNIT{
200   - vector<DxGPUFrame> imgBig;
201   - vector<DxGPUFrame> imgSmall;
202   - vector<VPT_Result> imgVPTResult;
203   -};
204 109  
205 110 class CMutliSourceVideoProcess
206 111 {
... ... @@ -278,9 +183,6 @@ public: /*锟斤拷锟斤拷锟斤拷锟斤拷应锟斤拷锟斤拷public锟斤拷 锟斤拷锟斤拷锟斤拷
278 183  
279 184 FINISH_CALLBACK taskFinishCallbackFunc;
280 185 OBJECT_INFO_CALLBACK taskObjInfoCallbackFunc;
281   -
282   - queue<SNAPSHOT_PROCESS_UNIT> snapshotProcessQueue;
283   -
284 186  
285 187 std::mutex taskMutex;
286 188 std::condition_variable taskCondVar;
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MyAtomic.hpp 0 → 100644
  1 +#include <atomic>
  2 +
  3 +template <typename T> class MyAtomic;
  4 +template<typename T>
  5 +bool operator == (MyAtomic<T> & d1, T &d2);
  6 +
  7 +template<typename T>
  8 +bool operator == (MyAtomic<T> & d1, MyAtomic<T> &d2);
  9 +template <typename T>
  10 +class MyAtomic
  11 +{
  12 +public:
  13 + MyAtomic() {};
  14 + MyAtomic(const T & d) { data.store(d); };
  15 + MyAtomic(const MyAtomic & d) { data.store(d.data.load()); };
  16 + MyAtomic& operator =(T d) { data.store(d); return *this; };
  17 + MyAtomic& operator =(MyAtomic & d) { data.store(d.data.load()); return *this; };
  18 + MyAtomic& operator +=(T d) { data.fetch_add(d); return *this; };
  19 + MyAtomic& operator +=(MyAtomic & d) { data.fetch_add(d); return *this; };
  20 + operator int() { return data.load(); }
  21 + friend bool operator ==<T> (MyAtomic<T> &d1, T &d2);
  22 + friend bool operator ==<T> (MyAtomic<T> &d1, MyAtomic<T> &d2);
  23 +private:
  24 + std::atomic<T> data;
  25 +};
  26 +template<typename T>
  27 +bool operator == (MyAtomic<T> & d1, T &d2)
  28 +{
  29 + if (d1.data.load() == d2)
  30 + return true;
  31 + else
  32 + return false;
  33 +}
  34 +
  35 +template<typename T>
  36 +bool operator == (MyAtomic<T> & d1, MyAtomic<T> & d2)
  37 +{
  38 + if (d1.data.load() == d2.load())
  39 + return true;
  40 + else
  41 + return false;
  42 +}
0 43 \ No newline at end of file
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h
... ... @@ -9,29 +9,10 @@
9 9 #include <iostream>
10 10 #include "utools.h"
11 11 #include <vector>
  12 +#include "common.h"
  13 +
12 14 using namespace std;
13 15 #define VTTYPECOUNT 10 //֧�ֵ���������
14   -#define MAX_OBJ_COUNT 100
15   -typedef struct VPT_ObjInfo //����ṹ��
16   -{
17   - int left;
18   - int top;
19   - int right;
20   - int bottom;
21   - int center_x;
22   - int center_y;
23   - int index; // ����/�������֧��10��
24   - long id; // Ŀ��ΨһID��ͬһIDΪͬһĿ��
25   - int num; // ��ID�����µĵ�num֡
26   - double confidence; // ���Ŷ�
27   - int snap_flag;
28   -}VPT_ObjInfo;
29   -
30   -typedef struct VPT_Result
31   -{
32   - int objCount;
33   - VPT_ObjInfo obj[MAX_OBJ_COUNT];
34   -}VPT_Result;
35 16  
36 17  
37 18 typedef struct VPTProcess_PARAM
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h
... ... @@ -2,7 +2,17 @@
2 2 #define COMMON_H_
3 3 #include <functional>
4 4 #include "header.h"
  5 +
  6 +#include "opencv2/opencv.hpp"
  7 +#include "opencv2/highgui/highgui.hpp"
  8 +
  9 +#include "MyAtomic.hpp"
  10 +#include "../FFNvDecoder/DxDecoderWrap.h"
  11 +
5 12 #define IMG_CHANNELS 3
  13 +#define SCALE_OUT 10 //判断目标框初始位置时,在最小距离的基础上适当外扩
  14 +#define MAX_OBJ_COUNT 100
  15 +
6 16 struct OBJ_KEY {
7 17 int videoID;
8 18 int objID;
... ... @@ -48,4 +58,61 @@ using SNAPSHOT_CALLBACK = std::function&lt;void(video_object_snapshot *)&gt;;
48 58 using REALTIME_CALLBACK = std::function<void(unsigned char *img_data, int img_height, int img_width)>;
49 59 using FINISH_CALLBACK = std::function<void( const int )>;
50 60 using OBJECT_INFO_CALLBACK = std::function<void(video_object_info *)>;
  61 +
  62 +
  63 +struct VideoHeightWidth{
  64 + double height;
  65 + double width;
  66 +};
  67 +
  68 +enum TaskState
  69 +{
  70 + PLAY,
  71 + PAUSE,
  72 + FINISH,
  73 + DECODEERROR //解码线程可能报错,报错之后直接结束掉该路解码
  74 +};
  75 +
  76 +struct Task{
  77 + int taskID;
  78 + const char *taskFileSource;
  79 + TaskState taskState;
  80 + DxDecoderWrap *taskTcuvid;
  81 + DxGPUFrame task_algorithm_data; //����¿�ܲ���resize�Ĵ���������ʱ��backup��ԭͼ��С��ͼƬ�ͽ��㷨�������
  82 + bool taskHasBackup;
  83 + VideoHeightWidth taskHeightWidth;
  84 + MyAtomic<int> taskFrameCount;
  85 + MyAtomic<int> taskLastFrameCount;
  86 + int taskTotalFrameCount;
  87 + SNAPSHOT_CALLBACK taskObjCallbackFunc;
  88 + REALTIME_CALLBACK taskRealTimeCallbackFunc;
  89 + cv::Mat frameImage;
  90 + char* folderNameLittle;
  91 + char* folderName;
  92 + char* folderNameFace;
  93 + sy_rect task_min_boxsize[DETECTTYPE];
  94 +};
  95 +
  96 +typedef struct VPT_ObjInfo //����ṹ��
  97 +{
  98 + int left;
  99 + int top;
  100 + int right;
  101 + int bottom;
  102 + int center_x;
  103 + int center_y;
  104 + int index; // ����/�������֧��10��
  105 + long id; // Ŀ��ΨһID��ͬһIDΪͬһĿ��
  106 + int num; // ��ID�����µĵ�num֡
  107 + double confidence; // ���Ŷ�
  108 + int snap_flag;
  109 +}VPT_ObjInfo;
  110 +
  111 +typedef struct VPT_Result
  112 +{
  113 + int objCount;
  114 + VPT_ObjInfo obj[MAX_OBJ_COUNT];
  115 +}VPT_Result;
  116 +
  117 +
51 118 #endif
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.cpp
1 1 #include "mvpt_process_assist.h"
2 2  
3   -int minDistance[EDGESIZE];
4 3  
5   -//******** 判断位置是否合法函数 **********//
6   -// 目的:剔除掉靠近摄像头时,面积最大,但是检测物体已经不完整的情况
7   -// 1. 设定阈值,靠近边缘不要了(阈值目前设定为自身宽高的20%)
8   -bool LegalPos(bitset<EDGESIZE> flags, int left, int top, int right, int bottom, int imgHeight, int imgWidth)
  4 +//******** 锟叫讹拷位锟斤拷锟角凤拷戏锟斤拷锟斤拷锟 **********//
  5 +// 目锟侥o拷锟睫筹拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷头时锟斤拷锟斤拷锟斤拷锟襟,碉拷锟角硷拷锟斤拷锟斤拷锟斤拷丫锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
  6 +// 1. 锟借定锟斤拷值锟斤拷锟斤拷锟斤拷锟斤拷缘锟斤拷要锟剿o拷锟斤拷值目前锟借定为锟斤拷锟斤拷锟斤拷锟竭碉拷20%锟斤拷
  7 +bool LegalPos(bitset<EDGESIZE> flags, int left, int top, int right, int bottom, int imgHeight, int imgWidth, int minDistance[EDGESIZE])
9 8 {
10 9 int pos[4] = { left, top, right, bottom };
11 10 int edges[4] = { 0, 0, imgWidth, imgHeight };
12 11  
13 12 for (int i = 0; i < EDGESIZE; i++)
14 13 {
15   - if (flags[i]) //是需要判断的边
  14 + if (flags[i]) //锟斤拷锟斤拷要锟叫断的憋拷
16 15 {
17 16 if (abs(pos[i] - edges[i]) < minDistance[i])
18 17 return false;
... ... @@ -26,13 +25,13 @@ bool LegalMinArea(int width, int height, sy_rect min_box)
26 25 return (width >= min_box.width_ && height >= min_box.height_);
27 26 }
28 27  
29   -//******** 判断面积是否合法函数 **********//
30   -// 目的:选取框最大最完整的那帧
31   -// 1. 比之前面积小的不要
32   -// 2. 突变的面积不要
  28 +//******** 锟叫讹拷锟斤拷锟斤拷欠锟较凤拷锟斤拷锟斤拷 **********//
  29 +// 目锟侥o拷选取锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街
  30 +// 1. 锟斤拷之前锟斤拷锟叫★拷牟锟揭
  31 +// 2. 突锟斤拷锟斤拷锟斤拷锟斤拷要
33 32 bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bottom)
34 33 {
35   - //不需要通过MINBOX来判断,直接返回true
  34 + //锟斤拷锟斤拷要通锟斤拷MINBOX锟斤拷锟叫断o拷直锟接凤拷锟斤拷true
36 35  
37 36 int newArea = (bottom - top)*(right - left);
38 37  
... ... @@ -41,14 +40,14 @@ bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bott
41 40  
42 41 if (newArea < maxArea)
43 42 return false;
44   - else if ((newArea - lastArea) / lastArea > 0.5) //阈值测试之后再确定,看是否需要分种类来确定不同的阈
  43 + else if ((newArea - lastArea) / lastArea > 0.5) //锟斤拷值锟斤拷锟斤拷之锟斤拷锟斤拷确锟斤拷锟斤拷锟斤拷锟角凤拷锟斤拷要锟斤拷锟斤拷锟斤拷锟斤拷确锟斤拷锟斤拷同锟斤拷锟斤拷
45 44 return false;
46 45 else return true;
47 46 }
48 47  
49 48  
50   -//******** 辅助函数:根据目标运动的轨迹,判断需要特别外扩的方向 **********//
51   -// 目的:因为跳帧的存在,目标运动较快时,框会有一定的滞后的情况(车向前运动,车头被裁掉的情况尤其明显),框滞后的方向需要额外外扩
  49 +//******** 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷目锟斤拷锟剿讹拷锟侥轨迹锟斤拷锟叫讹拷锟斤拷要锟截憋拷锟斤拷锟斤拷锟侥凤拷锟斤拷 **********//
  50 +// 目锟侥o拷锟斤拷为锟斤拷帧锟侥达拷锟节o拷目锟斤拷锟剿讹拷锟较匡拷时锟斤拷锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷秃锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟角帮拷硕锟斤拷锟斤拷锟酵凤拷锟斤拷玫锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟皆o拷锟斤拷锟斤拷锟酵猴拷姆锟斤拷锟斤拷锟揭拷锟斤拷锟斤拷锟斤拷锟
52 51 void ExpandMargin(int direction_x, int direction_y, int boundary_w, int boundary_h,
53 52 int &boundary_left, int &boundary_right, int &boundary_top, int &boundary_bottom)
54 53 {
... ... @@ -185,7 +184,7 @@ void CreateResultFolder(char* resultFolder, const char* jointFolder)
185 184 }
186 185 }
187 186  
188   -//俯仰角比较容易产生大角度 所以单独设置 一般建议阈值 max_angle 15.0 max_pitch_angle 20.0
  187 +//锟斤拷锟斤拷锟角比斤拷锟斤拷锟阶诧拷锟斤拷锟斤拷嵌锟 锟斤拷锟皆碉拷锟斤拷锟斤拷锟斤拷 一锟姐建锟斤拷锟斤拷值 max_angle 15.0 max_pitch_angle 20.0
189 188 bool validAngle(float roll, float yaw, float pitch, float max_angle, float max_pitch_angle)
190 189 {
191 190 if (yaw >= -max_angle && yaw <= max_angle \
... ... @@ -200,7 +199,7 @@ bool validAngle(float roll, float yaw, float pitch, float max_angle, float max_p
200 199 }
201 200  
202 201  
203   -//俯仰角比较容易产生大角度 所以单独设置 一般建议阈值 max_angle 15.0 max_pitch_angle 20.0
  202 +//锟斤拷锟斤拷锟角比斤拷锟斤拷锟阶诧拷锟斤拷锟斤拷嵌锟 锟斤拷锟皆碉拷锟斤拷锟斤拷锟斤拷 一锟姐建锟斤拷锟斤拷值 max_angle 15.0 max_pitch_angle 20.0
204 203 bool betterArea(sy_rect& area1, sy_rect& area2)
205 204 {
206 205 return area1.width_*area1.height_ > area2.width_*area2.height_;
... ... @@ -214,9 +213,9 @@ bool betterArea(sy_rect&amp; area1, sy_rect&amp; area2)
214 213 // cv::Mat host_image;
215 214 // host_image.create(testHeight, testWidth, CV_8UC3);
216 215 //
217   -// unsigned char *Host_img = new unsigned char[3 * testWidth * testHeight]{};//主机内存
  216 +// unsigned char *Host_img = new unsigned char[3 * testWidth * testHeight]{};//锟斤拷锟斤拷锟节达拷
218 217 //
219   -// (cudaMemcpy(Host_img, imgdata, testWidth*testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost));//拷贝显卡处理完图像到主机
  218 +// (cudaMemcpy(Host_img, imgdata, testWidth*testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost));//锟斤拷锟斤拷锟皆匡拷锟斤拷锟斤拷锟斤拷图锟斤拷锟斤拷锟斤拷
220 219 //
221 220 // for (int j = 0; j < host_image.rows; j++)
222 221 // {
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.h
  1 +#ifndef __MVPT_PROCESS_ASSIST_H__
  2 +#define __MVPT_PROCESS_ASSIST_H__
  3 +
1 4 #include <bitset>
2 5 #include "opencv2/highgui/highgui.hpp"
3 6 #include <cuda.h>
... ... @@ -22,16 +25,17 @@
22 25  
23 26 #define EDGESIZE 4
24 27  
25   -
26 28 using namespace std;
27 29  
28 30 //void showGpuMat(unsigned char* imgdata, int height, int width);
29 31 int CreateDir(char *pszDir);
30 32 void CreateResultFolder(char* resultFolder, const char* jointFolder);
31   -bool LegalPos(bitset<EDGESIZE> flags, int left, int top, int right, int bottom, int imgHeight, int imgWidth);
  33 +bool LegalPos(bitset<EDGESIZE> flags, int left, int top, int right, int bottom, int imgHeight, int imgWidth, int minDistance[EDGESIZE]);
32 34 bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bottom);
33 35 bool LegalMinArea(int width, int height, sy_rect min_box);
34 36 void ExpandMargin(int direction_x, int direction_y, int boundary_w, int boundary_h,
35 37 int &boundary_left, int &boundary_right, int &boundary_top, int &boundary_bottom);
36 38 bool validAngle(float roll, float yaw, float pitch, float max_angle, float max_pitch_angle);
37   -bool betterArea(sy_rect& area1, sy_rect& area2);
38 39 \ No newline at end of file
  40 +bool betterArea(sy_rect& area1, sy_rect& area2);
  41 +
  42 +#endif // __MVPT_PROCESS_ASSIST_H__
39 43 \ No newline at end of file
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehiclePlate.cpp
... ... @@ -47,11 +47,11 @@ int VehiclePlate::process(sy_img * batch_img, int batchsize, vehicle_plate_resul
47 47 LOG_ERROR("data null ");
48 48 return FAILED;
49 49 }
50   - // cpu_batch_img[i].data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char));
51   - // cudaMemcpy(cpu_batch_img[i].data_, batch_img[i].data_, batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char), cudaMemcpyDeviceToHost);
52   - // cpu_batch_img[i].w_ = batch_img[i].w_;
53   - // cpu_batch_img[i].h_ = batch_img[i].h_;
54   - // cpu_batch_img[i].c_ = batch_img[i].c_;
  50 + cpu_batch_img[i].data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char));
  51 + cudaMemcpy(cpu_batch_img[i].data_, batch_img[i].data_, batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char), cudaMemcpyDeviceToHost);
  52 + cpu_batch_img[i].w_ = batch_img[i].w_;
  53 + cpu_batch_img[i].h_ = batch_img[i].h_;
  54 + cpu_batch_img[i].c_ = batch_img[i].c_;
55 55 }
56 56  
57 57 vehicle_plate_results * all_result = new vehicle_plate_results[batchsize] {};
... ... @@ -61,7 +61,7 @@ int VehiclePlate::process(sy_img * batch_img, int batchsize, vehicle_plate_resul
61 61 }
62 62 }
63 63  
64   - int index_count = vpdr_batch(handle, batch_img, batchsize, all_result);
  64 + int index_count = vpdr_batch(handle, cpu_batch_img, batchsize, all_result);
65 65 cudaDeviceSynchronize();
66 66  
67 67 for (int b = 0; b < batchsize; b++)
... ... @@ -85,12 +85,12 @@ int VehiclePlate::process(sy_img * batch_img, int batchsize, vehicle_plate_resul
85 85 memcpy(&result[b], &all_result[b].vehicle_plate_infos[best_index], sizeof(vehicle_plate_result));
86 86 }
87 87  
88   - // for (int i = 0; i < batchsize; i++) {
89   - // if(cpu_batch_img[i].data_ != nullptr) {
90   - // free(cpu_batch_img[i].data_);
91   - // cpu_batch_img[i].data_ = nullptr;
92   - // }
93   - // }
  88 + for (int i = 0; i < batchsize; i++) {
  89 + if(cpu_batch_img[i].data_ != nullptr) {
  90 + free(cpu_batch_img[i].data_);
  91 + cpu_batch_img[i].data_ = nullptr;
  92 + }
  93 + }
94 94  
95 95 if (all_result != NULL)
96 96 delete [] all_result;
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp
... ... @@ -6,12 +6,16 @@
6 6 #include <chrono>
7 7  
8 8 #include "../FFNvDecoder/logger.hpp"
  9 +#include "../mvpt_process_assist.h"
  10 +#include "../common.h"
  11 +#include "../FFNvDecoder/ImageSaveGPU.h"
9 12  
10 13 using namespace std;
11 14  
12 15 string ObjTypes[9] = { "行人", "自行车", "摩托车", "三轮车", "小型车", "大车", "卡车", "拖拉机", "中巴" };
13 16 string ObjTypesEnglish[9] = { "person", "bike", "motor", "tricycle", "car", "bigbus", "lorry", "tractor", "midibus" };
14 17  
  18 +extern int minDistance[];
15 19  
16 20 #ifdef _MSC_VER
17 21 char* GbkToUtf8(const char *src_str)
... ... @@ -2043,4 +2047,276 @@ int snapshot_helper::SaveResultInFile(const OBJ_KEY &amp; obj_key, const OBJ_VALUE &amp;
2043 2047 }
2044 2048  
2045 2049 return 0;
  2050 +}
  2051 +
  2052 +CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Task task) {
  2053 +
  2054 + //逐个目标更新快照
  2055 + int boundary = 10;
  2056 + int boundaryLittle = 4;
  2057 +
  2058 + int cur_real_width = (obj.right - obj.left);
  2059 + int cur_real_height = (obj.bottom - obj.top);
  2060 + int cur_real_index = obj.index;
  2061 +
  2062 + int frameHeight = task.task_algorithm_data.height;
  2063 + int frameWidth = task.task_algorithm_data.width;
  2064 +
  2065 + int minDistance[EDGESIZE];
  2066 + minDistance[0] = minDistance[2] = 35; //left right
  2067 + minDistance[1] = minDistance[3] = 50; //top bottom
  2068 +
  2069 + CropInfo cropInfo;
  2070 + //第一次添加快照
  2071 + if (snapShotInfo.find(newObj) == snapShotInfo.end())
  2072 + {
  2073 + //DxAppendLog(DxLOG_INFO, "30");
  2074 + if (LegalMinArea(cur_real_width, cur_real_height, task.task_min_boxsize[cur_real_index]))
  2075 + {
  2076 + //DxAppendLog(DxLOG_INFO, "31");
  2077 + //--------------------- 保存快照视频截图 -----------------------------//
  2078 +
  2079 + int left = max(0, (int)(obj.left - boundaryLittle));
  2080 + int top = max(0, (int)(obj.top - boundaryLittle));
  2081 + int right = min({ frameWidth - 1, (int)(obj.right + boundaryLittle) });
  2082 + int bottom = min({ frameHeight - 1, (int)(obj.bottom + boundaryLittle) });
  2083 + snapShotInfo[newObj].frameCount = task.taskFrameCount;
  2084 + snapShotInfo[newObj].isupdate = true;
  2085 + snapShotInfo[newObj].lost = 0;
  2086 +
  2087 + snapShotInfo[newObj].index.count++;
  2088 + snapShotInfo[newObj].index.index = obj.index;
  2089 +
  2090 + snapShotInfo[newObj].confidence = obj.confidence;
  2091 +
  2092 + snapShotInfo[newObj].box.left = left;
  2093 + snapShotInfo[newObj].box.top = top;
  2094 + snapShotInfo[newObj].box.right = right;
  2095 + snapShotInfo[newObj].box.bottom = bottom;
  2096 + snapShotInfo[newObj].lastArea = (bottom - top)*(right - left);
  2097 +
  2098 + snapShotInfo[newObj].flags[0] = left < minDistance[0] + SCALE_OUT ? 0 : 1; //left
  2099 + snapShotInfo[newObj].flags[1] = top < minDistance[1] + SCALE_OUT ? 0 : 1; //top
  2100 + snapShotInfo[newObj].flags[2] = right > frameWidth - minDistance[2] - SCALE_OUT ? 0 : 1; //right
  2101 + snapShotInfo[newObj].flags[3] = bottom > frameHeight - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom
  2102 +
  2103 + snapShotInfo[newObj].snapShotLittle.frame = NULL;
  2104 + snapShotInfo[newObj].snapShot.frame = NULL;
  2105 +
  2106 + if (task.folderName != NULL){
  2107 + FRAME_KEY frame_id = { newObj.videoID, task.taskFrameCount };
  2108 + ImgSaveCache.insert(newObj, frame_id, task.task_algorithm_data);
  2109 +
  2110 + snapShotInfo[newObj].snapShot.height = frameHeight;
  2111 + snapShotInfo[newObj].snapShot.width = frameWidth;
  2112 + }
  2113 +
  2114 +
  2115 + //--------------------- 保存快照抠图 -----------------------------/
  2116 + int vLeft = max(0, obj.left - boundary);
  2117 + int vTop = max(0, obj.top - boundary);
  2118 + int vRight = min({ frameWidth - 1, obj.right + boundary });
  2119 + int vBottom = min({ frameHeight - 1, obj.bottom + boundary });
  2120 +
  2121 + if (task.folderNameLittle != NULL)
  2122 + {
  2123 + int cur_width = 0;
  2124 + int cur_height = 0;
  2125 +
  2126 + if (0 == snapShotInfo[newObj].index.index)
  2127 + {
  2128 + cur_width = HP_WIDTH;
  2129 + cur_height = HP_HEIGHT;
  2130 + }
  2131 + else if (1 == snapShotInfo[newObj].index.index || 2 == snapShotInfo[newObj].index.index)
  2132 + {
  2133 + cur_width = HCP_WIDTH;
  2134 + cur_height = HCP_HEIGHT;
  2135 + }
  2136 + else if (8 == snapShotInfo[newObj].index.index || (snapShotInfo[newObj].index.index >= 4 && snapShotInfo[newObj].index.index <= 6))
  2137 + {
  2138 + cur_width = VEHICLE_WIDTH;
  2139 + cur_height = VEHICLE_HEIGHT;
  2140 + }
  2141 + else //其余类别
  2142 + {
  2143 + cur_width = vRight - vLeft;
  2144 + cur_height = vBottom - vTop;
  2145 + }
  2146 +
  2147 + if (cur_width != 0 && cur_height != 0)
  2148 + {
  2149 + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, IMG_CHANNELS * cur_width * cur_height * sizeof(unsigned char));
  2150 + snapShotInfo[newObj].snapShotLittle.height = cur_height;
  2151 + snapShotInfo[newObj].snapShotLittle.width = cur_width;
  2152 +
  2153 + cropInfo.snapshot_image_data = (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame;
  2154 + cropInfo.snapshot_left = vLeft;
  2155 + cropInfo.snapshot_top = vTop;
  2156 + cropInfo.snapshot_right = vRight;
  2157 + cropInfo.snapshot_bottom = vBottom;
  2158 + cropInfo.snapshot_dst_width = cur_width;
  2159 + cropInfo.snapshot_dst_height = cur_height;
  2160 +
  2161 + cropInfo.bCrop = true;
  2162 + }
  2163 + }
  2164 + }
  2165 + }
  2166 + else
  2167 + {
  2168 + //DxAppendLog(DxLOG_INFO, "36");
  2169 + bool updateShotInfo = false;
  2170 + int oldIndex = snapShotInfo[newObj].index.index;
  2171 + snapShotInfo[newObj].frameCount = task.taskFrameCount;
  2172 + snapShotInfo[newObj].isupdate = true;
  2173 + snapShotInfo[newObj].lost = 0;
  2174 +
  2175 + if (snapShotInfo[newObj].index.count == 0)
  2176 + {
  2177 + snapShotInfo[newObj].index.count++;
  2178 + snapShotInfo[newObj].index.index = obj.index;
  2179 + }
  2180 + else
  2181 + {
  2182 + if (snapShotInfo[newObj].index.index == obj.index)
  2183 + snapShotInfo[newObj].index.count++;
  2184 + else
  2185 + snapShotInfo[newObj].index.count--;
  2186 + }
  2187 + if (oldIndex != snapShotInfo[newObj].index.index)
  2188 + {
  2189 + updateShotInfo = true;
  2190 + }
  2191 +
  2192 + int left = max(0, (int)(obj.left - boundaryLittle));
  2193 + int top = max(0, (int)(obj.top - boundaryLittle));
  2194 + int right = min(frameWidth - 1, (int)(obj.right + boundaryLittle));
  2195 + int bottom = min(frameHeight - 1, (int)(obj.bottom + boundaryLittle));
  2196 +
  2197 + int maxArea = (snapShotInfo[newObj].box.right - snapShotInfo[newObj].box.left)*(snapShotInfo[newObj].box.bottom - snapShotInfo[newObj].box.top);
  2198 +
  2199 + if ((LegalArea(maxArea, snapShotInfo[newObj].lastArea, left, top, right, bottom)
  2200 + && LegalPos(snapShotInfo[newObj].flags, left, top, right, bottom, frameHeight, frameWidth, minDistance)
  2201 + && LegalMinArea(cur_real_width, cur_real_height, task.task_min_boxsize[cur_real_index])) || updateShotInfo)
  2202 + {
  2203 + //DxAppendLog(DxLOG_INFO, "37");
  2204 + int boundary_w = (obj.right - obj.left) * 0.1;
  2205 + int boundary_h = (obj.bottom - obj.top)* 0.1;
  2206 +
  2207 + int boundary_left = boundary_w, boundary_right = boundary_w, boundary_top = boundary_h, boundary_bottom = boundary_h;
  2208 +
  2209 + ExpandMargin((left - snapShotInfo[newObj].box.left),
  2210 + (bottom - snapShotInfo[newObj].box.bottom),
  2211 + boundary_w, boundary_h, boundary_left, boundary_right, boundary_top, boundary_bottom);
  2212 +
  2213 + snapShotInfo[newObj].box.left = left;
  2214 + snapShotInfo[newObj].box.top = top;
  2215 + snapShotInfo[newObj].box.right = right;
  2216 + snapShotInfo[newObj].box.bottom = bottom;
  2217 + //printf("ori: %d %d %d %d\n", left, top, right - left, bottom - top);
  2218 + snapShotInfo[newObj].confidence = obj.confidence;
  2219 + if (task.folderName != NULL)
  2220 + {
  2221 + FRAME_KEY frame_id = { newObj.videoID, task.taskFrameCount };
  2222 + ImgSaveCache.insert(newObj, frame_id, task.task_algorithm_data);
  2223 + }
  2224 +
  2225 + //--------------------- 保存快照抠图 -----------------------------//
  2226 + int vLeft = max(0, obj.left - boundary_left);
  2227 + int vTop = max(0, obj.top - boundary_top);
  2228 + int vRight = min(frameWidth - 1, obj.right + boundary_right);
  2229 + int vBottom = min(frameHeight - 1, obj.bottom + boundary_bottom);
  2230 + if (task.folderNameLittle != NULL)
  2231 + {
  2232 +
  2233 + if (0 == snapShotInfo[newObj].index.index)
  2234 + {
  2235 + if (snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT)
  2236 + {
  2237 + cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存
  2238 + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char));
  2239 + snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH;
  2240 + snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT;
  2241 + }
  2242 +
  2243 + cropInfo.snapshot_image_data = (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame;
  2244 + cropInfo.snapshot_left = vLeft;
  2245 + cropInfo.snapshot_top = vTop;
  2246 + cropInfo.snapshot_right = vRight;
  2247 + cropInfo.snapshot_bottom = vBottom;
  2248 + cropInfo.snapshot_dst_width = HP_WIDTH;
  2249 + cropInfo.snapshot_dst_height = HP_HEIGHT;
  2250 + cropInfo.bCrop = true;
  2251 + }
  2252 + else if (1 == snapShotInfo[newObj].index.index || 2 == snapShotInfo[newObj].index.index)
  2253 + {
  2254 + if (snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT)
  2255 + {
  2256 + cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存
  2257 + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char));
  2258 + snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH;
  2259 + snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT;
  2260 + }
  2261 +
  2262 + cropInfo.snapshot_image_data = (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame;
  2263 + cropInfo.snapshot_left = vLeft;
  2264 + cropInfo.snapshot_top = vTop;
  2265 + cropInfo.snapshot_right = vRight;
  2266 + cropInfo.snapshot_bottom = vBottom;
  2267 + cropInfo.snapshot_dst_width = HCP_WIDTH;
  2268 + cropInfo.snapshot_dst_height = HCP_HEIGHT;
  2269 + cropInfo.bCrop = true;
  2270 + }
  2271 + else if (8 == snapShotInfo[newObj].index.index || (snapShotInfo[newObj].index.index >= 4 && snapShotInfo[newObj].index.index <= 6))
  2272 + {
  2273 + //DxAppendLog(DxLOG_INFO, "43.1");
  2274 + if (snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT)
  2275 + {
  2276 + //DxAppendLog(DxLOG_INFO, "44");
  2277 + cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存
  2278 + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char));
  2279 + snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH;
  2280 + snapShotInfo[newObj].snapShotLittle.height = VEHICLE_HEIGHT;
  2281 + }
  2282 +
  2283 + cropInfo.snapshot_image_data = (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame;
  2284 + cropInfo.snapshot_left = vLeft;
  2285 + cropInfo.snapshot_top = vTop;
  2286 + cropInfo.snapshot_right = vRight;
  2287 + cropInfo.snapshot_bottom = vBottom;
  2288 + cropInfo.snapshot_dst_width = VEHICLE_WIDTH;
  2289 + cropInfo.snapshot_dst_height = VEHICLE_HEIGHT;
  2290 + cropInfo.bCrop = true;
  2291 + }
  2292 + else
  2293 + {
  2294 + int cur_width = vRight - vLeft;
  2295 + int cur_height = vBottom - vTop;
  2296 + if (cur_width != 0 && cur_height != 0) {
  2297 + cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存
  2298 + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char));
  2299 + snapShotInfo[newObj].snapShotLittle.height = vBottom - vTop;
  2300 + snapShotInfo[newObj].snapShotLittle.width = vRight - vLeft;
  2301 +
  2302 + //printf("begin partMemCopy: %d %d %d %d %d %d\n", vLeft, vTop, vRight, vBottom, frameWidth, frameHeight);
  2303 + partMemCopy((unsigned char*)task.task_algorithm_data.frame, frameWidth, frameHeight,
  2304 + (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom);
  2305 + }
  2306 + }
  2307 +
  2308 + }
  2309 + }
  2310 + snapShotInfo[newObj].lastArea = (bottom - top)*(right - left);
  2311 + }
  2312 +
  2313 + return cropInfo;
  2314 +}
  2315 +
  2316 +int snapshot_helper::getIndexByKey(OBJ_KEY newObj) {
  2317 + if (snapShotInfo.find(newObj) == snapShotInfo.end()) {
  2318 + return snapShotInfo[newObj].index.index;
  2319 + }
  2320 +
  2321 + return -1;
2046 2322 }
2047 2323 \ No newline at end of file
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h
... ... @@ -118,6 +118,17 @@ struct SNAPSHOT_IMAGE_UNIT {
118 118 SNAPSHOT_IMAGE_UNIT() {}
119 119 };
120 120  
  121 +struct CropInfo {
  122 + bool bCrop {false};
  123 + unsigned char* snapshot_image_data {nullptr};
  124 + int snapshot_left;
  125 + int snapshot_right;
  126 + int snapshot_top;
  127 + int snapshot_bottom;
  128 + int snapshot_dst_width;
  129 + int snapshot_dst_height;
  130 +};
  131 +
121 132 enum {
122 133 HP_ANALYSIS,
123 134 HCP_ANALYSIS,
... ... @@ -182,6 +193,10 @@ public:
182 193 void object_attri_analysis();
183 194 void snapshot_res_callback(OBJ_KEY obj_key,/* OBJ_VALUE obj_value,*/ void* analysisRes = NULL);
184 195  
  196 + CropInfo cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Task task);
  197 +
  198 + int getIndexByKey(OBJ_KEY newObj);
  199 +
185 200 private:
186 201 int save_snapshot(bool is_image, bool on_image_display, OBJ_KEY obj_key, char* filename, char* mode, float* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom);
187 202 int save_snapshot(bool is_image, bool on_image_display, OBJ_KEY obj_key, char* filename, char* mode, unsigned char* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom);
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/vf_fea.h deleted
1   -#pragma once
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.cpp
1 1 #include "Sort.h"
2 2 #include <opencv2/opencv.hpp>
3   -#include "../../FFNvDecoder/ImageSaveGPU.h"
  3 +
4 4  
5 5 #ifdef _MSC_VER
6 6 #include <io.h>
... ...