From 13fb7a260662c37c2b74c8d65b1892c6e8f451d8 Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Fri, 3 Nov 2023 11:50:01 +0800 Subject: [PATCH] 代码优化 --- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp | 32 +++++++++++++------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp | 19 ++++++++++++++++--- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h | 10 +++++++--- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp index 60371ba..108eb7e 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp @@ -744,10 +744,14 @@ void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_Obj newObjInfo.right = obj[c].right; newObjInfo.top = obj[c].top; newObjInfo.bottom = obj[c].bottom; - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) + + int index = m_snaphot_helper.getIndexByKey(newObj); + if(index < 0) { newObjInfo.index = obj[c].index; - else - newObjInfo.index = m_snaphot_helper.snapShotInfo[newObj].index.index; + } else { + newObjInfo.index = index; + } + newObjInfo.confidence = obj[c].confidence; if (taskObjInfoCallbackFunc != nullptr) { @@ -1067,11 +1071,10 @@ void CMutliSourceVideoProcess::algorthim_process() //实时查看模块 绘制目标框到画面上 if (view) { - int index = 0; - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) + int index = m_snaphot_helper.getIndexByKey(newObj); + if(index < 0) { index = VPTResult[i].obj[c].index; - else - index = m_snaphot_helper.snapShotInfo[newObj].index.index; + } //cout << "---- vew ---- "; int p1 = VPTResult[i].obj[c].left - 10 > 0 ? VPTResult[i].obj[c].left - 10 : 0; @@ -1153,26 +1156,17 @@ void CMutliSourceVideoProcess::algorthim_process() cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; #endif - - auto task_iter = TaskinPlayID.begin(); - AttributionAnalysis = false; long long second_analysis_time = get_cur_time_ms(); + auto task_iter = TaskinPlayID.begin(); for (int i = 0; i < curPlayTaskCount; i++) { for (int j = 0; j < deleteObjectID[i].size(); j++) { OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; - - if (m_snaphot_helper.snapShotInfo.find(deleteObj) == m_snaphot_helper.snapShotInfo.end()) - continue; - - auto iter = m_snaphot_helper.snapShotInfo.find(deleteObj); - iter->second.finishTracker = true; - - m_snaphot_helper.SaveResultInFile(iter->first, iter->second); + m_snaphot_helper.SaveResultInFile(deleteObj); } task_iter++; @@ -1220,7 +1214,7 @@ void CMutliSourceVideoProcess::algorthim_process() long long costTime1 = get_cur_time_ms() - begintime1; LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times); - m_snaphot_helper.snapShotInfo.clear(); + m_snaphot_helper.clearSnapshotInfo(); ProcessFlag = false; if (batch_img != NULL) diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp index 4964222..3b068f7 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp +++ b/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) //是 if (!hcp_keys.empty()) { LOG_DEBUG("hcp_keys size: {}", hcp_keys.size()); - + const int obj_batch_count = OBJ_BATCH_COUNT / OBJ_SCALE; const int hcp_batch_size = hcp_keys.size(); 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 return 1; } -int snapshot_helper::SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value) +int snapshot_helper::SaveResultInFile(OBJ_KEY deleteObj) { + auto it = snapShotInfo.find(deleteObj); + if(it == snapShotInfo.end()){ + return 0; + } + it->second.finishTracker = true; + + const OBJ_KEY & obj_key = it->first; + const OBJ_VALUE & obj_value = it->second; + if (0 == obj_value.index.index && obj_value.snapShotLittle.width == HP_WIDTH && obj_value.snapShotLittle.height == HP_HEIGHT) { if (face_detect_cf == SY_CONFIG_OPEN) @@ -2297,7 +2306,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas } int snapshot_helper::getIndexByKey(OBJ_KEY newObj) { - if (snapShotInfo.find(newObj) == snapShotInfo.end()) { + if (snapShotInfo.find(newObj) != snapShotInfo.end()) { return snapShotInfo[newObj].index.index; } @@ -2448,4 +2457,8 @@ void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count, delete[] face_det_result[fd_i].info; delete face_det_result; } +} + +void snapshot_helper::clearSnapshotInfo() { + snapShotInfo.clear(); } \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h index ece4cde..7f081fc 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h @@ -58,7 +58,7 @@ struct AABBBOX }; struct OBJ_INDEX { - int index; + int index {-1}; int count; //用于对index的计数 }; @@ -154,7 +154,6 @@ public: public: std::mutex callback_tx; - map snapShotInfo; queue snapshotImageQueue; map finished_analysis_ss_info; queue finished_save_ss_info_que; @@ -175,7 +174,7 @@ public: void add_task_info(int new_task_id, TASK_INFO new_task_info); void delete_task_info(int new_task_id, TASK_INFO new_task_info); - int SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value); + int SaveResultInFile(OBJ_KEY deleteObj); void erase_snapshotImage(OBJ_KEY obj_key); //整体的三种二次属性分析 @@ -199,6 +198,9 @@ public: void cacheFaceSnapshotInfo(sy_img *human_img, int human_count, sy_point* ori_points, vector human_idx, vector human_obj_keys, int snapshot_left[], int snapshot_top[], Task task); int getIndexByKey(OBJ_KEY newObj); + std::map::iterator getValueByKey(OBJ_KEY newObj); + + void clearSnapshotInfo(); private: 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: VehicleRecognition m_vehicle_recognition; face_det_module m_face_det_module; + map snapShotInfo; + queue count_person; queue count_bike; queue count_vehicle; -- libgit2 0.21.4