From 938566bdf588fcdf4646ec38f164a1b3c63fa47c Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Fri, 12 Jan 2024 10:47:27 +0800 Subject: [PATCH] 删除无用代码;优化解码线程退出,避免任务结束时丢帧;代码优化 --- .vscode/launch.json | 22 ++-------------------- .vscode/settings.json | 3 ++- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp | 5 +++++ vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h | 1 + vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp | 16 ++++++++++++---- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h | 4 +++- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h | 2 -- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp | 92 +++----------------------------------------------------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h | 13 ------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h | 12 ++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp | 1 + vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleColor.h | 4 +--- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleRearRecg.cpp | 2 ++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp | 23 ++++++++++------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h | 5 +++-- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.h | 4 +--- vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp | 6 +++--- 18 files changed, 129 insertions(+), 270 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e5211d5..0727445 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,29 +2,11 @@ "version": "0.2.0", "configurations": [ { - "name": "(gdb) Launch", + "name": "mvpt", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512/test", - "args": ["file:///home/cmhu/data/video/Street.uvf?fastdecode=on","6","0","./db/mvpt.bin"], - "stopAtEntry": false, - "cwd": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - },{ - "name": "test_ffnvdecoder", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512/test", - "args": ["/home/cmhu/data/video/Street.uvf","6","0","./db/mvpt.bin"], + "args": ["/home/cmhu/data/video/123456-6.mp4","1","0","./db/mvpt.bin"], "stopAtEntry": false, "cwd": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512", "environment": [], diff --git a/.vscode/settings.json b/.vscode/settings.json index b216077..e553057 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -78,7 +78,8 @@ "numbers": "cpp", "semaphore": "cpp", "stop_token": "cpp", - "variant": "cpp" + "variant": "cpp", + "*.inc": "cpp" }, "git.ignoreLimitWarning": true } \ No newline at end of file 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 2de5fc5..119dc83 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 @@ -64,6 +64,7 @@ int DxDecoderWrap::DxOpenDecoder( const char * uri, unsigned int skip ) if(1 == m_decMode) { m_pDec->setDecKeyframe(true); } + m_bReal = m_pDec->isRealStream(); m_pDec->start(); LOG_INFO("[{}][{}]- 解码器初始化成功", m_name.c_str(), uri); return 0; @@ -232,6 +233,10 @@ void DxDecoderWrap::post_decode_callback(GPUFrame * decodedFrame) { break; } else { m_queue_frames_mutex.unlock(); + if (m_bReal) { + // 实时流不等待,直接弃帧 + return; + } std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } 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 b0cadc3..181f136 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 @@ -75,6 +75,7 @@ public: private: bool m_bClose; + bool m_bReal; FFDecConfig m_cfg; string m_name; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp index 5bb1865..af09e43 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp @@ -45,7 +45,6 @@ FFNvDecoder::FFNvDecoder() m_bReal = true; m_decode_thread = 0; - m_post_decode_thread = 0; m_bFinished = false; m_dec_keyframe = false; @@ -192,6 +191,8 @@ void FFNvDecoder::decode_thread() pkt = av_packet_alloc(); av_init_packet( pkt ); + m_bExitDisplay = false; + pthread_t m_post_decode_thread = 0; pthread_create(&m_post_decode_thread,0, [](void* arg) { @@ -255,6 +256,7 @@ void FFNvDecoder::decode_thread() if (result < 0){ av_packet_unref(pkt); LOG_ERROR("[{}] - Failed to send pkt: {}", m_dec_name, result); + std::this_thread::sleep_for(std::chrono::milliseconds(3)); continue; } @@ -264,8 +266,10 @@ void FFNvDecoder::decode_thread() LOG_ERROR("[{}] - Failed to receive frame: {}", m_dec_name, result); av_frame_free(&gpuFrame); av_packet_unref(pkt); + std::this_thread::sleep_for(std::chrono::milliseconds(3)); continue; } + av_packet_unref(pkt); decoded_frame_count++; @@ -295,8 +299,8 @@ void FFNvDecoder::decode_thread() // long end_time = get_cur_time(); // cout << "解码用时:" << end_time - start_time << endl; - if (m_post_decode_thread != 0) - { + if (m_post_decode_thread != 0){ + m_bExitDisplay = true; pthread_join(m_post_decode_thread,0); } @@ -341,7 +345,7 @@ void FFNvDecoder::post_decode_thread(){ unsigned long long index = 0; int frame_count = 0; - while (m_bRunning) + while (!m_bExitDisplay) { std::this_thread::sleep_for(std::chrono::milliseconds(2)); //给m_snapshot_mutex的喘息时间,避免截图一直截不到。避免线程资源占用。 if(mFrameQueue.size() > 0){ @@ -429,4 +433,8 @@ float FFNvDecoder::fps(){ unsigned long long FFNvDecoder::GetFrameCount() { return m_nb_frames; +} + +bool FFNvDecoder::isRealStream() { + return m_bReal; } \ No newline at end of file diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h index cafc5dd..65aecbd 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h @@ -33,6 +33,8 @@ public: DECODER_TYPE getDecoderType(){ return DECODER_TYPE_FFMPEG; } + bool isRealStream(); + public: AVPixelFormat getHwPixFmt(); @@ -50,9 +52,9 @@ private: AVPixelFormat hw_pix_fmt; pthread_t m_decode_thread; - pthread_t m_post_decode_thread; bool m_bRunning; + bool m_bExitDisplay{false}; bool m_bFinished; bool m_bPause; 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 3a3222b..524c198 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 @@ -106,22 +106,11 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN { set_default_logger(LogLevel(1), "multi_source_process", "logs/main.log", 64 * 1024 * 1024, 30); - // checkGpuMem(); licence_status = -1; thrd_status = -1; - //SetUnhandledExceptionFilter(CustomExceptionCrashHandler); int ret = SUCCESS; - /*DxLogConfig sCfg = { 0 }; - sCfg.serviceID = vptParam.serviceID; - sCfg.limitSize = vptParam.limitSize; - strcpy(sCfg.name, vptParam.name); - strcpy(sCfg.path, vptParam.path); - DxInitializeLog(&sCfg);*/ - - /*printf("=====================��ȨERROR==================\n"); - printf("=====================��ȨERROR==================\n"); - printf("=====================��ȨERROR==================\n");*/ + #ifdef AUTHORIZATION #ifdef _WIN32 if (SUCCESS == (ret = sy_licence(productSN))) @@ -130,99 +119,87 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN memset(wtime, 0, 15); char * time = wtime; ret = sy_licence(productSN, &time); - if (SUCCESS == ret) #endif #else ret = license_check(vptParam.auth_license, productSN);// sy_time_check(2022, 2); // ret = strcmp(AUTH_LICENSE, vptParam.auth_license); - if (ret == SUCCESS) #endif + if (ret != SUCCESS){ + return AUTHOR_ERROR; + } + + + cuInit(0); + int device_count = 0; + cuDeviceGetCount(&device_count); + + if (vptParam.gpuid >= device_count) { - cuInit(0); - int device_count = 0; - cuDeviceGetCount(&device_count); + printf("\nGPU_ID PARAM WRONG, gpuid: %d device_count: %d\n", vptParam.gpuid, device_count); + return GPUID_PARAM_ERROR; + } - if (vptParam.gpuid >= device_count) - { - printf("\nGPU_ID PARAM WRONG, gpuid: %d device_count: %d\n", vptParam.gpuid, device_count); - return GPUID_PARAM_ERROR; - } + CUdevice dev = 0; + size_t memSize = 0; + dev = vptParam.gpuid; - CUdevice dev = 0; - size_t memSize = 0; - dev = vptParam.gpuid; + CUresult rlt = CUDA_SUCCESS; + rlt = cuDeviceTotalMem(&memSize, dev); - CUresult rlt = CUDA_SUCCESS; - rlt = cuDeviceTotalMem(&memSize, dev); + gpu_total_memory = (float)memSize / (1024 * 1024); - gpu_total_memory = (float)memSize / (1024 * 1024); + if (gpu_total_memory < 9000) //8G�Դ棬С�ڴ淽�� + section_batch_size = 10; + else + section_batch_size = 20; - if (gpu_total_memory < 9000) //8G�Դ棬С�ڴ淽�� - section_batch_size = 10; - else - section_batch_size = 20; + if(vptParam.skip_frame > 0){ + // 默认值为5 + skip_frame_ = vptParam.skip_frame; + } - if(vptParam.skip_frame > 0){ - // 默认值为5 - skip_frame_ = vptParam.skip_frame; - } + mgpuid = vptParam.gpuid; + ret = m_vptProcess.init(mgpuid, section_batch_size); + if (0 != ret) + return ret; - mgpuid = vptParam.gpuid; - ret = m_vptProcess.init(mgpuid, section_batch_size); - if (0 != ret) - return ret; + viewTaskID = -1; + TotalTask = 0; - viewTaskID = -1; - TaskinPlay = 0; - TotalTask = 0; + taskFinishCallbackFunc = nullptr; + if (tFinishCallbackFunc != nullptr) + taskFinishCallbackFunc = std::bind(tFinishCallbackFunc, this, std::placeholders::_1); + + taskObjInfoCallbackFunc = nullptr; + if (tObjInfoCallbackFunc != nullptr) + taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1); - taskFinishCallbackFunc = nullptr; - if (tFinishCallbackFunc != nullptr) - taskFinishCallbackFunc = std::bind(tFinishCallbackFunc, this, std::placeholders::_1); - - taskObjInfoCallbackFunc = nullptr; - if (tObjInfoCallbackFunc != nullptr) - taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1); + CommandConfig cmdConfig; + cmdConfig.hp_analysis_config = vptParam.hp_analysis_config; + cmdConfig.hcp_analysis_config = vptParam.hcp_analysis_config; + cmdConfig.vehicle_analysis_config = vptParam.vehicle_analysis_config; + cmdConfig.hf_recg_config = vptParam.hf_recg_config; + cmdConfig.hcf_recg_config = vptParam.hcf_recg_config; + cmdConfig.vcf_recg_config = vptParam.vcf_recg_config; + cmdConfig.face_detect_config = vptParam.face_det_config; - m_hp_analysis_config = vptParam.hp_analysis_config; - m_hcp_analysis_config = vptParam.hcp_analysis_config; - m_vehicle_analysis_config = vptParam.vehicle_analysis_config; - m_hf_recg_config = vptParam.hf_recg_config; - m_hcf_recg_config = vptParam.hcf_recg_config; - m_vcf_recg_config = vptParam.vcf_recg_config; - m_face_det_config = vptParam.face_det_config; + m_face_det_config = vptParam.face_det_config; - m_snaphot_helper.snapshot_helper_init(vptParam.gpuid, gpu_total_memory, vptParam.vrdbpath, vptParam.auth_license, vptParam.wait_framecount, m_hp_analysis_config, \ - m_hcp_analysis_config, m_vehicle_analysis_config, m_vehicle_recg_config, m_vehicle_plate_det_recg_config, m_hf_recg_config, m_hcf_recg_config, m_vcf_recg_config, m_face_det_config); + m_snaphot_helper.snapshot_helper_init(vptParam.gpuid, gpu_total_memory, vptParam.vrdbpath, vptParam.auth_license, vptParam.wait_framecount, cmdConfig); - m_bProcessExit = false; - ProcessThread = std::thread(algorthim_process_thread, this); + m_bProcessExit = false; + ProcessThread = std::thread(algorthim_process_thread, this); - if (ret == SUCCESS) //�ɹ� - { - licence_status = 0; + if (ret == SUCCESS) //�ɹ� + { + licence_status = 0; #ifdef AUTHORIZATION - m_bExit = false; - thrd = std::thread(check_thread, this); + m_bExit = false; + thrd = std::thread(check_thread, this); #endif - thrd_status = 0; - } - - } - else - { - return AUTHOR_ERROR; - } -/* -#ifdef AUTHORIZATION -#ifdef __linux__ - if (wtime) - { - delete[] wtime; - wtime = NULL; + thrd_status = 0; } -#endif -#endif */ // debug by zsh + return ret; } @@ -234,7 +211,6 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID) Task& task = m_taskMap[taskID]; - if (task.taskState == PLAY) TaskinPlay--; task.taskState = FINISH; task.taskFileSource = nullptr; task.taskObjCallbackFunc = nullptr; @@ -284,7 +260,6 @@ void CMutliSourceVideoProcess::PauseTask(const int taskID) Task& task = m_taskMap[taskID]; - if (task.taskState == PLAY) TaskinPlay--; task.taskState = PAUSE; m_vptProcess.PauseTaskTracker(taskID); task.taskTcuvid->PauseDecoder(); @@ -301,7 +276,6 @@ void CMutliSourceVideoProcess::RestartTask(const int taskID) Task& task = m_taskMap[taskID]; task.taskState = PLAY; - TaskinPlay++; m_vptProcess.RestartTaskTraker(taskID); task.taskTcuvid->ResumeDecoder(); printf("-----------------------restart task: %d-----------------------\n", taskID); @@ -464,7 +438,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh m_taskMap[new_task.taskID] = new_task; TotalTask++; - TaskinPlay++; m_vptProcess.AddTaskTracker(new_task.taskID, width, height); @@ -645,19 +618,14 @@ void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(const VPT_Result& vpt } } + void CMutliSourceVideoProcess::algorthim_process() { - int count = 0; - - DxGPUFrame frame = {}; - cudaSetDevice(mgpuid); int total_count = 0; long long begintime1 =get_cur_time_ms(); - int process_times = 0; - long long last_time = get_cur_time_ms(); while (!m_bProcessExit) { @@ -696,6 +664,7 @@ void CMutliSourceVideoProcess::algorthim_process() } if (vec_dxGpuFrame.size() <= 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(5)); continue; } @@ -876,14 +845,6 @@ void CMutliSourceVideoProcess::algorthim_process() task.taskRealTimeCallbackFunc(task.frameImage.data, task.frameImage.rows, task.frameImage.cols); } } - - { - cudaError_t cudaStatus = cudaGetLastError(); - if (cudaStatus != cudaSuccess) { - LOG_ERROR("result last error: {}", cudaGetErrorString(cudaStatus)); - } - } - #ifdef LOG_INFO2 @@ -903,26 +864,17 @@ void CMutliSourceVideoProcess::algorthim_process() } } - - for (auto task_algorithm_data: vec_dxGpuFrame) { - cudaFree(task_algorithm_data.frame); - 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(); cudaError_t cudaStatus = cudaGetLastError(); if (cudaStatus != cudaSuccess) { LOG_ERROR("object_attri_analysis last error: {}", cudaGetErrorString(cudaStatus)); } + for (auto task_algorithm_data: vec_dxGpuFrame) { + cudaFree(task_algorithm_data.frame); + task_algorithm_data.frame = nullptr; + } + #ifdef LOG_INFO2 long long second_analysis_time2 = get_cur_time_ms(); cout << "second_analysis time_using:" << second_analysis_time2 - second_analysis_time << endl; @@ -940,7 +892,7 @@ void CMutliSourceVideoProcess::algorthim_process() m_snaphot_helper.clearSnapshotInfo(); long long costTime1 = get_cur_time_ms() - begintime1; - LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times); + LOG_INFO("Process Thread is Finished. total frame cost time = {} ms", costTime1); } int CMutliSourceVideoProcess::GetRuningNb() { 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 1b753db..fa40a01 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 @@ -136,9 +136,7 @@ public: int skip_frame_ {5}; // 控制跳帧参数 map m_taskMap; int AddTaskSucFlag; //0:��ʼ��״̬ 1����������ɹ� -1����������ʧ�� - int TaskinPlay; int TotalTask; - set TaskinPlayID; int viewTaskID; 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 232e390..cdabc49 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 @@ -289,6 +289,8 @@ vector VPTProcess::process(vector vec_data) { cout << "FrameIndex error !! lastFrameIndex= " << task_tracker.lastFrameIndex << " cur_frameindex = " << det_result_info.ts << endl; } + cout << "update_times " << update_times << 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); @@ -308,96 +310,8 @@ vector VPTProcess::process(vector vec_data) { 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){ - return FAILED; - } - - long long t1 = get_cur_time_ms(); - - vector >> detectResult(batchsize); - int real_index = 0; - - int cycle_time = batchsize / m_max_batch_size; - cycle_time = (batchsize % m_max_batch_size) == 0 ? cycle_time : (cycle_time + 1) ; - vector vec_img; - for (int i = 0; i < cycle_time; i++) { - vec_img.clear(); - - int start_index = i * m_max_batch_size; - int end_index = start_index + m_max_batch_size; - if(end_index >= batchsize) { - end_index = batchsize; - } - for (int j = start_index; j < end_index; j++) { - vec_img.push_back(batch_img[j]); - } - - 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]; - 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); - } - } - real_index++; - } - } - - for (int i = 0; i < batchsize; i++) { - TaskTracker& task_tracker = m_taskTrackerMap[i]; - if (!task_tracker.tracker.GetState()) { - continue; - } - if (task_tracker.lastFrameIndex > 0) { - // 非第一帧 - int update_times = vec_frameIndex[i] - task_tracker.lastFrameIndex - 1; - if (update_times < 0) { - cout << "FrameIndex error !! lastFrameIndex= " << task_tracker.lastFrameIndex << " cur_frameindex = " << vec_frameIndex[i] << 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); - unUsedResult[i].push_back(unresult); - } - } - result[i].objCount = task_tracker.tracker.update(task_tracker.ratioWidth, task_tracker.ratioHeight, true, detectResult[i], result[i].obj, deleteObjectID[i]); - - check_VPT_Result(result[i]); - - task_tracker.lastDetectResult = detectResult[i]; - task_tracker.lastDeleteObjectID = deleteObjectID[i]; - - // 记录帧序号 - task_tracker.lastFrameIndex = vec_frameIndex[i]; - } + return vec_result; } void VPTProcess::release() { 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 3e464aa..2f9159d 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 @@ -61,18 +61,7 @@ public: /************************************************************************* * PURPOSE: 人车物检测跟踪 - * PARAM: - [in] handle - 处理句柄 - [in] rgb - 图片数据(3通道BGR数据 cv::Mat格式) - [in] width - 图片宽度 - [in] height - 图片高度 - [in] result - 搜索结果,在外部申请足够内存 - [in] deleteObjectID - 删除的轨迹ID号 - [out] traffic - 交通流量结果结构体 内存在外部申请,大小与初始化时流量监测线个数相同,设置为NULL时不返回 - * RETURN: -1:图像错误; 其他:检测到的个数 - * NOTES: *************************************************************************/ - int process(sy_img * batch_img, int batchsize, vector vec_frameIndex, vector& result, vector>& deleteObjectID, vector>& unUsedResult); vector process(vector vec_data); @@ -85,8 +74,6 @@ public: *************************************************************************/ void release(); - - void AddTaskTracker(const int taskID, const double rWidth, const double rHeight); void FinishTaskTracker(const int taskID); void PauseTaskTracker(const int taskID); 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 26d6163..0846979 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 @@ -117,4 +117,16 @@ typedef struct VPT_Result }VPT_Result; +struct CommandConfig { + sy_command hp_analysis_config; + sy_command hcp_analysis_config; + sy_command vehicle_analysis_config; + sy_command vehicle_recg_config; + sy_command vehicle_plate_det_recg_config; + sy_command hf_recg_config; + sy_command hcf_recg_config; + sy_command vcf_recg_config; + sy_command face_detect_config; +}; + #endif diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp index 27fc0e8..968aa7f 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp @@ -91,6 +91,7 @@ int HumanCarParsing::process(sy_img * batch_img, int batch_size, hcp_analysis_re return SUCCESS; } + int HumanCarParsing::release() { if(handle) { diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleColor.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleColor.h index 31ec266..d6d2a85 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleColor.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleColor.h @@ -1,7 +1,5 @@ -#include "vehicle_color.h" - - #pragma once +#include "vehicle_color.h" #include #include "utools.h" #include diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleRearRecg.cpp b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleRearRecg.cpp index 84b8c4c..e2c7484 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleRearRecg.cpp +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleRearRecg.cpp @@ -33,6 +33,7 @@ int VehicleRearRecg::init(char*dbpath, int gpuid, char* auth_license) LOG_INFO("vrr_init success! gpu_id: {}", gpuid); return SUCCESS; } + int VehicleRearRecg::process(sy_img * batch_img, int batchsize, vehicle_rear_result *&vr_result) { for (int i = 0; i < batchsize; i++) @@ -47,6 +48,7 @@ int VehicleRearRecg::process(sy_img * batch_img, int batchsize, vehicle_rear_res return SUCCESS; } + int VehicleRearRecg::release() { if (handle) { 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 eaed8d4..0d8979b 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 @@ -15,8 +15,6 @@ 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) { @@ -85,16 +83,15 @@ void SnapshotImageWriteThreadProcess(const void * userPtr){ } } -void snapshot_helper::snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, sy_command hp_analysis_config, \ - sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command vehicle_recg_config, sy_command vehicle_plate_det_recg_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config, sy_command face_detect_config) +void snapshot_helper::snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, CommandConfig cmdConfig) { - hp_analysis_cf = hp_analysis_config; - hcp_analysis_cf = hcp_analysis_config; - vehicle_analysis_cf = vehicle_analysis_config; - hf_recg_cf = hf_recg_config; - hcf_recg_cf = hcf_recg_config; - vcf_recg_cf = vcf_recg_config; - face_detect_cf = face_detect_config; + hp_analysis_cf = cmdConfig.hp_analysis_config; + hcp_analysis_cf = cmdConfig.hcp_analysis_config; + vehicle_analysis_cf = cmdConfig.vehicle_analysis_config; + hf_recg_cf = cmdConfig.hf_recg_config; + hcf_recg_cf = cmdConfig.hcf_recg_config; + vcf_recg_cf = cmdConfig.vcf_recg_config; + face_detect_cf = cmdConfig.face_detect_config; char* dbpath_utf8 = nullptr; #ifdef _MSC_VER //dbpath_utf8 = GbkToUtf8(dbpath); @@ -2067,8 +2064,8 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, sy_ 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 right = min(frameWidth - 1, (int)(obj.right + boundaryLittle) ); + int bottom = min(frameHeight - 1, (int)(obj.bottom + boundaryLittle) ); snapShotInfo[newObj].frameCount = dxGpuFrame.timestamp; snapShotInfo[newObj].isupdate = true; snapShotInfo[newObj].lost = 0; 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 3be0864..d0c4904 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 @@ -166,8 +166,9 @@ public: std::mutex finishedThreadMutex; V_ANALYSIS_TYPE v_analysis; - void snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, sy_command hp_analysis_config, \ - sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command vehicle_recg_config, sy_command vehicle_plate_det_recg_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config, sy_command face_detect_config); + + void snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, CommandConfig cmdConfig); + void snapshot_helper_release(); void add_task_info(int new_task_id, TASK_INFO new_task_info); void delete_task_info(int new_task_id, TASK_INFO new_task_info); diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.h b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.h index 8d7d5ec..88614b3 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.h +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.h @@ -66,12 +66,10 @@ private: bool istraffic = 0; //by zl 是否统计交通量 //vector tracker; bool WORK = false; - bool m_bYOLOv5 = true; + bool m_bYOLOv5 {true}; private: void associate_detections_to_trackers(vector< vector > &matched, vector &unmatched_dets, vector &unmatched_trks, vector< vector > &dets, vector< vector > &trks, float iou_threshold = 0.3); - //int addTracker(VPT_ObjInfo *result, int resultcount); - int Traffic(); }; //辅助函数 void RectboundCheck(int Width, int Height, VPT_ObjInfo * result); //防止坐标越界 by zl 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 140312b..d1dc9ac 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 @@ -686,7 +686,7 @@ void create_task(const char * videoFileName, int total_index) { strcpy(tparam.video_filename, videoFileName); tparam.on_image_display = false; tparam.jpeg_quality = 30; //debug by zsh - tparam.decMode = 1; // 关键帧解码 + tparam.decMode = 0; // 关键帧解码 //tparam.video_filename = argv[total_index%4]; memcpy(tparam.minBoxsize, m_boxsize, sizeof(sy_rect)* DETECTTYPE); @@ -741,7 +741,7 @@ int main(int argc, char* argv[]) vptParam.wait_framecount = 30; vptParam.serviceID = 0; vptParam.limitSize = (10 << 20); - vptParam.skip_frame = 1; + vptParam.skip_frame = 12; strcat(vptParam.name, "gbrealtime"); strcat(vptParam.path, "./log/"); int flag = mvpt_init(&handle, vptParam); @@ -788,7 +788,7 @@ int main(int argc, char* argv[]) break; } - } while(1) ; + } while(0) ; // printf("-------------------Begin rt_view_task 1 !----------------------\n"); // rt_view_task(handle, 0); -- libgit2 0.21.4