From 5e9071740a5c86ccb7d7fd3c9c9713bb7b2e02d0 Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Thu, 2 Nov 2023 19:24:28 +0800 Subject: [PATCH] 代码优化,改动较大,但是未改变代码逻辑 --- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/ImageSaveGPU.cpp | 3 ++- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp | 305 +++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h | 102 ++---------------------------------------------------------------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MyAtomic.hpp | 42 ++++++++++++++++++++++++++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h | 23 ++--------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.cpp | 35 +++++++++++++++++------------------ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.h | 10 +++++++--- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehiclePlate.cpp | 24 ++++++++++++------------ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp | 276 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h | 15 +++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/vf_fea.h | 1 - vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.cpp | 2 +- 13 files changed, 464 insertions(+), 441 deletions(-) create mode 100644 vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MyAtomic.hpp delete mode 100644 vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/vf_fea.h diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/ImageSaveGPU.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/ImageSaveGPU.cpp index eb0e759..d15aab5 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/ImageSaveGPU.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/ImageSaveGPU.cpp @@ -1,5 +1,6 @@ -#include "cuda_kernels.h" +#include "ImageSaveGPU.h" +#include "cuda_kernels.h" #include "logger.hpp" 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 3cfe677..e233aa3 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 @@ -290,9 +290,6 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN if (tObjInfoCallbackFunc != nullptr) taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1); - minDistance[0] = minDistance[2] = 35; //left right - minDistance[1] = minDistance[3] = 50; //top bottom - m_hp_analysis_config = vptParam.hp_analysis_config; m_hcp_analysis_config = vptParam.hcp_analysis_config; m_vehicle_analysis_config = vptParam.vehicle_analysis_config; @@ -1075,15 +1072,15 @@ void CMutliSourceVideoProcess::algorthim_process() { OBJ_KEY newObj = { (*iter), VPTResult[i].obj[c].id }; - int index = 0; - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) - index = VPTResult[i].obj[c].index; - else - index = m_snaphot_helper.snapShotInfo[newObj].index.index; - //实时查看模块 绘制目标框到画面上 if (view) { + int index = 0; + if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) + 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; int p2 = VPTResult[i].obj[c].top - 15 > 0 ? VPTResult[i].obj[c].top - 15 : 0; @@ -1100,284 +1097,24 @@ void CMutliSourceVideoProcess::algorthim_process() #endif } - //逐个目标更新快照 - int boundary = 10; - int boundaryLittle = 4; - - int cur_real_width = (VPTResult[i].obj[c].right - VPTResult[i].obj[c].left); - int cur_real_height = (VPTResult[i].obj[c].bottom - VPTResult[i].obj[c].top); - int cur_real_index = VPTResult[i].obj[c].index; - - //第一次添加快照 - if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) - { - //DxAppendLog(DxLOG_INFO, "30"); - if (LegalMinArea(cur_real_width, cur_real_height, tasks[*iter].task_min_boxsize[cur_real_index])) - { - //DxAppendLog(DxLOG_INFO, "31"); - //--------------------- 保存快照视频截图 -----------------------------// - - int left = max(0, (int)(VPTResult[i].obj[c].left - boundaryLittle)); - int top = max(0, (int)(VPTResult[i].obj[c].top - boundaryLittle)); - int right = min({ frameWidth - 1, (int)(VPTResult[i].obj[c].right + boundaryLittle) }); - int bottom = min({ frameHeight - 1, (int)(VPTResult[i].obj[c].bottom + boundaryLittle) }); - m_snaphot_helper.snapShotInfo[newObj].frameCount = tasks[*iter].taskFrameCount; - m_snaphot_helper.snapShotInfo[newObj].isupdate = true; - m_snaphot_helper.snapShotInfo[newObj].lost = 0; - - m_snaphot_helper.snapShotInfo[newObj].index.count++; - m_snaphot_helper.snapShotInfo[newObj].index.index = VPTResult[i].obj[c].index; - - m_snaphot_helper.snapShotInfo[newObj].confidence = VPTResult[i].obj[c].confidence; - - m_snaphot_helper.snapShotInfo[newObj].box.left = left; - m_snaphot_helper.snapShotInfo[newObj].box.top = top; - m_snaphot_helper.snapShotInfo[newObj].box.right = right; - m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; - m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); - - m_snaphot_helper.snapShotInfo[newObj].flags[0] = left < minDistance[0] + SCALE_OUT ? 0 : 1; //left - m_snaphot_helper.snapShotInfo[newObj].flags[1] = top < minDistance[1] + SCALE_OUT ? 0 : 1; //top - m_snaphot_helper.snapShotInfo[newObj].flags[2] = right > frameWidth - minDistance[2] - SCALE_OUT ? 0 : 1; //right - m_snaphot_helper.snapShotInfo[newObj].flags[3] = bottom > frameHeight - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom - - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame = NULL; - m_snaphot_helper.snapShotInfo[newObj].snapShot.frame = NULL; - - if (tasks[*iter].folderName != NULL) - { - //DxAppendLog(DxLOG_INFO, "32"); - FRAME_KEY frame_id = { (*iter),tasks[*iter].taskFrameCount }; - m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, tasks[*iter].task_algorithm_data); - - m_snaphot_helper.snapShotInfo[newObj].snapShot.height = frameHeight; - m_snaphot_helper.snapShotInfo[newObj].snapShot.width = frameWidth; - } - - - //--------------------- 保存快照抠图 -----------------------------/ - int vLeft = 0; - int vTop = 0; - int vRight = 0; - int vBottom = 0; - - vLeft = max(0, VPTResult[i].obj[c].left - boundary); - vTop = max(0, VPTResult[i].obj[c].top - boundary); - vRight = min({ frameWidth - 1, VPTResult[i].obj[c].right + boundary }); - vBottom = min({ frameHeight - 1, VPTResult[i].obj[c].bottom + boundary }); - //DxAppendLog(DxLOG_INFO, "34"); - if (tasks[*iter].folderNameLittle != NULL) - { - //DxAppendLog(DxLOG_INFO, "35"); - int cur_width = 0; - int cur_height = 0; - - if (0 == m_snaphot_helper.snapShotInfo[newObj].index.index) - { - cur_width = HP_WIDTH; - cur_height = HP_HEIGHT; - - human_idx.emplace_back(copy_obj_count); - human_obj_keys.emplace_back (newObj); - } - else if (1 == m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == m_snaphot_helper.snapShotInfo[newObj].index.index) - { - cur_width = HCP_WIDTH; - cur_height = HCP_HEIGHT; - } - 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)) - { - cur_width = VEHICLE_WIDTH; - cur_height = VEHICLE_HEIGHT; - } - else //其余类别 - { - cur_width = vRight - vLeft; - cur_height = vBottom - vTop; - } - - if (cur_width != 0 && cur_height != 0) - { - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, IMG_CHANNELS * cur_width * cur_height * sizeof(unsigned char)); - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = cur_height; - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = cur_width; - - snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; - snapshot_left[copy_obj_count] = vLeft; - snapshot_top[copy_obj_count] = vTop; - snapshot_right[copy_obj_count] = vRight; - snapshot_bottom[copy_obj_count] = vBottom; - - snapshot_dst_width[copy_obj_count] = cur_width; - snapshot_dst_height[copy_obj_count++] = cur_height; - } - } - } - } - else - { - //DxAppendLog(DxLOG_INFO, "36"); - bool updateShotInfo = false; - int oldIndex = m_snaphot_helper.snapShotInfo[newObj].index.index; - m_snaphot_helper.snapShotInfo[newObj].frameCount = tasks[*iter].taskFrameCount; - m_snaphot_helper.snapShotInfo[newObj].isupdate = true; - m_snaphot_helper.snapShotInfo[newObj].lost = 0; - - if (m_snaphot_helper.snapShotInfo[newObj].index.count == 0) - { - m_snaphot_helper.snapShotInfo[newObj].index.count++; - m_snaphot_helper.snapShotInfo[newObj].index.index = VPTResult[i].obj[c].index; - } - else - { - if (m_snaphot_helper.snapShotInfo[newObj].index.index == VPTResult[i].obj[c].index) - m_snaphot_helper.snapShotInfo[newObj].index.count++; - else - m_snaphot_helper.snapShotInfo[newObj].index.count--; + CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, VPTResult[i].obj[c], tasks[*iter]); + if(crop_info.bCrop){ + snapshot_image_data[copy_obj_count] = crop_info.snapshot_image_data; + snapshot_left[copy_obj_count] = crop_info.snapshot_left; + snapshot_top[copy_obj_count] = crop_info.snapshot_top; + snapshot_right[copy_obj_count] = crop_info.snapshot_right; + snapshot_bottom[copy_obj_count] = crop_info.snapshot_bottom; + snapshot_dst_width[copy_obj_count] = crop_info.snapshot_dst_width; + snapshot_dst_height[copy_obj_count] = crop_info.snapshot_dst_height; + + int index = m_snaphot_helper.getIndexByKey(newObj); + if(0 == index) { + human_idx.push_back(copy_obj_count); + human_obj_keys.emplace_back(newObj); } - if (oldIndex != m_snaphot_helper.snapShotInfo[newObj].index.index) - { - updateShotInfo = true; - } - - int left = max(0, (int)(VPTResult[i].obj[c].left - boundaryLittle)); - int top = max(0, (int)(VPTResult[i].obj[c].top - boundaryLittle)); - int right = min(frameWidth - 1, (int)(VPTResult[i].obj[c].right + boundaryLittle)); - int bottom = min(frameHeight - 1, (int)(VPTResult[i].obj[c].bottom + boundaryLittle)); - - 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); - - if ((LegalArea(maxArea, m_snaphot_helper.snapShotInfo[newObj].lastArea, left, top, right, bottom) - && LegalPos(m_snaphot_helper.snapShotInfo[newObj].flags, left, top, right, bottom, frameHeight, frameWidth) - && LegalMinArea(cur_real_width, cur_real_height, tasks[*iter].task_min_boxsize[cur_real_index])) || updateShotInfo) - { - //DxAppendLog(DxLOG_INFO, "37"); - int boundary_w = (VPTResult[i].obj[c].right - VPTResult[i].obj[c].left) * 0.1; - int boundary_h = (VPTResult[i].obj[c].bottom - VPTResult[i].obj[c].top)* 0.1; - - int boundary_left = boundary_w, boundary_right = boundary_w, boundary_top = boundary_h, boundary_bottom = boundary_h; - - ExpandMargin((left - m_snaphot_helper.snapShotInfo[newObj].box.left), - (bottom - m_snaphot_helper.snapShotInfo[newObj].box.bottom), - boundary_w, boundary_h, boundary_left, boundary_right, boundary_top, boundary_bottom); - - m_snaphot_helper.snapShotInfo[newObj].box.left = left; - m_snaphot_helper.snapShotInfo[newObj].box.top = top; - m_snaphot_helper.snapShotInfo[newObj].box.right = right; - m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; - //printf("ori: %d %d %d %d\n", left, top, right - left, bottom - top); - m_snaphot_helper.snapShotInfo[newObj].confidence = VPTResult[i].obj[c].confidence; - if (tasks[*iter].folderName != NULL) - { - FRAME_KEY frame_id = { (*iter),tasks[*iter].taskFrameCount }; - m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, tasks[*iter].task_algorithm_data); - } - - //--------------------- 保存快照抠图 -----------------------------// - int vLeft = 0; - int vTop = 0; - int vRight = 0; - int vBottom = 0; - - vLeft = max(0, VPTResult[i].obj[c].left - boundary_left); - vTop = max(0, VPTResult[i].obj[c].top - boundary_top); - vRight = min(frameWidth - 1, VPTResult[i].obj[c].right + boundary_right); - vBottom = min(frameHeight - 1, VPTResult[i].obj[c].bottom + boundary_bottom); - if (tasks[*iter].folderNameLittle != NULL) - { - - if (0 == m_snaphot_helper.snapShotInfo[newObj].index.index) - { - if (m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) - { - cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char)); - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH; - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT; - } - - human_idx.push_back(copy_obj_count); - human_obj_keys.emplace_back(newObj); - - snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; - snapshot_left[copy_obj_count] = vLeft; - snapshot_top[copy_obj_count] = vTop; - snapshot_right[copy_obj_count] = vRight; - snapshot_bottom[copy_obj_count] = vBottom; - //printf("crop: %d %d %d %d\n", vLeft, vTop, vRight - vLeft, vBottom - vTop); - snapshot_dst_width[copy_obj_count] = HP_WIDTH; - snapshot_dst_height[copy_obj_count++] = HP_HEIGHT; - - } - else if (1 == m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == m_snaphot_helper.snapShotInfo[newObj].index.index) - { - //DxAppendLog(DxLOG_INFO, "42"); - if (m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) - { - //DxAppendLog(DxLOG_INFO, "43"); - cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char)); - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH; - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT; - } - - snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; - snapshot_left[copy_obj_count] = vLeft; - snapshot_top[copy_obj_count] = vTop; - snapshot_right[copy_obj_count] = vRight; - snapshot_bottom[copy_obj_count] = vBottom; - - snapshot_dst_width[copy_obj_count] = HCP_WIDTH; - snapshot_dst_height[copy_obj_count++] = HCP_HEIGHT; - - } - 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)) - { - //DxAppendLog(DxLOG_INFO, "43.1"); - if (m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT) - { - //DxAppendLog(DxLOG_INFO, "44"); - cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char)); - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH; - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = VEHICLE_HEIGHT; - } - - snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; - snapshot_left[copy_obj_count] = vLeft; - snapshot_top[copy_obj_count] = vTop; - snapshot_right[copy_obj_count] = vRight; - snapshot_bottom[copy_obj_count] = vBottom; - - snapshot_dst_width[copy_obj_count] = VEHICLE_WIDTH; - snapshot_dst_height[copy_obj_count++] = VEHICLE_HEIGHT; - - } - else - { - //DxAppendLog(DxLOG_INFO, "45"); - // modified by zsh 220614---------------------------- - int cur_width = vRight - vLeft; - int cur_height = vBottom - vTop; - if (cur_width != 0 && cur_height != 0) { - //---------------------------------------- - cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char)); - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = vBottom - vTop; - m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = vRight - vLeft; - - //printf("begin partMemCopy: %d %d %d %d %d %d\n", vLeft, vTop, vRight, vBottom, frameWidth, frameHeight); - partMemCopy((unsigned char*)tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, - (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom); - } - } - - } - } - m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); + copy_obj_count++; } - } //若待抠图的快照数不为0 则进行批量抠图 diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h index 5ca32c7..eb04107 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h @@ -5,7 +5,7 @@ #include #include -#include "../FFNvDecoder/DxDecoderWrap.h" + #include "nvml.h" #include "time.h" #include "opencv2/opencv.hpp" @@ -68,27 +68,9 @@ using namespace std; #define SNAPSHOTFRAME 15 #define LOSTMAXFRAMECCOUNT 4 -#define SCALE_OUT 10 //�ж�Ŀ����ʼλ��ʱ������С����Ļ������ʵ����� - #define MAX_BATCH 10 -extern int minDistance[]; - -enum TaskState -{ - PLAY, - PAUSE, - FINISH, - DECODEERROR //�����߳̿��ܱ���������֮��ֱ�ӽ�������·���� -}; - - - -struct VideoHeightWidth{ - double height; - double width; -}; struct VideoObjectSS { @@ -98,67 +80,7 @@ struct VideoObjectSS VideoObjectSS() : obj_person(NULL), obj_bike(NULL), obj_car(NULL){} }; -template class MyAtomic; -template -bool operator == (MyAtomic & d1, T &d2); - -template -bool operator == (MyAtomic & d1, MyAtomic &d2); -template -class MyAtomic -{ -public: - MyAtomic() {}; - MyAtomic(const T & d) { data.store(d); }; - MyAtomic(const MyAtomic & d) { data.store(d.data.load()); }; - MyAtomic& operator =(T d) { data.store(d); return *this; }; - MyAtomic& operator =(MyAtomic & d) { data.store(d.data.load()); return *this; }; - MyAtomic& operator +=(T d) { data.fetch_add(d); return *this; }; - MyAtomic& operator +=(MyAtomic & d) { data.fetch_add(d); return *this; }; - operator int() { return data.load(); } - friend bool operator == (MyAtomic &d1, T &d2); - friend bool operator == (MyAtomic &d1, MyAtomic &d2); -private: - std::atomic data; -}; -template -bool operator == (MyAtomic & d1, T &d2) -{ - if (d1.data.load() == d2) - return true; - else - return false; -} - -template -bool operator == (MyAtomic & d1, MyAtomic & d2) -{ - if (d1.data.load() == d2.load()) - return true; - else - return false; -} - -struct Task{ - int taskID; - const char *taskFileSource; - TaskState taskState; - DxDecoderWrap *taskTcuvid; - DxGPUFrame task_algorithm_data; //����¿�ܲ���resize�Ĵ���������ʱ��backup��ԭͼ��С��ͼƬ�ͽ��㷨������� - bool taskHasBackup; - //VideoHeightWidth taskHeightWidthRatio; - VideoHeightWidth taskHeightWidth; - MyAtomic taskFrameCount; - MyAtomic taskLastFrameCount; - int taskTotalFrameCount; - SNAPSHOT_CALLBACK taskObjCallbackFunc; - REALTIME_CALLBACK taskRealTimeCallbackFunc; - cv::Mat frameImage; - char* folderNameLittle; - char* folderName; - char* folderNameFace; - sy_rect task_min_boxsize[DETECTTYPE]; -}; + enum TaskOperator { @@ -183,24 +105,7 @@ struct Operator{ VIDEO_REALTIME_CALLBACK taskRealTimeCallbackFunc; sy_rect minBoxsize[DETECTTYPE]; }; - -struct CUVID_USERDATA{ - int id; - void *opaque; -}; - -struct CUVID_DATA{ - float* pData; - int nWidth; - int nHeight; - int nDatasize; -}; -struct SNAPSHOT_PROCESS_UNIT{ - vector imgBig; - vector imgSmall; - vector imgVPTResult; -}; class CMutliSourceVideoProcess { @@ -278,9 +183,6 @@ public: /*��������Ӧ����public�� ������ FINISH_CALLBACK taskFinishCallbackFunc; OBJECT_INFO_CALLBACK taskObjInfoCallbackFunc; - - queue snapshotProcessQueue; - std::mutex taskMutex; std::condition_variable taskCondVar; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MyAtomic.hpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MyAtomic.hpp new file mode 100644 index 0000000..3521bfe --- /dev/null +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MyAtomic.hpp @@ -0,0 +1,42 @@ +#include + +template class MyAtomic; +template +bool operator == (MyAtomic & d1, T &d2); + +template +bool operator == (MyAtomic & d1, MyAtomic &d2); +template +class MyAtomic +{ +public: + MyAtomic() {}; + MyAtomic(const T & d) { data.store(d); }; + MyAtomic(const MyAtomic & d) { data.store(d.data.load()); }; + MyAtomic& operator =(T d) { data.store(d); return *this; }; + MyAtomic& operator =(MyAtomic & d) { data.store(d.data.load()); return *this; }; + MyAtomic& operator +=(T d) { data.fetch_add(d); return *this; }; + MyAtomic& operator +=(MyAtomic & d) { data.fetch_add(d); return *this; }; + operator int() { return data.load(); } + friend bool operator == (MyAtomic &d1, T &d2); + friend bool operator == (MyAtomic &d1, MyAtomic &d2); +private: + std::atomic data; +}; +template +bool operator == (MyAtomic & d1, T &d2) +{ + if (d1.data.load() == d2) + return true; + else + return false; +} + +template +bool operator == (MyAtomic & d1, MyAtomic & d2) +{ + if (d1.data.load() == d2.load()) + return true; + else + return false; +} \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h index 4abf5b9..764b1ae 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h @@ -9,29 +9,10 @@ #include #include "utools.h" #include +#include "common.h" + using namespace std; #define VTTYPECOUNT 10 //֧�ֵ��������� -#define MAX_OBJ_COUNT 100 -typedef struct VPT_ObjInfo //����ṹ�� -{ - int left; - int top; - int right; - int bottom; - int center_x; - int center_y; - int index; // ����/�������֧��10�� - long id; // Ŀ��ΨһID��ͬһIDΪͬһĿ�� - int num; // ��ID�����µĵ�num֡ - double confidence; // ���Ŷ� - int snap_flag; -}VPT_ObjInfo; - -typedef struct VPT_Result -{ - int objCount; - VPT_ObjInfo obj[MAX_OBJ_COUNT]; -}VPT_Result; typedef struct VPTProcess_PARAM diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h index 1092a30..14ee8c6 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h @@ -2,7 +2,17 @@ #define COMMON_H_ #include #include "header.h" + +#include "opencv2/opencv.hpp" +#include "opencv2/highgui/highgui.hpp" + +#include "MyAtomic.hpp" +#include "../FFNvDecoder/DxDecoderWrap.h" + #define IMG_CHANNELS 3 +#define SCALE_OUT 10 //判断目标框初始位置时,在最小距离的基础上适当外扩 +#define MAX_OBJ_COUNT 100 + struct OBJ_KEY { int videoID; int objID; @@ -48,4 +58,61 @@ using SNAPSHOT_CALLBACK = std::function; using REALTIME_CALLBACK = std::function; using FINISH_CALLBACK = std::function; using OBJECT_INFO_CALLBACK = std::function; + + +struct VideoHeightWidth{ + double height; + double width; +}; + +enum TaskState +{ + PLAY, + PAUSE, + FINISH, + DECODEERROR //解码线程可能报错,报错之后直接结束掉该路解码 +}; + +struct Task{ + int taskID; + const char *taskFileSource; + TaskState taskState; + DxDecoderWrap *taskTcuvid; + DxGPUFrame task_algorithm_data; //����¿�ܲ���resize�Ĵ���������ʱ��backup��ԭͼ��С��ͼƬ�ͽ��㷨������� + bool taskHasBackup; + VideoHeightWidth taskHeightWidth; + MyAtomic taskFrameCount; + MyAtomic taskLastFrameCount; + int taskTotalFrameCount; + SNAPSHOT_CALLBACK taskObjCallbackFunc; + REALTIME_CALLBACK taskRealTimeCallbackFunc; + cv::Mat frameImage; + char* folderNameLittle; + char* folderName; + char* folderNameFace; + sy_rect task_min_boxsize[DETECTTYPE]; +}; + +typedef struct VPT_ObjInfo //����ṹ�� +{ + int left; + int top; + int right; + int bottom; + int center_x; + int center_y; + int index; // ����/�������֧��10�� + long id; // Ŀ��ΨһID��ͬһIDΪͬһĿ�� + int num; // ��ID�����µĵ�num֡ + double confidence; // ���Ŷ� + int snap_flag; +}VPT_ObjInfo; + +typedef struct VPT_Result +{ + int objCount; + VPT_ObjInfo obj[MAX_OBJ_COUNT]; +}VPT_Result; + + #endif diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.cpp index 52e96be..d2f8a26 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.cpp @@ -1,18 +1,17 @@ #include "mvpt_process_assist.h" -int minDistance[EDGESIZE]; -//******** жλǷϷ **********// -// Ŀģ޳ͷʱ󣬵ǼѾ -// 1. 趨ֵԵҪˣֵĿǰ趨Ϊߵ20% -bool LegalPos(bitset flags, int left, int top, int right, int bottom, int imgHeight, int imgWidth) +//******** �ж�λ���Ƿ�Ϸ����� **********// +// Ŀ�ģ��޳�����������ͷʱ�������󣬵��Ǽ�������Ѿ������������ +// 1. �趨��ֵ��������Ե��Ҫ�ˣ���ֵĿǰ�趨Ϊ�������ߵ�20%�� +bool LegalPos(bitset flags, int left, int top, int right, int bottom, int imgHeight, int imgWidth, int minDistance[EDGESIZE]) { int pos[4] = { left, top, right, bottom }; int edges[4] = { 0, 0, imgWidth, imgHeight }; for (int i = 0; i < EDGESIZE; i++) { - if (flags[i]) //Ҫжϵı + if (flags[i]) //����Ҫ�жϵı� { if (abs(pos[i] - edges[i]) < minDistance[i]) return false; @@ -26,13 +25,13 @@ bool LegalMinArea(int width, int height, sy_rect min_box) return (width >= min_box.width_ && height >= min_box.height_); } -//******** жǷϷ **********// -// Ŀģѡȡ֡ -// 1. ֮ǰСIJҪ -// 2. ͻҪ +//******** �ж�����Ƿ�Ϸ����� **********// +// Ŀ�ģ�ѡȡ���������������֡ +// 1. ��֮ǰ���С�IJ�Ҫ +// 2. ͻ��������Ҫ bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bottom) { - //ҪͨMINBOXжϣֱӷtrue + //����Ҫͨ��MINBOX���жϣ�ֱ�ӷ���true int newArea = (bottom - top)*(right - left); @@ -41,14 +40,14 @@ bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bott if (newArea < maxArea) return false; - else if ((newArea - lastArea) / lastArea > 0.5) //ֵ֮ȷǷҪȷֵͬ + else if ((newArea - lastArea) / lastArea > 0.5) //��ֵ����֮����ȷ�������Ƿ���Ҫ��������ȷ����ͬ����ֵ return false; else return true; } -//******** Ŀ˶Ĺ켣жҪرķ **********// -// ĿģΪ֡ĴڣĿ˶Ͽʱһͺǰ˶ͷõԣͺķҪ +//******** ��������������Ŀ���˶��Ĺ켣���ж���Ҫ�ر������ķ��� **********// +// Ŀ�ģ���Ϊ��֡�Ĵ��ڣ�Ŀ���˶��Ͽ�ʱ�������һ�����ͺ�����������ǰ�˶�����ͷ���õ�������������ԣ������ͺ�ķ�����Ҫ�������� void ExpandMargin(int direction_x, int direction_y, int boundary_w, int boundary_h, int &boundary_left, int &boundary_right, int &boundary_top, int &boundary_bottom) { @@ -185,7 +184,7 @@ void CreateResultFolder(char* resultFolder, const char* jointFolder) } } -//DZȽײǶ Ե һ㽨ֵ max_angle 15.0 max_pitch_angle 20.0 +//�����DZȽ����ײ�����Ƕ� ���Ե������� һ�㽨����ֵ max_angle 15.0 max_pitch_angle 20.0 bool validAngle(float roll, float yaw, float pitch, float max_angle, float max_pitch_angle) { 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 } -//DZȽײǶ Ե һ㽨ֵ max_angle 15.0 max_pitch_angle 20.0 +//�����DZȽ����ײ�����Ƕ� ���Ե������� һ�㽨����ֵ max_angle 15.0 max_pitch_angle 20.0 bool betterArea(sy_rect& area1, sy_rect& area2) { return area1.width_*area1.height_ > area2.width_*area2.height_; @@ -214,9 +213,9 @@ bool betterArea(sy_rect& area1, sy_rect& area2) // cv::Mat host_image; // host_image.create(testHeight, testWidth, CV_8UC3); // -// unsigned char *Host_img = new unsigned char[3 * testWidth * testHeight]{};//ڴ +// unsigned char *Host_img = new unsigned char[3 * testWidth * testHeight]{};//�����ڴ� // -// (cudaMemcpy(Host_img, imgdata, testWidth*testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost));//Կͼ +// (cudaMemcpy(Host_img, imgdata, testWidth*testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost));//�����Կ�������ͼ������ // // for (int j = 0; j < host_image.rows; j++) // { diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.h index 22ebbe5..734a364 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt_process_assist.h @@ -1,3 +1,6 @@ +#ifndef __MVPT_PROCESS_ASSIST_H__ +#define __MVPT_PROCESS_ASSIST_H__ + #include #include "opencv2/highgui/highgui.hpp" #include @@ -22,16 +25,17 @@ #define EDGESIZE 4 - using namespace std; //void showGpuMat(unsigned char* imgdata, int height, int width); int CreateDir(char *pszDir); void CreateResultFolder(char* resultFolder, const char* jointFolder); -bool LegalPos(bitset flags, int left, int top, int right, int bottom, int imgHeight, int imgWidth); +bool LegalPos(bitset flags, int left, int top, int right, int bottom, int imgHeight, int imgWidth, int minDistance[EDGESIZE]); bool LegalArea(int maxArea, int lastArea, int left, int top, int right, int bottom); bool LegalMinArea(int width, int height, sy_rect min_box); void ExpandMargin(int direction_x, int direction_y, int boundary_w, int boundary_h, int &boundary_left, int &boundary_right, int &boundary_top, int &boundary_bottom); bool validAngle(float roll, float yaw, float pitch, float max_angle, float max_pitch_angle); -bool betterArea(sy_rect& area1, sy_rect& area2); \ No newline at end of file +bool betterArea(sy_rect& area1, sy_rect& area2); + +#endif // __MVPT_PROCESS_ASSIST_H__ \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehiclePlate.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehiclePlate.cpp index 7fb7639..fcd298c 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehiclePlate.cpp +++ b/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 LOG_ERROR("data null "); return FAILED; } - // cpu_batch_img[i].data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char)); - // 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); - // cpu_batch_img[i].w_ = batch_img[i].w_; - // cpu_batch_img[i].h_ = batch_img[i].h_; - // cpu_batch_img[i].c_ = batch_img[i].c_; + cpu_batch_img[i].data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char)); + 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); + cpu_batch_img[i].w_ = batch_img[i].w_; + cpu_batch_img[i].h_ = batch_img[i].h_; + cpu_batch_img[i].c_ = batch_img[i].c_; } 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 } } - int index_count = vpdr_batch(handle, batch_img, batchsize, all_result); + int index_count = vpdr_batch(handle, cpu_batch_img, batchsize, all_result); cudaDeviceSynchronize(); for (int b = 0; b < batchsize; b++) @@ -85,12 +85,12 @@ int VehiclePlate::process(sy_img * batch_img, int batchsize, vehicle_plate_resul memcpy(&result[b], &all_result[b].vehicle_plate_infos[best_index], sizeof(vehicle_plate_result)); } - // for (int i = 0; i < batchsize; i++) { - // if(cpu_batch_img[i].data_ != nullptr) { - // free(cpu_batch_img[i].data_); - // cpu_batch_img[i].data_ = nullptr; - // } - // } + for (int i = 0; i < batchsize; i++) { + if(cpu_batch_img[i].data_ != nullptr) { + free(cpu_batch_img[i].data_); + cpu_batch_img[i].data_ = nullptr; + } + } if (all_result != NULL) delete [] all_result; 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 de70b32..40b59b5 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 @@ -6,12 +6,16 @@ #include #include "../FFNvDecoder/logger.hpp" +#include "../mvpt_process_assist.h" +#include "../common.h" +#include "../FFNvDecoder/ImageSaveGPU.h" using namespace std; string ObjTypes[9] = { "行人", "自行车", "摩托车", "三轮车", "小型车", "大车", "卡车", "拖拉机", "中巴" }; string ObjTypesEnglish[9] = { "person", "bike", "motor", "tricycle", "car", "bigbus", "lorry", "tractor", "midibus" }; +extern int minDistance[]; #ifdef _MSC_VER char* GbkToUtf8(const char *src_str) @@ -2043,4 +2047,276 @@ int snapshot_helper::SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & } return 0; +} + +CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Task task) { + + //逐个目标更新快照 + int boundary = 10; + int boundaryLittle = 4; + + int cur_real_width = (obj.right - obj.left); + int cur_real_height = (obj.bottom - obj.top); + int cur_real_index = obj.index; + + int frameHeight = task.task_algorithm_data.height; + int frameWidth = task.task_algorithm_data.width; + + int minDistance[EDGESIZE]; + minDistance[0] = minDistance[2] = 35; //left right + minDistance[1] = minDistance[3] = 50; //top bottom + + CropInfo cropInfo; + //第一次添加快照 + if (snapShotInfo.find(newObj) == snapShotInfo.end()) + { + //DxAppendLog(DxLOG_INFO, "30"); + if (LegalMinArea(cur_real_width, cur_real_height, task.task_min_boxsize[cur_real_index])) + { + //DxAppendLog(DxLOG_INFO, "31"); + //--------------------- 保存快照视频截图 -----------------------------// + + int left = max(0, (int)(obj.left - boundaryLittle)); + int top = max(0, (int)(obj.top - boundaryLittle)); + int right = min({ frameWidth - 1, (int)(obj.right + boundaryLittle) }); + int bottom = min({ frameHeight - 1, (int)(obj.bottom + boundaryLittle) }); + snapShotInfo[newObj].frameCount = task.taskFrameCount; + snapShotInfo[newObj].isupdate = true; + snapShotInfo[newObj].lost = 0; + + snapShotInfo[newObj].index.count++; + snapShotInfo[newObj].index.index = obj.index; + + snapShotInfo[newObj].confidence = obj.confidence; + + snapShotInfo[newObj].box.left = left; + snapShotInfo[newObj].box.top = top; + snapShotInfo[newObj].box.right = right; + snapShotInfo[newObj].box.bottom = bottom; + snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); + + snapShotInfo[newObj].flags[0] = left < minDistance[0] + SCALE_OUT ? 0 : 1; //left + snapShotInfo[newObj].flags[1] = top < minDistance[1] + SCALE_OUT ? 0 : 1; //top + snapShotInfo[newObj].flags[2] = right > frameWidth - minDistance[2] - SCALE_OUT ? 0 : 1; //right + snapShotInfo[newObj].flags[3] = bottom > frameHeight - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom + + snapShotInfo[newObj].snapShotLittle.frame = NULL; + snapShotInfo[newObj].snapShot.frame = NULL; + + if (task.folderName != NULL){ + FRAME_KEY frame_id = { newObj.videoID, task.taskFrameCount }; + ImgSaveCache.insert(newObj, frame_id, task.task_algorithm_data); + + snapShotInfo[newObj].snapShot.height = frameHeight; + snapShotInfo[newObj].snapShot.width = frameWidth; + } + + + //--------------------- 保存快照抠图 -----------------------------/ + int vLeft = max(0, obj.left - boundary); + int vTop = max(0, obj.top - boundary); + int vRight = min({ frameWidth - 1, obj.right + boundary }); + int vBottom = min({ frameHeight - 1, obj.bottom + boundary }); + + if (task.folderNameLittle != NULL) + { + int cur_width = 0; + int cur_height = 0; + + if (0 == snapShotInfo[newObj].index.index) + { + cur_width = HP_WIDTH; + cur_height = HP_HEIGHT; + } + else if (1 == snapShotInfo[newObj].index.index || 2 == snapShotInfo[newObj].index.index) + { + cur_width = HCP_WIDTH; + cur_height = HCP_HEIGHT; + } + else if (8 == snapShotInfo[newObj].index.index || (snapShotInfo[newObj].index.index >= 4 && snapShotInfo[newObj].index.index <= 6)) + { + cur_width = VEHICLE_WIDTH; + cur_height = VEHICLE_HEIGHT; + } + else //其余类别 + { + cur_width = vRight - vLeft; + cur_height = vBottom - vTop; + } + + if (cur_width != 0 && cur_height != 0) + { + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, IMG_CHANNELS * cur_width * cur_height * sizeof(unsigned char)); + snapShotInfo[newObj].snapShotLittle.height = cur_height; + snapShotInfo[newObj].snapShotLittle.width = cur_width; + + cropInfo.snapshot_image_data = (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame; + cropInfo.snapshot_left = vLeft; + cropInfo.snapshot_top = vTop; + cropInfo.snapshot_right = vRight; + cropInfo.snapshot_bottom = vBottom; + cropInfo.snapshot_dst_width = cur_width; + cropInfo.snapshot_dst_height = cur_height; + + cropInfo.bCrop = true; + } + } + } + } + else + { + //DxAppendLog(DxLOG_INFO, "36"); + bool updateShotInfo = false; + int oldIndex = snapShotInfo[newObj].index.index; + snapShotInfo[newObj].frameCount = task.taskFrameCount; + snapShotInfo[newObj].isupdate = true; + snapShotInfo[newObj].lost = 0; + + if (snapShotInfo[newObj].index.count == 0) + { + snapShotInfo[newObj].index.count++; + snapShotInfo[newObj].index.index = obj.index; + } + else + { + if (snapShotInfo[newObj].index.index == obj.index) + snapShotInfo[newObj].index.count++; + else + snapShotInfo[newObj].index.count--; + } + if (oldIndex != snapShotInfo[newObj].index.index) + { + updateShotInfo = true; + } + + int left = max(0, (int)(obj.left - boundaryLittle)); + int top = max(0, (int)(obj.top - boundaryLittle)); + int right = min(frameWidth - 1, (int)(obj.right + boundaryLittle)); + int bottom = min(frameHeight - 1, (int)(obj.bottom + boundaryLittle)); + + int maxArea = (snapShotInfo[newObj].box.right - snapShotInfo[newObj].box.left)*(snapShotInfo[newObj].box.bottom - snapShotInfo[newObj].box.top); + + if ((LegalArea(maxArea, snapShotInfo[newObj].lastArea, left, top, right, bottom) + && LegalPos(snapShotInfo[newObj].flags, left, top, right, bottom, frameHeight, frameWidth, minDistance) + && LegalMinArea(cur_real_width, cur_real_height, task.task_min_boxsize[cur_real_index])) || updateShotInfo) + { + //DxAppendLog(DxLOG_INFO, "37"); + int boundary_w = (obj.right - obj.left) * 0.1; + int boundary_h = (obj.bottom - obj.top)* 0.1; + + int boundary_left = boundary_w, boundary_right = boundary_w, boundary_top = boundary_h, boundary_bottom = boundary_h; + + ExpandMargin((left - snapShotInfo[newObj].box.left), + (bottom - snapShotInfo[newObj].box.bottom), + boundary_w, boundary_h, boundary_left, boundary_right, boundary_top, boundary_bottom); + + snapShotInfo[newObj].box.left = left; + snapShotInfo[newObj].box.top = top; + snapShotInfo[newObj].box.right = right; + snapShotInfo[newObj].box.bottom = bottom; + //printf("ori: %d %d %d %d\n", left, top, right - left, bottom - top); + snapShotInfo[newObj].confidence = obj.confidence; + if (task.folderName != NULL) + { + FRAME_KEY frame_id = { newObj.videoID, task.taskFrameCount }; + ImgSaveCache.insert(newObj, frame_id, task.task_algorithm_data); + } + + //--------------------- 保存快照抠图 -----------------------------// + int vLeft = max(0, obj.left - boundary_left); + int vTop = max(0, obj.top - boundary_top); + int vRight = min(frameWidth - 1, obj.right + boundary_right); + int vBottom = min(frameHeight - 1, obj.bottom + boundary_bottom); + if (task.folderNameLittle != NULL) + { + + if (0 == snapShotInfo[newObj].index.index) + { + if (snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) + { + cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char)); + snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH; + snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT; + } + + cropInfo.snapshot_image_data = (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame; + cropInfo.snapshot_left = vLeft; + cropInfo.snapshot_top = vTop; + cropInfo.snapshot_right = vRight; + cropInfo.snapshot_bottom = vBottom; + cropInfo.snapshot_dst_width = HP_WIDTH; + cropInfo.snapshot_dst_height = HP_HEIGHT; + cropInfo.bCrop = true; + } + else if (1 == snapShotInfo[newObj].index.index || 2 == snapShotInfo[newObj].index.index) + { + if (snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) + { + cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char)); + snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH; + snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT; + } + + cropInfo.snapshot_image_data = (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame; + cropInfo.snapshot_left = vLeft; + cropInfo.snapshot_top = vTop; + cropInfo.snapshot_right = vRight; + cropInfo.snapshot_bottom = vBottom; + cropInfo.snapshot_dst_width = HCP_WIDTH; + cropInfo.snapshot_dst_height = HCP_HEIGHT; + cropInfo.bCrop = true; + } + else if (8 == snapShotInfo[newObj].index.index || (snapShotInfo[newObj].index.index >= 4 && snapShotInfo[newObj].index.index <= 6)) + { + //DxAppendLog(DxLOG_INFO, "43.1"); + if (snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT) + { + //DxAppendLog(DxLOG_INFO, "44"); + cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char)); + snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH; + snapShotInfo[newObj].snapShotLittle.height = VEHICLE_HEIGHT; + } + + cropInfo.snapshot_image_data = (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame; + cropInfo.snapshot_left = vLeft; + cropInfo.snapshot_top = vTop; + cropInfo.snapshot_right = vRight; + cropInfo.snapshot_bottom = vBottom; + cropInfo.snapshot_dst_width = VEHICLE_WIDTH; + cropInfo.snapshot_dst_height = VEHICLE_HEIGHT; + cropInfo.bCrop = true; + } + else + { + int cur_width = vRight - vLeft; + int cur_height = vBottom - vTop; + if (cur_width != 0 && cur_height != 0) { + cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char)); + snapShotInfo[newObj].snapShotLittle.height = vBottom - vTop; + snapShotInfo[newObj].snapShotLittle.width = vRight - vLeft; + + //printf("begin partMemCopy: %d %d %d %d %d %d\n", vLeft, vTop, vRight, vBottom, frameWidth, frameHeight); + partMemCopy((unsigned char*)task.task_algorithm_data.frame, frameWidth, frameHeight, + (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom); + } + } + + } + } + snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); + } + + return cropInfo; +} + +int snapshot_helper::getIndexByKey(OBJ_KEY newObj) { + if (snapShotInfo.find(newObj) == snapShotInfo.end()) { + return snapShotInfo[newObj].index.index; + } + + return -1; } \ 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 13c93a2..7268573 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 @@ -118,6 +118,17 @@ struct SNAPSHOT_IMAGE_UNIT { SNAPSHOT_IMAGE_UNIT() {} }; +struct CropInfo { + bool bCrop {false}; + unsigned char* snapshot_image_data {nullptr}; + int snapshot_left; + int snapshot_right; + int snapshot_top; + int snapshot_bottom; + int snapshot_dst_width; + int snapshot_dst_height; +}; + enum { HP_ANALYSIS, HCP_ANALYSIS, @@ -182,6 +193,10 @@ public: void object_attri_analysis(); void snapshot_res_callback(OBJ_KEY obj_key,/* OBJ_VALUE obj_value,*/ void* analysisRes = NULL); + CropInfo cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Task task); + + int getIndexByKey(OBJ_KEY newObj); + 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); 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); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/vf_fea.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/vf_fea.h deleted file mode 100644 index 50e9667..0000000 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/vf_fea.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.cpp index 0de8cbb..cf17e19 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.cpp @@ -1,6 +1,6 @@ #include "Sort.h" #include -#include "../../FFNvDecoder/ImageSaveGPU.h" + #ifdef _MSC_VER #include -- libgit2 0.21.4