Commit 13fb7a260662c37c2b74c8d65b1892c6e8f451d8

Authored by Hu Chunming
1 parent bab9a6c3

代码优化

vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp
@@ -744,10 +744,14 @@ void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_Obj @@ -744,10 +744,14 @@ void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_Obj
744 newObjInfo.right = obj[c].right; 744 newObjInfo.right = obj[c].right;
745 newObjInfo.top = obj[c].top; 745 newObjInfo.top = obj[c].top;
746 newObjInfo.bottom = obj[c].bottom; 746 newObjInfo.bottom = obj[c].bottom;
747 - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) 747 +
  748 + int index = m_snaphot_helper.getIndexByKey(newObj);
  749 + if(index < 0) {
748 newObjInfo.index = obj[c].index; 750 newObjInfo.index = obj[c].index;
749 - else  
750 - newObjInfo.index = m_snaphot_helper.snapShotInfo[newObj].index.index; 751 + } else {
  752 + newObjInfo.index = index;
  753 + }
  754 +
751 newObjInfo.confidence = obj[c].confidence; 755 newObjInfo.confidence = obj[c].confidence;
752 if (taskObjInfoCallbackFunc != nullptr) 756 if (taskObjInfoCallbackFunc != nullptr)
753 { 757 {
@@ -1067,11 +1071,10 @@ void CMutliSourceVideoProcess::algorthim_process() @@ -1067,11 +1071,10 @@ void CMutliSourceVideoProcess::algorthim_process()
1067 //实时查看模块 绘制目标框到画面上 1071 //实时查看模块 绘制目标框到画面上
1068 if (view) 1072 if (view)
1069 { 1073 {
1070 - int index = 0;  
1071 - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) 1074 + int index = m_snaphot_helper.getIndexByKey(newObj);
  1075 + if(index < 0) {
1072 index = VPTResult[i].obj[c].index; 1076 index = VPTResult[i].obj[c].index;
1073 - else  
1074 - index = m_snaphot_helper.snapShotInfo[newObj].index.index; 1077 + }
1075 1078
1076 //cout << "---- vew ---- "; 1079 //cout << "---- vew ---- ";
1077 int p1 = VPTResult[i].obj[c].left - 10 > 0 ? VPTResult[i].obj[c].left - 10 : 0; 1080 int p1 = VPTResult[i].obj[c].left - 10 > 0 ? VPTResult[i].obj[c].left - 10 : 0;
@@ -1153,26 +1156,17 @@ void CMutliSourceVideoProcess::algorthim_process() @@ -1153,26 +1156,17 @@ void CMutliSourceVideoProcess::algorthim_process()
1153 cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; 1156 cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl;
1154 #endif 1157 #endif
1155 1158
1156 -  
1157 - auto task_iter = TaskinPlayID.begin();  
1158 -  
1159 AttributionAnalysis = false; 1159 AttributionAnalysis = false;
1160 1160
1161 long long second_analysis_time = get_cur_time_ms(); 1161 long long second_analysis_time = get_cur_time_ms();
1162 1162
  1163 + auto task_iter = TaskinPlayID.begin();
1163 for (int i = 0; i < curPlayTaskCount; i++) 1164 for (int i = 0; i < curPlayTaskCount; i++)
1164 { 1165 {
1165 for (int j = 0; j < deleteObjectID[i].size(); j++) 1166 for (int j = 0; j < deleteObjectID[i].size(); j++)
1166 { 1167 {
1167 OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; 1168 OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] };
1168 -  
1169 - if (m_snaphot_helper.snapShotInfo.find(deleteObj) == m_snaphot_helper.snapShotInfo.end())  
1170 - continue;  
1171 -  
1172 - auto iter = m_snaphot_helper.snapShotInfo.find(deleteObj);  
1173 - iter->second.finishTracker = true;  
1174 -  
1175 - m_snaphot_helper.SaveResultInFile(iter->first, iter->second); 1169 + m_snaphot_helper.SaveResultInFile(deleteObj);
1176 } 1170 }
1177 1171
1178 task_iter++; 1172 task_iter++;
@@ -1220,7 +1214,7 @@ void CMutliSourceVideoProcess::algorthim_process() @@ -1220,7 +1214,7 @@ void CMutliSourceVideoProcess::algorthim_process()
1220 long long costTime1 = get_cur_time_ms() - begintime1; 1214 long long costTime1 = get_cur_time_ms() - begintime1;
1221 LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times); 1215 LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times);
1222 1216
1223 - m_snaphot_helper.snapShotInfo.clear(); 1217 + m_snaphot_helper.clearSnapshotInfo();
1224 ProcessFlag = false; 1218 ProcessFlag = false;
1225 1219
1226 if (batch_img != NULL) 1220 if (batch_img != NULL)
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp
@@ -585,7 +585,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 @@ -585,7 +585,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是
585 if (!hcp_keys.empty()) 585 if (!hcp_keys.empty())
586 { 586 {
587 LOG_DEBUG("hcp_keys size: {}", hcp_keys.size()); 587 LOG_DEBUG("hcp_keys size: {}", hcp_keys.size());
588 - 588 +
589 const int obj_batch_count = OBJ_BATCH_COUNT / OBJ_SCALE; 589 const int obj_batch_count = OBJ_BATCH_COUNT / OBJ_SCALE;
590 const int hcp_batch_size = hcp_keys.size(); 590 const int hcp_batch_size = hcp_keys.size();
591 int hcp_batch_count = obj_batch_count; 591 int hcp_batch_count = obj_batch_count;
@@ -1977,8 +1977,17 @@ int snapshot_helper::save_snapshot(bool is_image, bool on_image_display, OBJ_KEY @@ -1977,8 +1977,17 @@ int snapshot_helper::save_snapshot(bool is_image, bool on_image_display, OBJ_KEY
1977 return 1; 1977 return 1;
1978 } 1978 }
1979 1979
1980 -int snapshot_helper::SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value) 1980 +int snapshot_helper::SaveResultInFile(OBJ_KEY deleteObj)
1981 { 1981 {
  1982 + auto it = snapShotInfo.find(deleteObj);
  1983 + if(it == snapShotInfo.end()){
  1984 + return 0;
  1985 + }
  1986 + it->second.finishTracker = true;
  1987 +
  1988 + const OBJ_KEY & obj_key = it->first;
  1989 + const OBJ_VALUE & obj_value = it->second;
  1990 +
1982 if (0 == obj_value.index.index && obj_value.snapShotLittle.width == HP_WIDTH && obj_value.snapShotLittle.height == HP_HEIGHT) 1991 if (0 == obj_value.index.index && obj_value.snapShotLittle.width == HP_WIDTH && obj_value.snapShotLittle.height == HP_HEIGHT)
1983 { 1992 {
1984 if (face_detect_cf == SY_CONFIG_OPEN) 1993 if (face_detect_cf == SY_CONFIG_OPEN)
@@ -2297,7 +2306,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas @@ -2297,7 +2306,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas
2297 } 2306 }
2298 2307
2299 int snapshot_helper::getIndexByKey(OBJ_KEY newObj) { 2308 int snapshot_helper::getIndexByKey(OBJ_KEY newObj) {
2300 - if (snapShotInfo.find(newObj) == snapShotInfo.end()) { 2309 + if (snapShotInfo.find(newObj) != snapShotInfo.end()) {
2301 return snapShotInfo[newObj].index.index; 2310 return snapShotInfo[newObj].index.index;
2302 } 2311 }
2303 2312
@@ -2448,4 +2457,8 @@ void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count, @@ -2448,4 +2457,8 @@ void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count,
2448 delete[] face_det_result[fd_i].info; 2457 delete[] face_det_result[fd_i].info;
2449 delete face_det_result; 2458 delete face_det_result;
2450 } 2459 }
  2460 +}
  2461 +
  2462 +void snapshot_helper::clearSnapshotInfo() {
  2463 + snapShotInfo.clear();
2451 } 2464 }
2452 \ No newline at end of file 2465 \ No newline at end of file
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h
@@ -58,7 +58,7 @@ struct AABBBOX @@ -58,7 +58,7 @@ struct AABBBOX
58 }; 58 };
59 59
60 struct OBJ_INDEX { 60 struct OBJ_INDEX {
61 - int index; 61 + int index {-1};
62 int count; //用于对index的计数 62 int count; //用于对index的计数
63 }; 63 };
64 64
@@ -154,7 +154,6 @@ public: @@ -154,7 +154,6 @@ public:
154 154
155 public: 155 public:
156 std::mutex callback_tx; 156 std::mutex callback_tx;
157 - map<OBJ_KEY, OBJ_VALUE> snapShotInfo;  
158 queue<SNAPSHOT_IMAGE_UNIT> snapshotImageQueue; 157 queue<SNAPSHOT_IMAGE_UNIT> snapshotImageQueue;
159 map<OBJ_KEY, video_object_snapshot> finished_analysis_ss_info; 158 map<OBJ_KEY, video_object_snapshot> finished_analysis_ss_info;
160 queue<OBJ_KEY> finished_save_ss_info_que; 159 queue<OBJ_KEY> finished_save_ss_info_que;
@@ -175,7 +174,7 @@ public: @@ -175,7 +174,7 @@ public:
175 void add_task_info(int new_task_id, TASK_INFO new_task_info); 174 void add_task_info(int new_task_id, TASK_INFO new_task_info);
176 void delete_task_info(int new_task_id, TASK_INFO new_task_info); 175 void delete_task_info(int new_task_id, TASK_INFO new_task_info);
177 176
178 - int SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value); 177 + int SaveResultInFile(OBJ_KEY deleteObj);
179 178
180 void erase_snapshotImage(OBJ_KEY obj_key); 179 void erase_snapshotImage(OBJ_KEY obj_key);
181 //整体的三种二次属性分析 180 //整体的三种二次属性分析
@@ -199,6 +198,9 @@ public: @@ -199,6 +198,9 @@ public:
199 void cacheFaceSnapshotInfo(sy_img *human_img, int human_count, sy_point* ori_points, vector<int> human_idx, vector<OBJ_KEY> human_obj_keys, int snapshot_left[], int snapshot_top[], Task task); 198 void cacheFaceSnapshotInfo(sy_img *human_img, int human_count, sy_point* ori_points, vector<int> human_idx, vector<OBJ_KEY> human_obj_keys, int snapshot_left[], int snapshot_top[], Task task);
200 199
201 int getIndexByKey(OBJ_KEY newObj); 200 int getIndexByKey(OBJ_KEY newObj);
  201 + std::map<OBJ_KEY, OBJ_VALUE>::iterator getValueByKey(OBJ_KEY newObj);
  202 +
  203 + void clearSnapshotInfo();
202 204
203 private: 205 private:
204 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); 206 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);
@@ -221,6 +223,8 @@ private: @@ -221,6 +223,8 @@ private:
221 VehicleRecognition m_vehicle_recognition; 223 VehicleRecognition m_vehicle_recognition;
222 face_det_module m_face_det_module; 224 face_det_module m_face_det_module;
223 225
  226 + map<OBJ_KEY, OBJ_VALUE> snapShotInfo;
  227 +
224 queue<OBJ_KEY> count_person; 228 queue<OBJ_KEY> count_person;
225 queue<OBJ_KEY> count_bike; 229 queue<OBJ_KEY> count_bike;
226 queue<OBJ_KEY> count_vehicle; 230 queue<OBJ_KEY> count_vehicle;