From 97243f564f60671326b3d25b6294bd5670b1dfe6 Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Thu, 9 Nov 2023 19:49:55 +0800 Subject: [PATCH] 优化任务管理和数据收集 --- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp | 24 +++++++++++++++++++++++- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h | 6 +++++- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.cpp | 2 +- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h | 2 +- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp | 466 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h | 9 +++------ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h | 18 ++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h | 2 +- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp | 1 - vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp | 53 +++++++++++++++++++++++++---------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h | 6 +++--- vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp | 12 ++++++++---- 13 files changed, 419 insertions(+), 353 deletions(-) diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp index b368aeb..2de5fc5 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp @@ -151,6 +151,13 @@ bool DxDecoderWrap::DxDecoderIsRun() const return false; } +bool DxDecoderWrap::DxDecoderIsFinished() { + if(m_pDec) { + return m_pDec->isFinished(); + } + + return true; +} bool DxDecoderWrap::DxFrameIsEmpty() { @@ -175,6 +182,20 @@ int DxDecoderWrap::DxLockFrame(DxGPUFrame& frame) return 0; } +DxGPUFrame DxDecoderWrap::DxGetFrame() +{ + std::lock_guard l(m_queue_frames_mutex); + + DxGPUFrame frame; + if(m_queue_frames.size() <= 0) { + return frame; + } + frame = m_queue_frames.front(); + m_queue_frames.pop(); + + return frame; +} + void DxDecoderWrap::post_decode_callback(GPUFrame * decodedFrame) { while(!m_bClose) { m_queue_frames_mutex.lock(); @@ -204,6 +225,7 @@ void DxDecoderWrap::post_decode_callback(GPUFrame * decodedFrame) { frame.size = gpuFrame->width; frame.frame = pHwData; frame.timestamp = decodedFrame->ts; + frame.dec_name = m_name; m_queue_frames.push(frame); m_queue_frames_mutex.unlock(); @@ -216,5 +238,5 @@ void DxDecoderWrap::post_decode_callback(GPUFrame * decodedFrame) { } void DxDecoderWrap::decode_finished_callback() { - m_bClose = true; + // m_bClose = true; } \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h index c12c745..b0cadc3 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h @@ -24,11 +24,12 @@ typedef struct DxConfig typedef struct DxGPUFrame { - void * frame; + void * frame {nullptr}; unsigned int size; unsigned int width; unsigned int height; unsigned long long timestamp; + std::string dec_name; }DxGPUFrame; @@ -54,12 +55,15 @@ public: int DxCloseDecoder(); bool DxDecoderIsRun() const; + bool DxDecoderIsFinished(); + int DxGetFrameCount(); int DxGetResolution( int &width, int &height ); bool DxFrameIsEmpty(); int DxLockFrame(DxGPUFrame& frame ); + DxGPUFrame DxGetFrame(); int PauseDecoder(); int ResumeDecoder(); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.cpp index 01a5fe1..f17aa98 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.cpp @@ -38,7 +38,7 @@ void ImageSaveCache::show() } //#include //std::ofstream os1("./mp_frameSize.txt", std::ofstream::out | std::ofstream::trunc); -void ImageSaveCache::add_frame(const OBJ_KEY &snaphot_id, const FRAME_KEY & frame_id, const DxGPUFrame & frame) +void ImageSaveCache::insert_frame(const OBJ_KEY &snaphot_id, const FRAME_KEY & frame_id, const DxGPUFrame & frame) { //std::lock_guard l(tx); //os1 << std::unitbuf; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h index dca2d8d..ae55498 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ImageSaveCache.h @@ -10,7 +10,7 @@ class ImageSaveCache { public: - void add_frame(const OBJ_KEY & snaphot_id, const FRAME_KEY & frame_id, const DxGPUFrame & frame); + void insert_frame(const OBJ_KEY & snaphot_id, const FRAME_KEY & frame_id, const DxGPUFrame & frame); void release(const OBJ_KEY & snaphot_id); DxGPUFrame* get_frame(const OBJ_KEY & snaphot_id); void show(); 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 4ffc82d..3a3222b 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 @@ -226,106 +226,102 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN return ret; } -void CMutliSourceVideoProcess::FinishDecode(const int taskID) +void CMutliSourceVideoProcess::FinishTask(const int taskID) { - for (int i = 0; i < tasks.size(); i++) - { - if (tasks[i].taskID == taskID && tasks[taskID].taskTcuvid != NULL) - { - tasks[taskID].taskState == FINISH; - tasks[taskID].taskTcuvid->DxCloseDecoder(); - delete tasks[taskID].taskTcuvid; - tasks[taskID].taskTcuvid = NULL; - printf("-----------------------finish task: %d-----------------------\n", taskID); - break; - } + if (m_taskMap.find(taskID) == m_taskMap.end()){ + return; } -} + Task& task = m_taskMap[taskID]; -void CMutliSourceVideoProcess::FinishTask(const int taskID) -{ - for (int i = 0; i < tasks.size(); i++) - { - if (tasks[i].taskID == taskID) - { - //printf("first begin finish\n"); - if (tasks[i].taskState == PLAY) TaskinPlay--; - tasks[i].taskState = FINISH; - tasks[i].taskFileSource = nullptr; - tasks[i].taskObjCallbackFunc = nullptr; - tasks[i].taskRealTimeCallbackFunc = nullptr; + if (task.taskState == PLAY) TaskinPlay--; + task.taskState = FINISH; + task.taskFileSource = nullptr; + task.taskObjCallbackFunc = nullptr; + task.taskRealTimeCallbackFunc = nullptr; - m_snaphot_helper.finish_task_ss_analysis(taskID); + m_snaphot_helper.finish_task_ss_analysis(taskID); - if (tasks[i].folderName) - { - delete tasks[i].folderName; - tasks[i].folderName = nullptr; - } + if (task.folderName) { + delete task.folderName; + task.folderName = nullptr; + } - if (tasks[i].folderNameLittle) - { - delete tasks[i].folderNameLittle; - tasks[i].folderNameLittle = nullptr; - } + if (task.folderNameLittle) { + delete task.folderNameLittle; + task.folderNameLittle = nullptr; + } - tasks[i].frameImage.release(); + task.frameImage.release(); - m_vptProcess.FinishTaskTracker(taskID); + m_vptProcess.FinishTaskTracker(taskID); - if (viewTaskID == taskID) viewTaskID = -1; + if (viewTaskID == taskID) { + viewTaskID = -1; + } - LOG_INFO("task {} is finished. timeusing: {}", taskID, get_cur_time_ms() - tasks[i].timestamp); + m_snaphot_helper.waitSaveAnalysisInfo(task.taskID); - break; - } + task.taskTcuvid->DxCloseDecoder(); + delete task.taskTcuvid; + task.taskTcuvid = NULL; + + //回调通知上层任务结束 + if (taskFinishCallbackFunc != nullptr) { + std::lock_guard l(m_snaphot_helper.callback_tx); + taskFinishCallbackFunc(task.taskID); } + + LOG_INFO("task {} is finished. timeusing: {}", taskID, get_cur_time_ms() - task.timestamp); + } void CMutliSourceVideoProcess::PauseTask(const int taskID) { - for (int i = 0; i < tasks.size(); i++) - { - if (tasks[i].taskID == taskID) - { - if (tasks[i].taskState == PLAY) TaskinPlay--; - tasks[i].taskState = PAUSE; - m_vptProcess.PauseTaskTracker(taskID); - tasks[i].taskTcuvid->PauseDecoder(); - if (viewTaskID == taskID) viewTaskID = -1; - printf("-----------------------pasue task: %d-----------------------\n", taskID); - break; - } + if (m_taskMap.find(taskID) == m_taskMap.end()){ + return; } + + Task& task = m_taskMap[taskID]; + + if (task.taskState == PLAY) TaskinPlay--; + task.taskState = PAUSE; + m_vptProcess.PauseTaskTracker(taskID); + task.taskTcuvid->PauseDecoder(); + if (viewTaskID == taskID) viewTaskID = -1; + printf("-----------------------pasue task: %d-----------------------\n", taskID); } void CMutliSourceVideoProcess::RestartTask(const int taskID) { - for (int i = 0; i < tasks.size(); i++) - { - if (tasks[i].taskID == taskID) - { - tasks[i].taskState = PLAY; - TaskinPlay++; - m_vptProcess.RestartTaskTraker(taskID); - tasks[i].taskTcuvid->ResumeDecoder(); - printf("-----------------------restart task: %d-----------------------\n", taskID); - break; - } + if (m_taskMap.find(taskID) == m_taskMap.end()){ + return; } + + Task& task = m_taskMap[taskID]; + + task.taskState = PLAY; + TaskinPlay++; + m_vptProcess.RestartTaskTraker(taskID); + task.taskTcuvid->ResumeDecoder(); + printf("-----------------------restart task: %d-----------------------\n", taskID); } //ʵʱ�鿴�ӿ� �ɿ���һ·��ʵʱ�鿴������·�ķ������OSD��Ȼ�󽫻���ͨ���ص��������ظ��û� void CMutliSourceVideoProcess::ViewTask(const int taskID) { - if (tasks.size() > taskID && tasks[taskID].taskState == PLAY) - { + if (m_taskMap.find(taskID) == m_taskMap.end()){ + printf("Only can view playing task!"); + return; + } + + Task& task = m_taskMap[taskID]; + if (task.taskState == PLAY) { viewTaskID = taskID; printf("-----------------------view task: %d-----------------------\n", taskID); - } - else + } else { printf("Only can view playing task!"); + } } //����ʵʱ�鿴�ӿڣ��ر�ʵʱ����ķ��� @@ -465,9 +461,10 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh new_task_info.obj_callback = new_task.taskObjCallbackFunc; m_snaphot_helper.add_task_info(new_task.taskID, new_task_info); + m_taskMap[new_task.taskID] = new_task; + TotalTask++; TaskinPlay++; - tasks.push_back(new_task); m_vptProcess.AddTaskTracker(new_task.taskID, width, height); @@ -528,17 +525,14 @@ int CMutliSourceVideoProcess::AddOperator(task_param tparam) int CMutliSourceVideoProcess::get_task_progress(int taskid, double &progress) { - int ret = 0; - for (auto &item : tasks) - { - if (item.taskID == taskid) - { - progress = (double)item.taskFrameCount / (double)item.taskTotalFrameCount; - return 0; - } + int ret = -1; + if (m_taskMap.find(taskid) == m_taskMap.end()){ + return ret; } - return -1; + Task& task = m_taskMap[taskid]; + progress = (double)task.taskFrameCount / (double)task.taskTotalFrameCount; + return 0; } void CMutliSourceVideoProcess::AddOperator(int taskID, int taskOper) @@ -585,7 +579,14 @@ void CMutliSourceVideoProcess::OperatorTask() RestartTask(newOperator.changeTaskID); break; case FINISHTASK: - FinishTask(newOperator.changeTaskID); + { + FinishTask(newOperator.changeTaskID); + auto iter = m_taskMap.find(newOperator.changeTaskID); + if (iter != m_taskMap.end()) { + m_taskMap.erase(iter); + } + + } break; default: break; @@ -595,9 +596,9 @@ void CMutliSourceVideoProcess::OperatorTask() } //#define LOG_INFO -void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_ObjInfo *obj, int taskFrameCount, int taskId) +void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(const VPT_Result& vptResult, int taskFrameCount, int taskId) { - if (objCount == 0) + if (vptResult.objCount == 0) { video_object_info newObjInfo; newObjInfo.task_id = taskId; @@ -615,8 +616,9 @@ void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_Obj } else { - for (int c = 0; c < objCount; c++) + for (int c = 0; c < vptResult.objCount; c++) { + const VPT_ObjInfo* obj = vptResult.obj; OBJ_KEY newObj = { taskId, obj[c].id }; video_object_info newObjInfo; newObjInfo.task_id = taskId; @@ -645,7 +647,6 @@ void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_Obj } void CMutliSourceVideoProcess::algorthim_process() { - set k; int count = 0; DxGPUFrame frame = {}; @@ -658,10 +659,9 @@ void CMutliSourceVideoProcess::algorthim_process() int process_times = 0; long long last_time = get_cur_time_ms(); - while (!m_bProcessExit) - { - if (licence_status <= -3) - { + while (!m_bProcessExit) { + + if (licence_status <= -3) { printf("authority failed!\n"); break; } @@ -674,106 +674,31 @@ void CMutliSourceVideoProcess::algorthim_process() taskCondVar.notify_all(); - int curTaskSize = tasks.size(); - - count = 0; - static int ncount = 0; - map> finishTaskDeleteObj; - int curPlayTaskCount = 0; - - for (int i = 0; i < curTaskSize; i++) - { - if ((tasks[i].taskState == PLAY || tasks[i].taskState == DECODEERROR)) - { - if (!tasks[i].taskTcuvid->DxDecoderIsRun()) - { - cudaError_t cudaStatus = cudaGetLastError(); - if (cudaStatus != cudaSuccess) { - printf("begin finish last error: %s\n", cudaGetErrorString(cudaStatus)); - } - - tasks[i].taskState = FINISH; - - FinishTask(tasks[i].taskID); - - tasks[i].taskTcuvid->DxCloseDecoder(); - delete tasks[i].taskTcuvid; - tasks[i].taskTcuvid = NULL; - m_snaphot_helper.waitSaveAnalysisInfo(tasks[i].taskID); - - //回调通知上层任务结束 - if (taskFinishCallbackFunc != nullptr) - { - std::lock_guard l(m_snaphot_helper.callback_tx); - taskFinishCallbackFunc(tasks[i].taskID); - } - - TaskinPlay--; - } - } - - if (tasks[i].taskState == FINISH) - count++; - } - - //�������������FINISH״̬ - if (count >= tasks.size()) //have no decode video, break - { - { - std::lock_guard l(taskMutex); - //�ж���������ȴ������Ƿ����µ��������� - if (HasNewTask()) - { - continue; - } - else - { - continue; - } + for (auto it=m_taskMap.begin(); it!=m_taskMap.end(); ) { + Task& task = it->second; + if (!task.taskTcuvid->DxDecoderIsRun() && task.taskTcuvid->DxFrameIsEmpty()) { + FinishTask(task.taskID); + it = m_taskMap.erase(it); + } else { + ++it; } } - - //��ǰû��PLAY������ ѭ���ȴ� - curPlayTaskCount = TaskinPlay; - if (curPlayTaskCount <= 0) { - Sleep(30); - continue; - } - k.clear(); - TaskinPlayID.clear(); - - //��ȡ�������� - getdata_flag: - for (int i = 0; i < curTaskSize; i++) - { - if (k.find(i) == k.end() && tasks[i].taskState == PLAY && tasks[i].taskTcuvid->DxDecoderIsRun()) - { - if(tasks[i].taskTcuvid->DxLockFrame(tasks[i].task_algorithm_data) == 0) { - k.insert(i); - TaskinPlayID.insert(tasks[i].taskID); - } - } - else if (k.find(i) == k.end() && tasks[i].taskState == PLAY && !tasks[i].taskTcuvid->DxDecoderIsRun()) - { - tasks[i].taskState = DECODEERROR; - curPlayTaskCount--; - m_vptProcess.FinishTaskTracker(tasks[i].taskID); + vector vec_dxGpuFrame; + for (auto it=m_taskMap.begin(); it!=m_taskMap.end(); ++it) { + Task& task = it->second; + DxGPUFrame dxFrame = task.taskTcuvid->DxGetFrame(); + if(nullptr == dxFrame.frame) { + continue; } - } - - if (curPlayTaskCount <= 0) { - Sleep(30); - continue; + vec_dxGpuFrame.push_back(dxFrame); } - //��û�л�ȡ������·���Ľ������� ѭ���ȴ� - if (k.size() < curPlayTaskCount) - { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - goto getdata_flag; + if (vec_dxGpuFrame.size() <= 0) { + continue; } + #ifdef LOG_INFO2 long long gather_data_time = get_cur_time_ms(); @@ -781,49 +706,23 @@ void CMutliSourceVideoProcess::algorthim_process() #endif cudaDeviceSynchronize(); - - int cur_batch_size = 0; - cur_batch_size = section_batch_size; - - if (0) - { - if (section_batch_size == 20) - cur_batch_size = section_batch_size; - else - { - if (curPlayTaskCount <= 2 * section_batch_size) - cur_batch_size = section_batch_size; - else if (curPlayTaskCount >= 2 * MAX_BATCH) - cur_batch_size = MAX_BATCH; - else - cur_batch_size = curPlayTaskCount / 2 + (curPlayTaskCount % 2); - } - } long long start_time_vpt = get_cur_time_ms(); - set::iterator iter = TaskinPlayID.begin(); - - int task_in_play_size = TaskinPlayID.size(); - vector> deleteObjectID(task_in_play_size); - vector batch_img(task_in_play_size); - vector> unUsedResult(task_in_play_size); - vector VPTResult(task_in_play_size); - vector vec_frameIndex; - - for (size_t i = 0; i < TaskinPlayID.size(); i++) { - DxGPUFrame task_algorithm_data = tasks[*iter].task_algorithm_data; + vector vec_data; + for (auto task_algorithm_data: vec_dxGpuFrame) { int w = task_algorithm_data.width; int h = task_algorithm_data.height; - int npitch = task_algorithm_data.size; - - batch_img[i].set_data(w, h, 3, (unsigned char *)task_algorithm_data.frame); - vec_frameIndex.push_back(task_algorithm_data.timestamp); - iter++; + DataInfo data_info; + data_info.img.set_data(w, h, 3, (unsigned char *)task_algorithm_data.frame); + data_info.task_id = atoi(task_algorithm_data.dec_name.c_str()); + data_info.frameIndex = task_algorithm_data.timestamp; + + vec_data.push_back(data_info); } - - int flag = m_vptProcess.process(batch_img.data(), batch_img.size(), vec_frameIndex, VPTResult, deleteObjectID, unUsedResult); + + vector vec_vptResult = m_vptProcess.process(vec_data); #ifdef LOG_INFO2 std::cout << "VPT_Process_GPU time_using: " << get_cur_time_ms() - start_time_vpt << std::endl; @@ -831,50 +730,49 @@ void CMutliSourceVideoProcess::algorthim_process() long long result_analysis_time = get_cur_time_ms(); - iter = TaskinPlayID.begin(); - for (int i = 0; i < curPlayTaskCount; i++) + for (int i = 0; i < vec_vptResult.size(); i++) { - Task task = tasks[*iter]; - task.taskFrameCount = task.task_algorithm_data.timestamp; - //若该路任务当前帧未检测到目标,返回ID为-1的目标表明未检测到目标 - if (VPTResult[i].objCount == 0) - { - callTaskObjInfoCallbackFunc(0, nullptr, task.taskFrameCount, *iter); - } + int task_id = vec_vptResult[i].task_id; + Task& task = m_taskMap[task_id]; + + DxGPUFrame& task_algorithm_data = vec_dxGpuFrame[i]; + + task.taskFrameCount = task_algorithm_data.timestamp; //实时查看模块,若存在实时查看,把当前视频画面cp回内存 bool view = false; - int frameHeight = task.task_algorithm_data.height; - int frameWidth = task.task_algorithm_data.width; + int frameHeight = task_algorithm_data.height; + int frameWidth = task_algorithm_data.width; - if (*iter == viewTaskID) - { - cudaMemcpy(task.frameImage.data, task.task_algorithm_data.frame, 3 * frameWidth * frameHeight * sizeof(unsigned char), cudaMemcpyDeviceToHost); + if (task_id == viewTaskID) { + cudaMemcpy(task.frameImage.data, task_algorithm_data.frame, 3 * frameWidth * frameHeight * sizeof(unsigned char), cudaMemcpyDeviceToHost); view = true; } //跟踪帧也需要返回跟踪的结果 - if (task.taskLastFrameCount > 0) - { - vector OneUnUsedResult = unUsedResult[i]; - if (OneUnUsedResult.size() == 0) - { - callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + 1, *iter); + if (task.taskLastFrameCount > 0) { + + VPT_Result default_vptResult; + default_vptResult.objCount = 0; + + vector OneUnUsedResult = vec_vptResult[i].vecUnUsedResult; + if (OneUnUsedResult.size() == 0) { + callTaskObjInfoCallbackFunc(default_vptResult, task.taskLastFrameCount + 1, task_id); } - for (int k = 0; k < OneUnUsedResult.size(); ++k) - { - if (OneUnUsedResult[k].objCount == 0) - { - callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + k + 1, *iter); - } - else - { - //cout << "OneUnUsedResult.size = " << OneUnUsedResult.size() << " k=" << k << " OneUnUsedResult[k].objCount = " << OneUnUsedResult[k].objCount << endl; - callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, task.taskLastFrameCount + k + 1, *iter); + + for (int k = 0; k < OneUnUsedResult.size(); ++k) { + if (OneUnUsedResult[k].objCount == 0) { + callTaskObjInfoCallbackFunc(default_vptResult, task.taskLastFrameCount + k + 1, task_id); + } else { + callTaskObjInfoCallbackFunc(OneUnUsedResult[k], task.taskLastFrameCount + k + 1, task_id); } } } - task.taskLastFrameCount = task.taskFrameCount; + + VPT_Result vptResult = vec_vptResult[i].vptResult; + callTaskObjInfoCallbackFunc(vptResult, task_algorithm_data.timestamp, task_id); + + task.taskLastFrameCount = task_algorithm_data.timestamp; unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{}; int snapshot_left[MAX_OBJ_COUNT]{}; @@ -888,13 +786,11 @@ void CMutliSourceVideoProcess::algorthim_process() vector human_idx; //用于记录快照数组中那些是人脸 vector human_obj_keys; - callTaskObjInfoCallbackFunc(VPTResult[i].objCount, VPTResult[i].obj, task.taskFrameCount, *iter); - - for (int c = 0; c < VPTResult[i].objCount; c++) + for (int c = 0; c < vptResult.objCount; c++) { - VPT_ObjInfo obj = VPTResult[i].obj[c]; + VPT_ObjInfo obj = vptResult.obj[c]; - OBJ_KEY newObj = { (*iter), obj.id }; + OBJ_KEY newObj = { task_id, obj.id }; //实时查看模块 绘制目标框到画面上 if (view) @@ -908,9 +804,7 @@ void CMutliSourceVideoProcess::algorthim_process() int p1 = obj.left - 10 > 0 ? obj.left - 10 : 0; int p2 = obj.top - 15 > 0 ? obj.top - 15 : 0; - cv::rectangle(task.frameImage, Rect(obj.left, obj.top, - obj.right - obj.left, - obj.bottom - obj.top), Scalar(158, 52, 254), 3, 1, 0); + cv::rectangle(task.frameImage, Rect(obj.left, obj.top, obj.right - obj.left, obj.bottom - obj.top), Scalar(158, 52, 254), 3, 1, 0); #ifdef _MSC_VER string resss = "" + to_string(index) + " " + ObjTypes[index]; putTextZH(task.frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); @@ -920,7 +814,17 @@ void CMutliSourceVideoProcess::algorthim_process() #endif } - CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, obj, task); + bool bCacheSrc = false; + if (task.folderName != NULL){ + bCacheSrc = true; + } + + bool bCacheLittle = false; + if (task.folderNameLittle != NULL) { + bCacheLittle = true; + } + + CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, obj, task.task_min_boxsize, bCacheSrc, bCacheLittle, task_algorithm_data); if(crop_info.bCrop){ snapshot_image_data[copy_obj_count] = crop_info.snapshot_image_data; snapshot_left[copy_obj_count] = crop_info.snapshot_left; @@ -943,7 +847,7 @@ void CMutliSourceVideoProcess::algorthim_process() //若待抠图的快照数不为0 则进行批量抠图 if (0 != copy_obj_count) { - PartMemResizeBatch((unsigned char*)task.task_algorithm_data.frame, frameWidth, frameHeight, + PartMemResizeBatch((unsigned char*)task_algorithm_data.frame, frameWidth, frameHeight, snapshot_image_data, copy_obj_count, snapshot_left, snapshot_top, snapshot_right, snapshot_bottom, snapshot_dst_width, snapshot_dst_height, 0, 0, 0, 1, 1, 1); //最新刚添加的人脸检测模块,针对存在的行人快照进行人脸检测+人脸快照框的优选 @@ -961,21 +865,27 @@ void CMutliSourceVideoProcess::algorthim_process() ori_points[idx].y_ = (snapshot_bottom[ii] - snapshot_top[ii]); } - m_snaphot_helper.cacheFaceSnapshotInfo(human_img, human_count, ori_points, human_idx, human_obj_keys, snapshot_left, snapshot_top, task); + m_snaphot_helper.cacheFaceSnapshotInfo(human_img, human_count, ori_points, human_idx, human_obj_keys, snapshot_left, snapshot_top, task_algorithm_data); } } //实时查看 绘制目标轨迹 回调函数返回 - if (view) - { - m_vptProcess.DrawTracker(*iter, &task.frameImage); + if (view) { + m_vptProcess.DrawTracker(task_id, &task.frameImage); if (task.taskRealTimeCallbackFunc != nullptr) task.taskRealTimeCallbackFunc(task.frameImage.data, task.frameImage.rows, task.frameImage.cols); } - // tasks[*iter].taskFrameCount += skip_frame_; - iter++; } + { + cudaError_t cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) { + LOG_ERROR("result last error: {}", cudaGetErrorString(cudaStatus)); + } + } + + + #ifdef LOG_INFO2 long long result_analysis_time2 = get_cur_time_ms(); cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; @@ -983,21 +893,28 @@ void CMutliSourceVideoProcess::algorthim_process() long long second_analysis_time = get_cur_time_ms(); - auto task_iter = TaskinPlayID.begin(); - for (int i = 0; i < curPlayTaskCount; i++) + for (int i = 0; i < vec_vptResult.size(); i++) { - for (int j = 0; j < deleteObjectID[i].size(); j++) + vector& vecDeleteObj = vec_vptResult[i].vecDeleteObj; + for (int j = 0; j < vecDeleteObj.size(); j++) { - OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; + OBJ_KEY deleteObj = { vec_vptResult[i].task_id, vecDeleteObj[j] }; m_snaphot_helper.SaveResultInFile(deleteObj); } + } + - task_iter++; + for (auto task_algorithm_data: vec_dxGpuFrame) { + cudaFree(task_algorithm_data.frame); + task_algorithm_data.frame = nullptr; } - for (auto task_id: TaskinPlayID) { - cudaFree(tasks[task_id].task_algorithm_data.frame); - tasks[task_id].task_algorithm_data.frame = nullptr; + + { + cudaError_t cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) { + LOG_ERROR("cudaFree last error: {}", cudaGetErrorString(cudaStatus)); + } } m_snaphot_helper.object_attri_analysis(); @@ -1012,7 +929,6 @@ void CMutliSourceVideoProcess::algorthim_process() #endif ++total_count; - ++ncount; #ifdef LOG_INFO2 last_time = get_cur_time_ms(); @@ -1029,12 +945,12 @@ void CMutliSourceVideoProcess::algorthim_process() int CMutliSourceVideoProcess::GetRuningNb() { int no = 0; - for(int i=0; i < tasks.size(); i++){ - if(tasks[i].taskState == PLAY){ + for (auto it=m_taskMap.begin(); it!=m_taskMap.end(); ++it) { + Task& task = it->second; + if(task.taskState == PLAY){ no ++; } } - return no; } 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 72d2d40..1b753db 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 @@ -13,6 +13,7 @@ #include "VPTProcess.h" #include #include +#include #include "common.h" #include "../FFNvDecoder/ImageSaveGPU.h" @@ -112,12 +113,9 @@ public: int get_task_progress(int taskid, double & progress); void OperatorTask(); - bool HasNewTask() { - return !TaskOperatorQ.empty(); - } void AddOperator(int taskID, int taskOper); int AddOperator(task_param tparam); - void callTaskObjInfoCallbackFunc(int objCount, VPT_ObjInfo *obj, int taskFrameCount, int taskId); + void callTaskObjInfoCallbackFunc(const VPT_Result& vptResult, int taskFrameCount, int taskId); bool AddTask(task_param tparam); void PauseTask(const int taskID); void RestartTask(const int taskID); @@ -125,7 +123,6 @@ public: void ViewTask(const int taskID); void FinishViewTask(); int FinishProcessThread(); - void FinishDecode(const int taskID); int GetRuningNb(); @@ -137,7 +134,7 @@ public: int thrd_status; int mgpuid; int skip_frame_ {5}; // 控制跳帧参数 - vector tasks; + map m_taskMap; int AddTaskSucFlag; //0:��ʼ��״̬ 1����������ɹ� -1����������ʧ�� int TaskinPlay; int TotalTask; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp index 2fe4800..232e390 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp @@ -25,6 +25,13 @@ // #include "../../model/vptModeTrt/ga_trt_fpn_vpt_calibrator.h" +struct DetectResultInfo { + vector< vector > det_result; + int task_id; + unsigned long long ts; +}; + + static long long get_cur_time_ms(){ chrono::time_point tpMicro @@ -193,6 +200,116 @@ void VPTProcess::check_VPT_Result(VPT_Result & vResult) { vResult.objCount = index; } +vector VPTProcess::process(vector vec_data) { + + vector vec_result; + + if(nullptr == det_handle){ + return vec_result; + } + + long long t1 = get_cur_time_ms(); + + int batchsize = vec_data.size(); + + vector vec_detectResult; + + int cycle_time = batchsize / m_max_batch_size; + cycle_time = (batchsize % m_max_batch_size) == 0 ? cycle_time : (cycle_time + 1) ; + + for (int i = 0; i < cycle_time; i++) { + int start_index = i * m_max_batch_size; + int end_index = start_index + m_max_batch_size; + if(end_index >= batchsize) { + end_index = batchsize; + } + + vector vec_img; + vector vec_task_id; + vector vec_ts; + for (int j = start_index; j < end_index; j++) { + vec_img.push_back(vec_data[j].img); + vec_task_id.push_back(vec_data[j].task_id); + vec_ts.push_back(vec_data[j].frameIndex); + } + + ctools_result *detresult; + int res_status = ctools_process(det_handle, vec_img.data(), vec_img.size(), &detresult); + + for (size_t b = 0; b < vec_img.size(); b++) { + ctools_result &cur_result = detresult[b]; + + DetectResultInfo result_info; + result_info.task_id = vec_task_id[b]; + result_info.ts = vec_ts[b]; + for (int c = 0; c < cur_result.obj_count_ && c < MAX_OBJ_COUNT; c++) + { + float x1 = cur_result.obj_results_[c].data_[2]; + float y1 = cur_result.obj_results_[c].data_[3]; + float x2 = cur_result.obj_results_[c].data_[4]; + float y2 = cur_result.obj_results_[c].data_[5]; + + float class_id = cur_result.obj_results_[c].data_[0]; + float score = cur_result.obj_results_[c].data_[1]; + + if (score >= THRESHOLD) + { + vector obj; + + obj.push_back(x1); + obj.push_back(y1); + obj.push_back(x2); + obj.push_back(y2); + obj.push_back(score); + obj.push_back(class_id); + // detectResult[real_index].push_back(obj); + result_info.det_result.push_back(obj); + } + } + + vec_detectResult.push_back(result_info); + } + } + + for (int i = 0; i < vec_detectResult.size(); i++) { + DetectResultInfo& det_result_info = vec_detectResult[i]; + TaskTracker& task_tracker = m_taskTrackerMap[det_result_info.task_id]; + + // TaskTracker& task_tracker = tools->taskTrackers[i]; + if (!task_tracker.tracker.GetState()) { + continue; + } + + VPTProcessResult oneResult; + oneResult.task_id = det_result_info.task_id; + if (task_tracker.lastFrameIndex > 0) { + // 非第一帧 + int update_times = det_result_info.ts - task_tracker.lastFrameIndex - 1; + if (update_times < 0) { + cout << "FrameIndex error !! lastFrameIndex= " << task_tracker.lastFrameIndex << " cur_frameindex = " << det_result_info.ts << endl; + } + + for (int j = 0; j < update_times; j++) { // 无检测框跟踪 + VPT_Result unresult; + unresult.objCount = task_tracker.tracker.update(task_tracker.ratioWidth, task_tracker.ratioHeight, false, task_tracker.lastDetectResult, unresult.obj, task_tracker.lastDeleteObjectID); + check_VPT_Result(unresult); + oneResult.vecUnUsedResult.push_back(unresult); + } + } + oneResult.vptResult.objCount = task_tracker.tracker.update(task_tracker.ratioWidth, task_tracker.ratioHeight, true, det_result_info.det_result, oneResult.vptResult.obj, oneResult.vecDeleteObj); + + check_VPT_Result(oneResult.vptResult); + + task_tracker.lastDetectResult = det_result_info.det_result; + task_tracker.lastDeleteObjectID = oneResult.vecDeleteObj; + task_tracker.lastFrameIndex = det_result_info.ts; + + oneResult.ts = det_result_info.ts; + + vec_result.push_back(oneResult); + } +} + int VPTProcess::process(sy_img * batch_img, int batchsize, vector vec_frameIndex, vector& result, vector>& deleteObjectID, vector>& unUsedResult) { if(nullptr == det_handle){ @@ -252,7 +369,7 @@ int VPTProcess::process(sy_img * batch_img, int batchsize, vectortaskTrackers[i]; + TaskTracker& task_tracker = m_taskTrackerMap[i]; if (!task_tracker.tracker.GetState()) { continue; } @@ -289,7 +406,7 @@ void VPTProcess::release() { det_handle = NULL; } - vector().swap(taskTrackers); + m_taskTrackerMap.clear(); } void VPTProcess::AddTaskTracker(const int taskID, const double rWidth, const double rHeight) @@ -300,53 +417,45 @@ void VPTProcess::AddTaskTracker(const int taskID, const double rWidth, const dou t.ratioHeight = rHeight; t.lastFrameIndex = 0; t.tracker.setYOLOv5(true); // YOLOv5 要设为true, fpn 要设为false - taskTrackers.push_back(t); + + m_taskTrackerMap[taskID] = t; } void VPTProcess::FinishTaskTracker(const int taskID) { - for (int i = 0; i < taskTrackers.size(); i++) - { - if (taskTrackers[i].TaskID == taskID) - { - taskTrackers.erase(taskTrackers.begin() + i); - break; - } + if (m_taskTrackerMap.find(taskID) == m_taskTrackerMap.end()) { + return; } + + m_taskTrackerMap.erase(taskID); } void VPTProcess::PauseTaskTracker(const int taskID) { - for (int i = 0; i < taskTrackers.size(); i++) - { - if (taskTrackers[i].TaskID == taskID) - { - taskTrackers[i].tracker.Pause(); - break; - } + if (m_taskTrackerMap.find(taskID) == m_taskTrackerMap.end()) { + return; } + + TaskTracker& t = m_taskTrackerMap[taskID]; + t.tracker.Pause(); } void VPTProcess::RestartTaskTraker(const int taskID) { - for (int i = 0; i < taskTrackers.size(); i++) - { - if (taskTrackers[i].TaskID == taskID) - { - taskTrackers[i].tracker.ReSet(); - break; - } + if (m_taskTrackerMap.find(taskID) == m_taskTrackerMap.end()) { + return; } + + TaskTracker& t = m_taskTrackerMap[taskID]; + t.tracker.ReSet(); } void VPTProcess::DrawTracker(const int taskID, cv::Mat *img) { - for (int i = 0; i < taskTrackers.size(); i++) - { - if (taskTrackers[i].TaskID == taskID) - { - taskTrackers[i].tracker.addTracker(img); - break; - } + if (m_taskTrackerMap.find(taskID) == m_taskTrackerMap.end()) { + return; } + + TaskTracker& t = m_taskTrackerMap[taskID]; + t.tracker.addTracker(img); } \ 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 fb74e3b..3e464aa 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,6 +9,7 @@ #include #include "utools.h" #include +#include #include "common.h" #include "./sort/Sort.h" //tracker @@ -28,6 +29,20 @@ struct TaskTracker vector lastDeleteObjectID; }; +struct DataInfo { + int task_id {-1}; + sy_img img; + unsigned long long frameIndex; +}; + +struct VPTProcessResult { + int task_id {-1}; + VPT_Result vptResult; + vector vecDeleteObj; + vector vecUnUsedResult; + unsigned long long ts; +}; + class VPTProcess { @@ -59,6 +74,8 @@ public: *************************************************************************/ int process(sy_img * batch_img, int batchsize, vector vec_frameIndex, vector& result, vector>& deleteObjectID, vector>& unUsedResult); + vector process(vector vec_data); + /************************************************************************* * PURPOSE: 资源释放 * PARAM: @@ -86,4 +103,5 @@ private: void* det_handle {nullptr}; vector taskTrackers; + map m_taskTrackerMap; }; 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 473d1d2..26d6163 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 @@ -112,7 +112,7 @@ typedef struct VPT_ObjInfo //����ṹ�� typedef struct VPT_Result { - int objCount; + int objCount {0}; VPT_ObjInfo obj[MAX_OBJ_COUNT]; }VPT_Result; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp index 8732948..e60cb65 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/mvpt.cpp @@ -47,7 +47,6 @@ void finish_task(void *handle, int task_id) CMutliSourceVideoProcess* tools = (CMutliSourceVideoProcess*)handle; std::unique_lock l(tools->taskMutex); tools->AddOperator(task_id, 3); - tools->FinishDecode(task_id); } 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 657e9fd..eaed8d4 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 @@ -2038,7 +2038,7 @@ int snapshot_helper::SaveResultInFile(OBJ_KEY deleteObj) return 0; } -CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Task task) { +CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, sy_rect task_min_boxsize[DETECTTYPE], bool bCacheSrc, bool bCacheLittle, DxGPUFrame& dxGpuFrame) { //逐个目标更新快照 int boundary = 10; @@ -2048,8 +2048,8 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas 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 frameHeight = dxGpuFrame.height; + int frameWidth = dxGpuFrame.width; int minDistance[EDGESIZE]; minDistance[0] = minDistance[2] = 35; //left right @@ -2060,7 +2060,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas 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])) + if (LegalMinArea(cur_real_width, cur_real_height, task_min_boxsize[cur_real_index])) { //DxAppendLog(DxLOG_INFO, "31"); //--------------------- 保存快照视频截图 -----------------------------// @@ -2069,7 +2069,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas 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].frameCount = dxGpuFrame.timestamp; snapShotInfo[newObj].isupdate = true; snapShotInfo[newObj].lost = 0; @@ -2092,9 +2092,9 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas snapShotInfo[newObj].snapShotLittle.frame = NULL; snapShotInfo[newObj].snapShot.frame = NULL; - if (task.folderName != NULL){ - FRAME_KEY frame_id = { newObj.videoID, task.taskFrameCount }; - ImgSaveCache.add_frame(newObj, frame_id, task.task_algorithm_data); + if (bCacheSrc) { + FRAME_KEY frame_id = { newObj.videoID, dxGpuFrame.timestamp }; + ImgSaveCache.insert_frame(newObj, frame_id, dxGpuFrame); snapShotInfo[newObj].snapShot.height = frameHeight; snapShotInfo[newObj].snapShot.width = frameWidth; @@ -2107,8 +2107,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas int vRight = min({ frameWidth - 1, obj.right + boundary }); int vBottom = min({ frameHeight - 1, obj.bottom + boundary }); - if (task.folderNameLittle != NULL) - { + if (bCacheLittle) { int cur_width = 0; int cur_height = 0; @@ -2162,7 +2161,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas //DxAppendLog(DxLOG_INFO, "36"); bool updateShotInfo = false; int oldIndex = snapShotInfo[newObj].index.index; - snapShotInfo[newObj].frameCount = task.taskFrameCount; + snapShotInfo[newObj].frameCount = dxGpuFrame.timestamp; snapShotInfo[newObj].isupdate = true; snapShotInfo[newObj].lost = 0; @@ -2192,7 +2191,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas 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) + && LegalMinArea(cur_real_width, cur_real_height, task_min_boxsize[cur_real_index])) || updateShotInfo) { //DxAppendLog(DxLOG_INFO, "37"); int boundary_w = (obj.right - obj.left) * 0.1; @@ -2209,10 +2208,9 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas 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.add_frame(newObj, frame_id, task.task_algorithm_data); + if (bCacheSrc) { + FRAME_KEY frame_id = { newObj.videoID, dxGpuFrame.timestamp }; + ImgSaveCache.insert_frame(newObj, frame_id, dxGpuFrame); } //--------------------- 保存快照抠图 -----------------------------// @@ -2220,8 +2218,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas 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 (bCacheLittle) { if (0 == snapShotInfo[newObj].index.index) { if (snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) @@ -2247,7 +2244,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas // { // LOG_DEBUG("else , task_id:{} obj_id:{} index = {}", newObj.videoID, newObj.objID, snapShotInfo[newObj].index.index); // } - // if (snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) + 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)); @@ -2296,7 +2293,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas 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, + partMemCopy((unsigned char*)dxGpuFrame.frame, frameWidth, frameHeight, (unsigned char*)snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom); } } @@ -2317,7 +2314,7 @@ int snapshot_helper::getIndexByKey(OBJ_KEY newObj) { return -1; } -void snapshot_helper::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) { +void snapshot_helper::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[], DxGPUFrame& dxGpuFrame) { fd_result *face_det_result = new fd_result[human_count]; for (int fd_i = 0; fd_i < human_count; fd_i++) { @@ -2364,8 +2361,8 @@ void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count, int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); - int new_right = min((int)task.task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); - int new_bottom = min((int)task.task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); + int new_right = min((int)dxGpuFrame.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); + int new_bottom = min((int)dxGpuFrame.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); int new_width = new_right - new_left; int new_height = new_bottom - new_top; @@ -2398,7 +2395,7 @@ void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count, { (face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_ }; - cudacommon::CropImgGpu((unsigned char*)task.task_algorithm_data.frame, task.task_algorithm_data.width, task.task_algorithm_data.height, + cudacommon::CropImgGpu((unsigned char*)dxGpuFrame.frame, dxGpuFrame.width, dxGpuFrame.height, (unsigned char*)snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); } else @@ -2413,8 +2410,8 @@ void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count, { int new_left = max(0, face_ori_rect.left_ - face_ori_rect.width_); int new_top = max(0, face_ori_rect.top_ - face_ori_rect.height_); - int new_right = min((int)task.task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); - int new_bottom = min((int)task.task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); + int new_right = min((int)dxGpuFrame.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); + int new_bottom = min((int)dxGpuFrame.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); int new_width = new_right - new_left; int new_height = new_bottom - new_top; @@ -2448,7 +2445,7 @@ void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count, snapShotInfo[cur_obj_key].face_info.face_position = {(face_ori_rect.left_ - face_expand_rect.left_), (face_ori_rect.top_ - face_expand_rect.top_), face_ori_rect.width_, face_ori_rect.height_}; - cudacommon::CropImgGpu((unsigned char*)task.task_algorithm_data.frame, task.task_algorithm_data.width, task.task_algorithm_data.height, + cudacommon::CropImgGpu((unsigned char*)dxGpuFrame.frame, dxGpuFrame.width, dxGpuFrame.height, (unsigned char*)snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); } } @@ -2470,7 +2467,7 @@ void snapshot_helper::clearSnapshotInfo() { void snapshot_helper::erase_snapshot_info(OBJ_KEY& objKey){ // if (5 == objKey.videoID) // { - // LOG_DEBUG("task:{} objId: {}", objKey.videoID, objKey.objID); + // LOG_DEBUG("task_id:{} objId: {}", objKey.videoID, objKey.objID); // } snapShotInfo.erase(objKey); 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 1a856a0..3be0864 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 @@ -68,7 +68,7 @@ struct OBJ_INDEX { struct OBJ_VALUE { bool finishTracker; //轨迹结束可以保存了 - int frameCount; + unsigned long long frameCount; bool isupdate; int lost; DxGPUFrame snapShot; @@ -191,9 +191,9 @@ 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); + CropInfo cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, sy_rect task_min_boxsize[DETECTTYPE], bool bCacheSrc, bool bCacheLittle, DxGPUFrame& dxGpuFrame); - 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); + 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[], DxGPUFrame& dxGpuFrame); int getIndexByKey(OBJ_KEY newObj); std::map::iterator getValueByKey(OBJ_KEY newObj); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp index 911a60e..140312b 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp @@ -209,9 +209,6 @@ static int sum = 0; void videoObjSnapshotCallback(void * handle, video_object_snapshot *snapshot_info) { // printf("snapshot_info: %d \n", sum++); - if(1) { - return; - } //#ifdef PRINTF_ATTRIRES // cout << "handle :" << handle << " snapshot " << snapshot_info->task_id << " " << snapshot_info->object_id << " " << " " << snapshot_info->task_frame_count << " " << // snapshot_info->video_image_path << " " << snapshot_info->snapshot_image_path << " " << snapshot_info->face_image_path << " " @@ -264,7 +261,7 @@ void videoObjSnapshotCallback(void * handle, video_object_snapshot *snapshot_inf //------------------------------------------------------------------------------------------------------------- //输出二次属性分析结果 - if (0) + if (1) // if (snapshot_info->analysisRes != NULL) { if (0 == snapshot_info->object_type_index) @@ -757,6 +754,8 @@ int main(int argc, char* argv[]) } beginTime = std::chrono::system_clock::now(); + int time_count = 0; + printf("begin add task\n"); do { if(get_running_task_number(handle) > 0){ @@ -784,6 +783,11 @@ int main(int argc, char* argv[]) } + time_count ++; + if(time_count > 10) { + break; + } + } while(1) ; // printf("-------------------Begin rt_view_task 1 !----------------------\n"); -- libgit2 0.21.4