From c7af27aa5179d153c671fc653b586cced5b07bb4 Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Mon, 6 Nov 2023 15:53:27 +0800 Subject: [PATCH] 修复崩溃问题:tasks[*iter].task_algorithm_data.frame 重复释放了两次造成 --- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp | 79 ++++++++++++++++++++++++++++++++++++------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h | 6 ++---- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp | 11 ++++++++--- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/ImageSaveGPU.cpp | 2 +- vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/NV12ToRGB.cu | 4 ++-- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp | 711 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h | 20 +------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/CropImg.cu | 21 +++++++++++++++++++++ vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp | 65 +++++++++++++++++++++++++++++++++++++++-------------------------- vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h | 2 ++ vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp | 9 +++++---- 11 files changed, 439 insertions(+), 491 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 88ff6f3..0f022cc 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 @@ -22,7 +22,6 @@ DxDecoderWrap::DxDecoderWrap( const DxConfig * cfg ) { m_bClose = false; m_pDec = nullptr; - m_pHwData = nullptr; m_cfg.post_decoded_cbk = decoded_cbk; m_cfg.decode_finished_cbk = decode_finished_cbk; @@ -92,17 +91,15 @@ int DxDecoderWrap::DxCloseDecoder() m_queue_frames_mutex.lock(); while (m_queue_frames.size() > 0) { - GPUFrame * decodedFrame = m_queue_frames.front(); + DxGPUFrame decodedFrame = m_queue_frames.front(); + if (decodedFrame.frame) { + cudaFree(decodedFrame.frame); + decodedFrame.frame = nullptr; + } m_queue_frames.pop(); - delete decodedFrame; - decodedFrame = nullptr; } m_queue_frames_mutex.unlock(); - if(m_pHwData != nullptr){ - cudaFree(m_pHwData); - } - return 0; } @@ -165,48 +162,16 @@ bool DxDecoderWrap::DxFrameIsEmpty() } -int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) +int DxDecoderWrap::DxLockFrame(DxGPUFrame& frame) { - if ( NULL == frame ) - { - return -1; - } - std::lock_guard l(m_queue_frames_mutex); if(m_queue_frames.size() <= 0) { return -1; } - GPUFrame * decodedFrame = m_queue_frames.front(); + frame = m_queue_frames.front(); m_queue_frames.pop(); - AVFrame* gpuFrame = decodedFrame->gpuFrame; - - cudaSetDevice(atoi(m_cfg.gpuid.c_str())); - cudaError_t cudaStatus; - size_t rgbSize = 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char); - unsigned char *pHwData = nullptr; - cudaStatus = cudaMalloc((void **)&pHwData, rgbSize); - if (cudaStatus != cudaSuccess) { - LOG_ERROR("[{}]- cudaMalloc failed !!!", m_name.c_str()); - return -1; - } - cuda_common::setColorSpace( ITU_709, 0 ); - cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height); - if (cudaStatus != cudaSuccess) { - LOG_ERROR("[{}]- CUDAToBGR failed !!!", m_name.c_str()); - return -1; - } - - frame->width = gpuFrame->width; - frame->height = gpuFrame->height; - frame->size = gpuFrame->width; - frame->frame = pHwData; - frame->timestamp = decodedFrame->ts; - - delete decodedFrame; - decodedFrame = nullptr; - return 0; } @@ -215,7 +180,35 @@ void DxDecoderWrap::post_decode_thread(GPUFrame * decodedFrame) { m_queue_frames_mutex.lock(); if(m_queue_frames.size() < 3) { // 入队 - m_queue_frames.push(decodedFrame); + AVFrame* gpuFrame = decodedFrame->gpuFrame; + + cudaSetDevice(atoi(m_cfg.gpuid.c_str())); + cudaError_t cudaStatus; + size_t rgbSize = 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char); + unsigned char *pHwData = nullptr; + cudaStatus = cudaMalloc((void **)&pHwData, rgbSize); + if (cudaStatus != cudaSuccess) { + LOG_ERROR("[{}]- cudaMalloc failed !!!", m_name.c_str()); + return ; + } + cuda_common::setColorSpace( ITU_709, 0 ); + cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height); + if (cudaStatus != cudaSuccess) { + LOG_ERROR("[{}]- CUDAToBGR failed !!!", m_name.c_str()); + return ; + } + + DxGPUFrame frame; + frame.width = gpuFrame->width; + frame.height = gpuFrame->height; + frame.size = gpuFrame->width; + frame.frame = pHwData; + frame.timestamp = decodedFrame->ts; + + delete decodedFrame; + decodedFrame = nullptr; + + m_queue_frames.push(frame); m_queue_frames_mutex.unlock(); break; } else { 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 bf39fb7..b381508 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 @@ -59,7 +59,7 @@ public: int DxGetResolution( int &width, int &height ); bool DxFrameIsEmpty(); - int DxLockFrame( DxGPUFrame * frame ); + int DxLockFrame(DxGPUFrame& frame ); int PauseDecoder(); int ResumeDecoder(); @@ -76,11 +76,9 @@ private: string m_name; FFNvDecoder* m_pDec; - std::queue m_queue_frames; + std::queue m_queue_frames; std::mutex m_queue_frames_mutex; - unsigned char *m_pHwData {nullptr}; - int m_decMode{0}; }; 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 d7f2954..a996777 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 @@ -65,10 +65,11 @@ bool FFNvDecoder::init(FFDecConfig& cfg) fp=fopen(cfg.uri.c_str(),"rb"); if(fp!=nullptr) { m_bReal = false; + fclose(fp); } else { m_bReal = true; } - fclose(fp); + post_decoded_cbk = cfg.post_decoded_cbk; decode_finished_cbk = cfg.decode_finished_cbk; @@ -283,6 +284,10 @@ void FFNvDecoder::decode_thread() av_packet_unref(pkt); } + while(m_bRunning && mFrameQueue.size() > 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + } + m_bRunning = false; // long end_time = get_cur_time(); @@ -293,8 +298,6 @@ void FFNvDecoder::decode_thread() pthread_join(m_post_decode_thread,0); } - decode_finished_cbk(m_finishedDecArg); - // 清空队列 while(mFrameQueue.size() > 0){ GPUFrame * frame = mFrameQueue.front(); @@ -305,6 +308,8 @@ void FFNvDecoder::decode_thread() decode_finished(); + decode_finished_cbk(m_finishedDecArg); + LOG_INFO("[{}] - decode thread exited, decoded frame count: {}", m_dec_name, decoded_frame_count); } 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 d15aab5..bd0bff5 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 @@ -37,7 +37,7 @@ int partMemCopy(unsigned char* d_srcRGB, int src_width, int src_height, unsigned { cudaError_t cudaStatus = cuda_common::PartMemCopy(d_srcRGB, src_width, src_height, d_dstRGB, left, top, right, bottom); if (cudaStatus != cudaSuccess) { - LOG_ERROR("cuda_common::77 PartMemCopy failed: {} {} {} {} {} {} {}",cudaGetErrorString(cudaStatus), left, top, right, bottom, src_height, d_dstRGB); + LOG_ERROR("cuda_common::PartMemCopy failed: {} {} {} {} {} {} {}",cudaGetErrorString(cudaStatus), left, top, right, bottom, src_height, d_dstRGB); return -1; } diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/NV12ToRGB.cu b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/NV12ToRGB.cu index 58e1dff..6cfc5c4 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/NV12ToRGB.cu +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/NV12ToRGB.cu @@ -330,13 +330,13 @@ namespace cuda_common CUDAToBGR_drvapi << < grid, block >> >((uint32 *)dataY, (uint32 *)dataUV, pitchY, pitchUV, d_dstRGB, width, height); cudaError_t cudaStatus = cudaGetLastError(); if (cudaStatus != cudaSuccess) { - fprintf(stderr, "NV12ToRGB_drvapi launch failed: %s\n", cudaGetErrorString(cudaStatus)); + fprintf(stderr, "CUDAToBGR launch failed: %s\n", cudaGetErrorString(cudaStatus)); return cudaStatus; } cudaStatus = cudaDeviceSynchronize(); if (cudaStatus != cudaSuccess) { - fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching NV12ToRGB_drvapi !\n", cudaStatus); + fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching CUDAToBGR !\n", cudaStatus); return cudaStatus; } 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 108eb7e..21befc6 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 @@ -23,7 +23,7 @@ //********************************************************// //1.Ϊʲô��ʱ�򷵻ص�index=2��ȴδ�����ﳵ�ķ�������Ϊindex�ں�����Ϊ��2�����Ǵ�ʱ�Ŀ��ղ�������֮ǰ�Ŀ��գ����Կ���δ���£�����ͼ���С����Ϊ112*224 -#define AUTHORIZATION +// #define AUTHORIZATION //#define DQ_AUTHORIZATION @@ -50,6 +50,8 @@ // #define SKIP_FRMAE 5 //��֡֡�� #define EXTIME 500 +#define AUTH_LICENSE "sy_va_sub_sdk_2023" + static int TaskID = 0; auto show_gpu_syimage_ = [](sy_img& cur_frame) { @@ -212,7 +214,8 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN if (SUCCESS == ret) #endif #else - ret = license_check(vptParam.auth_license, productSN);// sy_time_check(2022, 2); + // ret = license_check(vptParam.auth_license, productSN);// sy_time_check(2022, 2); + ret = strcmp(AUTH_LICENSE, vptParam.auth_license); if (ret == SUCCESS) #endif { @@ -264,14 +267,6 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN viewTaskID = -1; TaskinPlay = 0; TotalTask = 0; - capacity = 20; - VPTResult.resize(capacity); - //dwThreadID = 0; - ProcessFlag = false; - SourceFlag = false; - - mModeSnapshotVideo = "cpu"; - mModeSnapshotLittle = "cpu"; taskFinishCallbackFunc = nullptr; if (tFinishCallbackFunc != nullptr) @@ -291,6 +286,10 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN 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_bProcessExit = false; + ProcessThread = std::thread(algorthim_process_thread, this); + if (ret == SUCCESS) //�ɹ� { licence_status = 0; @@ -365,13 +364,6 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID) tasks[i].frameImage.release(); - - if (tasks[i].task_algorithm_data.frame) - { - cudaFree(tasks[i].task_algorithm_data.frame); - tasks[i].task_algorithm_data.frame = nullptr; - } - FinishTaskTracker(VPT_Handle, taskID); if (viewTaskID == taskID) viewTaskID = -1; @@ -445,13 +437,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh std::lock_guard l(_tx_add_task); using std::placeholders::_1; - // printf("begin real add task\n"); - if (TaskinPlay >= capacity) - { - //cout << "********************** resize capacity *************************" << endl; - capacity *= 2; - VPTResult.resize(capacity); - } Task new_task = {}; new_task.taskID = TotalTask; @@ -490,7 +475,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh new_task.frameImage = cv::Mat::zeros(height, width, CV_8UC3); new_task.taskState = PLAY; - new_task.task_algorithm_data.frame = NULL; new_task.taskFrameCount = 0; new_task.taskLastFrameCount = 0; @@ -576,12 +560,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh tasks.push_back(new_task); AddTaskTracker(VPT_Handle, new_task.taskID, width, height); - - if (!ProcessFlag) { - m_bProcessExit = false; - ProcessThread = std::thread(algorthim_process_thread, this); - ProcessFlag = true; - } AddTaskSucFlag = 1; @@ -591,12 +569,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh int CMutliSourceVideoProcess::AddOperator(task_param tparam) { - if (!ProcessFlag) - { - AddTask(tparam); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - } - else { // printf("add first task in operator queue\n"); std::unique_lock l(taskMutex); @@ -765,466 +737,427 @@ void CMutliSourceVideoProcess::algorthim_process() { set k; int count = 0; - sy_img * batch_img = new sy_img[20]{}; DxGPUFrame frame = {}; cudaSetDevice(mgpuid); - CUdevice cuDevice; - cuDeviceGet(&cuDevice, mgpuid); - CUcontext context; - cuCtxCreate(&context, 0, cuDevice); - cuCtxPushCurrent(context); - 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) { - while (!m_bProcessExit) + if (licence_status <= -3) { - if (licence_status <= -3) - { - printf("authority failed!\n"); - break; - } + printf("authority failed!\n"); + break; + } - double time_val, time_val_p = 0; - { - std::lock_guard l(taskMutex); - OperatorTask(); - } - taskCondVar.notify_all(); + double time_val, time_val_p = 0; + { + std::lock_guard l(taskMutex); + OperatorTask(); + } + + taskCondVar.notify_all(); - int curTaskSize = tasks.size(); + int curTaskSize = tasks.size(); - count = 0; - static int ncount = 0; - map> finishTaskDeleteObj; - int curPlayTaskCount = 0; + count = 0; + static int ncount = 0; + map> finishTaskDeleteObj; + int curPlayTaskCount = 0; - for (int i = 0; i < curTaskSize; i++) + for (int i = 0; i < curTaskSize; i++) + { + if ((tasks[i].taskState == PLAY || tasks[i].taskState == DECODEERROR)) { - if ((tasks[i].taskState == PLAY || tasks[i].taskState == DECODEERROR)) + if (!tasks[i].taskTcuvid->DxDecoderIsRun()) { - if (!tasks[i].taskTcuvid->DxDecoderIsRun()) - { - cudaError_t cudaStatus = cudaGetLastError(); - if (cudaStatus != cudaSuccess) { - printf("begin finish last error: %s\n", cudaGetErrorString(cudaStatus)); - } + cudaError_t cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) { + printf("begin finish last error: %s\n", cudaGetErrorString(cudaStatus)); + } + + cout << "***************** Task " << i << " is Finished *****************" << endl; + tasks[i].taskState = FINISH; + + FinishTask(tasks[i].taskID); + + tasks[i].taskTcuvid->DxCloseDecoder(); + delete tasks[i].taskTcuvid; + tasks[i].taskTcuvid = NULL; - cout << "***************** Task " << i << " is Finished *****************" << endl; - tasks[i].taskState = FINISH; - - FinishTask(tasks[i].taskID); - - tasks[i].taskTcuvid->DxCloseDecoder(); - delete tasks[i].taskTcuvid; - tasks[i].taskTcuvid = NULL; - int taskid = tasks[i].taskID; - - //ѭ���ȴ� ֱ��finished_analysis_ss_info�����и�·Ŀ�궼�Ѿ����ظ��û����ſ��������������� - std::unique_lock lock(m_snaphot_helper.analysisThreadMutex); - while (std::find_if(m_snaphot_helper.finished_analysis_ss_info.begin(), m_snaphot_helper.finished_analysis_ss_info.end(), [&taskid](const std::pair & item) ->bool { - if (item.first.videoID == taskid) - { - return true; - } - else - { - return false; - } - - }) != m_snaphot_helper.finished_analysis_ss_info.end()) + int taskid = tasks[i].taskID; + std::unique_lock lock(m_snaphot_helper.analysisThreadMutex); + while (std::find_if(m_snaphot_helper.finished_analysis_ss_info.begin(), m_snaphot_helper.finished_analysis_ss_info.end(), [&taskid](const std::pair & item) ->bool { + if (item.first.videoID == taskid) { - lock.unlock(); - std::this_thread::yield(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - lock.lock(); + return true; } - - //�ص�֪ͨ�û� ��·����������� - if (taskFinishCallbackFunc != nullptr) + else { - std::lock_guard l(m_snaphot_helper.callback_tx); - taskFinishCallbackFunc(tasks[i].taskID); + return false; } - TaskinPlay--; + }) != m_snaphot_helper.finished_analysis_ss_info.end()) + { + lock.unlock(); + std::this_thread::yield(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + lock.lock(); } - } - if (tasks[i].taskState == FINISH) - count++; - } - - //�������������FINISH״̬ - if (count >= tasks.size()) //have no decode video, break - { - { - std::lock_guard l(taskMutex); - //�ж���������ȴ������Ƿ����µ��������� - if (HasNewTask()) + //�ص�֪ͨ�û� ��·����������� + if (taskFinishCallbackFunc != nullptr) { - continue; + std::lock_guard l(m_snaphot_helper.callback_tx); + taskFinishCallbackFunc(tasks[i].taskID); } - else - { - //std::this_thread::sleep_for(std::chrono::milliseconds(40)); - //continue; - //printf("802 set ProcessFlag false\n"); - //Sleep(10); - //continue; - - //printf("0708\n"); - //ProcessFlag = false; - break; - } + TaskinPlay--; } } - - //��ǰû��PLAY������ ѭ���ȴ� - curPlayTaskCount = TaskinPlay; - if (curPlayTaskCount <= 0) { - Sleep(30); - continue; - } - k.clear(); - TaskinPlayID.clear(); - - //��ȡ�������� - getdata_flag: - for (int i = 0; i < curTaskSize; i++) + if (tasks[i].taskState == FINISH) + count++; + } + + //�������������FINISH״̬ + if (count >= tasks.size()) //have no decode video, break + { { - if (k.find(i) == k.end() && tasks[i].taskState == PLAY && tasks[i].taskTcuvid->DxDecoderIsRun()) + std::lock_guard l(taskMutex); + //�ж���������ȴ������Ƿ����µ��������� + if (HasNewTask()) { - if(tasks[i].taskTcuvid->DxLockFrame(&tasks[i].task_algorithm_data) == 0) { - k.insert(i); - TaskinPlayID.insert(tasks[i].taskID); - } + continue; } - else if (k.find(i) == k.end() && tasks[i].taskState == PLAY && !tasks[i].taskTcuvid->DxDecoderIsRun()) + else { - tasks[i].taskState = DECODEERROR; - curPlayTaskCount--; - FinishTaskTracker(VPT_Handle, tasks[i].taskID); + continue; } } + } - if (curPlayTaskCount <= 0) { - Sleep(30); - continue; - } + //��ǰû��PLAY������ ѭ���ȴ� + curPlayTaskCount = TaskinPlay; + if (curPlayTaskCount <= 0) { + Sleep(30); + continue; + } - //��û�л�ȡ������·���Ľ������� ѭ���ȴ� - if (k.size() < curPlayTaskCount) + 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()) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - goto getdata_flag; + 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--; + FinishTaskTracker(VPT_Handle, tasks[i].taskID); } + } + + if (curPlayTaskCount <= 0) { + Sleep(30); + continue; + } + + //��û�л�ȡ������·���Ľ������� ѭ���ȴ� + if (k.size() < curPlayTaskCount) + { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + goto getdata_flag; + } #ifdef LOG_INFO2 - long long gather_data_time = get_cur_time_ms(); - std::cout << "gather_data time_using: " << gather_data_time - last_time << std::endl; + long long gather_data_time = get_cur_time_ms(); + std::cout << "gather_data time_using: " << gather_data_time - last_time << std::endl; #endif - cudaDeviceSynchronize(); + cudaDeviceSynchronize(); - //------------------------------ ͳһBATCH���� --------------------------------// - ////////////////////////////////////////////////////////////// - //// - //// compose data -> batch - //// - ///////////////////////////////////////////////////////////// - vector> deleteObjectID; - set::iterator iter = TaskinPlayID.begin(); + vector> deleteObjectID; + set::iterator iter = TaskinPlayID.begin(); - int cur_batch_size = 0; - cur_batch_size = section_batch_size; + int cur_batch_size = 0; + cur_batch_size = section_batch_size; - if (0) + if (0) + { + if (section_batch_size == 20) + cur_batch_size = section_batch_size; + else { - 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); - } + 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(); + } + + long long start_time_vpt = get_cur_time_ms(); + + sy_img batch_img[TaskinPlayID.size()]; + vector> unUsedResult; + vector vec_frameIndex; + vector VPTResult(TaskinPlayID.size()); + unUsedResult.resize(TaskinPlayID.size()); + int cycleTimes = curPlayTaskCount / cur_batch_size + (curPlayTaskCount % cur_batch_size == 0 ? 0 : 1); + for (int c = 0; c < cycleTimes; c++) + { + int batchsize = c == cycleTimes - 1 ? (curPlayTaskCount - cur_batch_size*c) : cur_batch_size; + int startbatch = c*cur_batch_size; - vector> unUsedResult; - vector vec_frameIndex; - unUsedResult.resize(VPTResult.size()); - int cycleTimes = curPlayTaskCount / cur_batch_size + (curPlayTaskCount % cur_batch_size == 0 ? 0 : 1); - for (int c = 0; c < cycleTimes; c++) + vec_frameIndex.clear(); + for (int i = 0; i < batchsize; i++) { - int batchsize = c == cycleTimes - 1 ? (curPlayTaskCount - cur_batch_size*c) : cur_batch_size; - int startbatch = c*cur_batch_size; + DxGPUFrame task_algorithm_data = tasks[*iter].task_algorithm_data; + int w = task_algorithm_data.width; + int h = task_algorithm_data.height; + int npitch = task_algorithm_data.size; - vec_frameIndex.clear(); - for (int i = 0; i < batchsize; i++) - { - DxGPUFrame task_algorithm_data = tasks[*iter].task_algorithm_data; - 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++; - } + batch_img[i].set_data(w, h, 3, (unsigned char *)task_algorithm_data.frame); + vec_frameIndex.push_back(task_algorithm_data.timestamp); + iter++; + } - vector> tempDeleteObjectID; - tempDeleteObjectID.resize(batchsize); - int flag = VPT_Process_GPU(GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, VPTResult, tempDeleteObjectID, unUsedResult); - process_times++ ; - - for (auto iter : tempDeleteObjectID) - { - deleteObjectID.push_back(iter); - } - vector>().swap(tempDeleteObjectID); + vector> tempDeleteObjectID; + tempDeleteObjectID.resize(batchsize); + int flag = VPT_Process_GPU(GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, VPTResult, tempDeleteObjectID, unUsedResult); + process_times++ ; + + for (auto iter : tempDeleteObjectID) + { + deleteObjectID.push_back(iter); } + vector>().swap(tempDeleteObjectID); + } + #ifdef LOG_INFO2 - std::cout << "VPT_Process_GPU time_using: " << get_cur_time_ms() - start_time_vpt << std::endl; + std::cout << "VPT_Process_GPU time_using: " << get_cur_time_ms() - start_time_vpt << std::endl; #endif + + long long result_analysis_time = get_cur_time_ms(); + + iter = TaskinPlayID.begin(); + for (int i = 0; i < curPlayTaskCount; 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); + } - long long result_analysis_time = get_cur_time_ms(); + //实时查看模块,若存在实时查看,把当前视频画面cp回内存 + bool view = false; + int frameHeight = task.task_algorithm_data.height; + int frameWidth = task.task_algorithm_data.width; - iter = TaskinPlayID.begin(); - for (int i = 0; i < curPlayTaskCount; i++) + if (*iter == viewTaskID) { - Task task = tasks[*iter]; - task.taskFrameCount = task.task_algorithm_data.timestamp; - //若该路任务当前帧未检测到目标,返回ID为-1的目标表明未检测到目标 - if (VPTResult[i].objCount == 0) - { - callTaskObjInfoCallbackFunc(0, nullptr, task.taskFrameCount, *iter); - } - - //实时查看模块,若存在实时查看,把当前视频画面cp回内存 - bool view = false; - int frameHeight = task.task_algorithm_data.height; - int frameWidth = task.task_algorithm_data.width; + cudaMemcpy(task.frameImage.data, task.task_algorithm_data.frame, 3 * task.task_algorithm_data.width * task.task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); + view = true; + } - if (*iter == viewTaskID) + //跟踪帧也需要返回跟踪的结果 + if (task.taskLastFrameCount > 0) + { + vector OneUnUsedResult = unUsedResult[i]; + if (OneUnUsedResult.size() == 0) { - cudaMemcpy(task.frameImage.data, task.task_algorithm_data.frame, 3 * task.task_algorithm_data.width * task.task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); - view = true; + callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + 1, *iter); } - - //跟踪帧也需要返回跟踪的结果 - if (task.taskLastFrameCount > 0) + for (int k = 0; k < OneUnUsedResult.size(); ++k) { - vector OneUnUsedResult = unUsedResult[i]; - if (OneUnUsedResult.size() == 0) + if (OneUnUsedResult[k].objCount == 0) { - callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + 1, *iter); + callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + k + 1, *iter); } - for (int k = 0; k < OneUnUsedResult.size(); ++k) + else { - 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); - } + //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); } } - task.taskLastFrameCount = task.taskFrameCount; - - unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{};// = new unsigned char*[VPTResult[i].objCount]; - int snapshot_left[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; - int snapshot_right[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; - int snapshot_top[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; - int snapshot_bottom[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; - int snapshot_dst_width[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; - int snapshot_dst_height[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; - - int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 - 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++) - { - OBJ_KEY newObj = { (*iter), VPTResult[i].obj[c].id }; + } + task.taskLastFrameCount = task.taskFrameCount; - //实时查看模块 绘制目标框到画面上 - if (view) - { - int index = m_snaphot_helper.getIndexByKey(newObj); - if(index < 0) { - index = VPTResult[i].obj[c].index; - } + unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{}; + int snapshot_left[MAX_OBJ_COUNT]{}; + int snapshot_right[MAX_OBJ_COUNT]{}; + int snapshot_top[MAX_OBJ_COUNT]{}; + int snapshot_bottom[MAX_OBJ_COUNT]{}; + int snapshot_dst_width[MAX_OBJ_COUNT]{}; + int snapshot_dst_height[MAX_OBJ_COUNT]{}; - //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; - - cv::rectangle(task.frameImage, Rect(VPTResult[i].obj[c].left, VPTResult[i].obj[c].top, - VPTResult[i].obj[c].right - VPTResult[i].obj[c].left, - VPTResult[i].obj[c].bottom - VPTResult[i].obj[c].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"); - #else - string resss = "" + to_string(VPTResult[i].obj[c].id) + " " + ObjTypesEnglish[VPTResult[i].obj[c].index]; - cv::putText(task.frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); - #endif + int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 + 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++) + { + VPT_ObjInfo obj = VPTResult[i].obj[c]; + + OBJ_KEY newObj = { (*iter), obj.id }; + + //实时查看模块 绘制目标框到画面上 + if (view) + { + int index = m_snaphot_helper.getIndexByKey(newObj); + if(index < 0) { + index = obj.index; } - CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, VPTResult[i].obj[c], task); - 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); - } + //cout << "---- vew ---- "; + 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); + #ifdef _MSC_VER + string resss = "" + to_string(index) + " " + ObjTypes[index]; + putTextZH(task.frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); + #else + string resss = "" + to_string(obj.id) + " " + ObjTypesEnglish[obj.index]; + cv::putText(task.frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); + #endif + } - copy_obj_count++; + CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, obj, task); + 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); } + + copy_obj_count++; } + } - //若待抠图的快照数不为0 则进行批量抠图 - if (0 != copy_obj_count) + //若待抠图的快照数不为0 则进行批量抠图 + if (0 != copy_obj_count) + { + PartMemResizeBatch((unsigned char*)task.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); + + //最新刚添加的人脸检测模块,针对存在的行人快照进行人脸检测+人脸快照框的优选 + if (m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty()) { - cudaSetDevice(mgpuid); - cuCtxPushCurrent(context); - PartMemResizeBatch((unsigned char*)task.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); - cuCtxPopCurrent(&context); - - //最新刚添加的人脸检测模块,针对存在的行人快照进行人脸检测+人脸快照框的优选 - if (m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty()) + //需要做人脸检测 + int human_count = human_idx.size(); + sy_img human_img[human_count]; + sy_point ori_points[human_count]; + for (int idx = 0; idx < human_count; idx++) { - //需要做人脸检测 - int human_count = human_idx.size(); - sy_img human_img[human_count]; - sy_point ori_points[human_count]; - for (int idx = 0; idx < human_count; idx++) - { - int ii = human_idx[idx]; - human_img[idx].set_data(snapshot_dst_width[ii], snapshot_dst_height[ii], 3, snapshot_image_data[ii]); - ori_points[idx].x_ = (snapshot_right[ii] - snapshot_left[ii]); - 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); + int ii = human_idx[idx]; + human_img[idx].set_data(snapshot_dst_width[ii], snapshot_dst_height[ii], 3, snapshot_image_data[ii]); + ori_points[idx].x_ = (snapshot_right[ii] - snapshot_left[ii]); + ori_points[idx].y_ = (snapshot_bottom[ii] - snapshot_top[ii]); } - } - //实时查看 绘制目标轨迹 回调函数返回 - if (view) - { - DrawTracker(VPT_Handle, *iter, &task.frameImage); - if (task.taskRealTimeCallbackFunc != nullptr) - task.taskRealTimeCallbackFunc(task.frameImage.data, task.frameImage.rows, task.frameImage.cols); + m_snaphot_helper.cacheFaceSnapshotInfo(human_img, human_count, ori_points, human_idx, human_obj_keys, snapshot_left, snapshot_top, task); } - // tasks[*iter].taskFrameCount += skip_frame_; - iter++; } + //实时查看 绘制目标轨迹 回调函数返回 + if (view) + { + DrawTracker(VPT_Handle, *iter, &task.frameImage); + if (task.taskRealTimeCallbackFunc != nullptr) + task.taskRealTimeCallbackFunc(task.frameImage.data, task.frameImage.rows, task.frameImage.cols); + } + // tasks[*iter].taskFrameCount += skip_frame_; + iter++; + } + #ifdef LOG_INFO2 - long long result_analysis_time2 = get_cur_time_ms(); - cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; + long long result_analysis_time2 = get_cur_time_ms(); + cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; #endif - AttributionAnalysis = false; + AttributionAnalysis = false; - long long second_analysis_time = get_cur_time_ms(); + long long second_analysis_time = get_cur_time_ms(); - auto task_iter = TaskinPlayID.begin(); - for (int i = 0; i < curPlayTaskCount; i++) + auto task_iter = TaskinPlayID.begin(); + for (int i = 0; i < curPlayTaskCount; i++) + { + for (int j = 0; j < deleteObjectID[i].size(); j++) { - for (int j = 0; j < deleteObjectID[i].size(); j++) - { - OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; - m_snaphot_helper.SaveResultInFile(deleteObj); - } - - task_iter++; + OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; + m_snaphot_helper.SaveResultInFile(deleteObj); } - for (auto task_id: TaskinPlayID) { - cudaFree(tasks[task_id].task_algorithm_data.frame); - } - + task_iter++; + } - for (int i = 0; i < deleteObjectID.size(); i++) - vector().swap(deleteObjectID[i]); - vector>().swap(deleteObjectID); + for (auto task_id: TaskinPlayID) { + cudaFree(tasks[task_id].task_algorithm_data.frame); + tasks[task_id].task_algorithm_data.frame = nullptr; + } + - m_snaphot_helper.object_attri_analysis(); + for (int i = 0; i < deleteObjectID.size(); i++) + vector().swap(deleteObjectID[i]); + vector>().swap(deleteObjectID); + + m_snaphot_helper.object_attri_analysis(); + cudaError_t cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) { + LOG_ERROR("object_attri_analysis last error: {}", cudaGetErrorString(cudaStatus)); + } #ifdef LOG_INFO2 - long long second_analysis_time2 = get_cur_time_ms(); - cout << "second_analysis time_using:" << second_analysis_time2 - second_analysis_time << endl; + long long second_analysis_time2 = get_cur_time_ms(); + cout << "second_analysis time_using:" << second_analysis_time2 - second_analysis_time << endl; #endif - - cudaError_t cudaStatus = cudaGetLastError(); - if (cudaStatus != cudaSuccess) { - LOG_ERROR("object_attri_analysis last error: {}", cudaGetErrorString(cudaStatus)); - } - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - - ++total_count; - ++ncount; + ++total_count; + ++ncount; #ifdef LOG_INFO2 - last_time = get_cur_time_ms(); - cout << "process time_using:" << last_time - gather_data_time << endl; - cout << endl; + last_time = get_cur_time_ms(); + cout << "process time_using:" << last_time - gather_data_time << endl; + cout << endl; #endif - } } - //catch (exception &e) - { - //os << 51 << e.what()<< std::endl; - /* std::cout << e.what() << std::endl; - exit(-1);*/ - } - long long costTime1 = get_cur_time_ms() - begintime1; - LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times); m_snaphot_helper.clearSnapshotInfo(); - ProcessFlag = false; - if (batch_img != NULL) - { - delete[] batch_img; - batch_img = NULL; - } - - cuCtxPopCurrent(nullptr); - cuCtxDestroy(context); + long long costTime1 = get_cur_time_ms() - begintime1; + LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times); } 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 97bb8d3..c61d3e5 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,24 +136,17 @@ public: void algorthim_process(); private: - //bool ChangeTask; - //HANDLE handle_process; std::thread ProcessThread; std::mutex _tx_add_task; - - //DWORD dwThreadID; deque TaskOperatorQ; int capacity; - - //cv::Mat objSnapshot; double gpu_total_memory; std::thread thrd; void* authority_handle; public: /*��������Ӧ����public�� �������̺߳����л��õ����µ����� ÿ����дһ��get����̫������*/ - //fstream fout[THREAD_COUNT]; //���������� void * VPT_Handle; int section_batch_size; int licence_status; @@ -165,19 +158,8 @@ public: /*��������Ӧ����public�� ������ int TaskinPlay; int TotalTask; set TaskinPlayID; -// float* pDataToVPT; - vector VPTResult; - std::atomic ProcessFlag; - bool SourceFlag; - //float* imgDataHost; - //float* snapshotDataHost; - unsigned char* imgDataDecive; - // void * FrameTemp; - char* mModeSnapshotVideo; - char* mModeSnapshotLittle; - int viewTaskID; - map> objDelete; + int viewTaskID; FINISH_CALLBACK taskFinishCallbackFunc; OBJECT_INFO_CALLBACK taskObjInfoCallbackFunc; diff --git a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/CropImg.cu b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/CropImg.cu index 6c8326b..72c24c8 100644 --- a/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/CropImg.cu +++ b/vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/CropImg.cu @@ -170,6 +170,17 @@ namespace cudacommon { dim3 grid((dst_width + (block.x - 1)) / block.x, (dst_height + (block.y - 1)) / block.y, 1); //kernel_bilinear << < grid, block >> >(d_srcRGB_original, d_dstRGB_original, src_width, src_height, dst_width, dst_height); ResizeImgBilinearBGR_CUDAKernel << < grid, block >> > (d_srcRGB, d_dstRGB, src_width, src_height, dst_width, dst_height); + + cudaError_t cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) { + printf("ResizeImgBilinearBGR_CUDAKernel launch failed: %s\n", cudaGetErrorString(cudaStatus)); + } + + cudaStatus = cudaDeviceSynchronize(); + if (cudaStatus != cudaSuccess) { + printf("cudaDeviceSynchronize returned error code %d after launching CropImgGpu!\n", cudaStatus); + } + return; } @@ -180,6 +191,16 @@ namespace cudacommon { dim3 block(32, 16, 1); dim3 grid((dst_width + (block.x - 1)) / block.x, (dst_height + (block.y - 1)) / block.y, 1); ResizeImgBilinearBGR_uint8 << < grid, block >> > (d_srcRGB, d_dstRGB, src_width, src_height, dst_width, dst_height); + + cudaError_t cudaStatus = cudaGetLastError(); + if (cudaStatus != cudaSuccess) { + printf("ResizeImgBilinearBGR_CUDAKernel launch failed: %s\n", cudaGetErrorString(cudaStatus)); + } + + cudaStatus = cudaDeviceSynchronize(); + if (cudaStatus != cudaSuccess) { + printf("cudaDeviceSynchronize returned error code %d after launching CropImgGpu!\n", cudaStatus); + } return; } 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 3b068f7..6a23deb 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 @@ -325,7 +325,7 @@ void snapshot_helper::save_without_analysis(OBJ_KEY obj_key) iter->second.snapShotLittle.frame = NULL; snapShotInfo[obj_key].snapShotLittle.frame = NULL; } - snapShotInfo.erase(iter); + erase_snapshot_info(obj_key); } } @@ -557,7 +557,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(iter); + erase_snapshot_info(hp_keys[k]); } } @@ -637,13 +637,13 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 int count_bike_size = count_bike.size(); for (int c = 0; c < count_bike_size; c++) { - OBJ_KEY iter = count_bike.front(); + OBJ_KEY iter_bike = count_bike.front(); count_bike.pop(); - if (iter.videoID == hcp_keys[k].videoID && iter.objID == hcp_keys[k].objID) + if (iter_bike.videoID == hcp_keys[k].videoID && iter_bike.objID == hcp_keys[k].objID) continue; - count_bike.push(iter); + count_bike.push(iter_bike); } if (count_bike.size() == count_bike_size) //当前hp_keys[k] 不在count_person数组里 @@ -657,7 +657,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(iter); + erase_snapshot_info(hcp_keys[k]); } } @@ -746,7 +746,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(iter);//modified by dyq + erase_snapshot_info(det_vehicle_keys[vc_idx]);//modified by dyq } } @@ -841,7 +841,7 @@ void snapshot_helper::hp_analysis() cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(cur_obj_key); + erase_snapshot_info(cur_obj_key); } erase_snapshotImage(cur_obj_key); continue; @@ -866,9 +866,9 @@ void snapshot_helper::hp_analysis() //删除已经进行保存和二次属性分析的目标 int resIndex = 0; - for (auto iter_key : erase_obj_key) + for (auto obj_key : erase_obj_key) { - auto iter = snapShotInfo.find(iter_key); + auto iter = snapShotInfo.find(obj_key); //返回分析结果 hp_result curRes{}; @@ -879,13 +879,13 @@ void snapshot_helper::hp_analysis() memcpy(curRes.feature, result_f[resIndex].human_fea, sizeof(int8)* HF_FEA_SIZE); ++resIndex; - snapshot_res_callback(iter_key, &curRes); + snapshot_res_callback(obj_key, &curRes); if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(iter); + erase_snapshot_info(obj_key); } erase_obj_key.clear(); @@ -951,7 +951,7 @@ void snapshot_helper::hcp_analysis() cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(cur_obj_key); + erase_snapshot_info(cur_obj_key); } erase_snapshotImage(cur_obj_key); continue; @@ -973,9 +973,9 @@ void snapshot_helper::hcp_analysis() } int resIndex = 0; - for (auto iter_key : erase_obj_key) + for (auto obj_key : erase_obj_key) { - auto iter = snapShotInfo.find(iter_key); + auto iter = snapShotInfo.find(obj_key); hcp_result curRes{}; if (hcp_analysis_cf == SY_CONFIG_OPEN) memcpy(&curRes.res_objs, result[resIndex].res_objs, sizeof(classify_obj_res)* HCP_FIR_INDEX_SIZE); @@ -984,14 +984,14 @@ void snapshot_helper::hcp_analysis() memcpy(curRes.feature, result_f[resIndex].human_fea, sizeof(int8)* HCF_FEA_SIZE); resIndex++; - snapshot_res_callback(iter_key, &curRes); + snapshot_res_callback(obj_key, &curRes); if (iter->second.snapShotLittle.frame) { cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(iter); + erase_snapshot_info(obj_key); } erase_obj_key.clear(); @@ -1062,7 +1062,7 @@ bool snapshot_helper::vehicle_color_analysis() cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(cur_obj_key); + erase_snapshot_info(cur_obj_key); } count_vehicle_v.erase(count_vehicle_v.begin() + i); @@ -1141,7 +1141,7 @@ bool snapshot_helper::vehicle_plate_dr_analysis() cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(cur_obj_key); + erase_snapshot_info(cur_obj_key); } else printf("cant find\n"); @@ -1378,7 +1378,7 @@ bool snapshot_helper::vehicle_recg_analysis() cudaFree(iter->second.snapShotLittle.frame); iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(cur_obj_key); + erase_snapshot_info(cur_obj_key); } count_vehicle_v.erase(count_vehicle_v.begin() + i); @@ -1639,7 +1639,7 @@ bool snapshot_helper::vehicle_recg_analysis() iter->second.snapShotLittle.frame = NULL; } - snapShotInfo.erase(iter); + erase_snapshot_info(count_vehicle_v[c]); } count_vehicle_v.erase(count_vehicle_v.begin(), count_vehicle_v.begin() + cur_batchsize/*OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE*/); @@ -2030,7 +2030,6 @@ int snapshot_helper::SaveResultInFile(OBJ_KEY deleteObj) { save_without_analysis(obj_key); } - } else { @@ -2123,7 +2122,11 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas { cur_width = HCP_WIDTH; cur_height = HCP_HEIGHT; - LOG_DEBUG("task_id:{} obj_id:{} index = 0、1", newObj.videoID, newObj.objID); + + // if(5 == newObj.videoID) + { + LOG_DEBUG("task_id:{} obj_id:{} index = {}", newObj.videoID, newObj.objID, snapShotInfo[newObj].index.index ); + } } else if (8 == snapShotInfo[newObj].index.index || (snapShotInfo[newObj].index.index >= 4 && snapShotInfo[newObj].index.index <= 6)) { @@ -2198,8 +2201,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas 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), + 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; @@ -2221,7 +2223,6 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas 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) @@ -2243,6 +2244,10 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas } else if (1 == snapShotInfo[newObj].index.index || 2 == snapShotInfo[newObj].index.index) { + // if(5 == newObj.videoID) + { + 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) { cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存 @@ -2461,4 +2466,12 @@ void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count, void snapshot_helper::clearSnapshotInfo() { snapShotInfo.clear(); +} + +void snapshot_helper::erase_snapshot_info(OBJ_KEY& objKey){ + if (5 == objKey.videoID) { + LOG_DEBUG("task:{} objId: {}", objKey.videoID, objKey.objID); + } + + snapShotInfo.erase(objKey); } \ 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 7f081fc..3695732 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 @@ -212,6 +212,8 @@ private: //针对车拆开的二次属性分析 void VehicleRecog_Process(sy_img * batch_img, int batchsize, vr_result *&vresult, OBJ_KEY* obj_keys); + void erase_snapshot_info(OBJ_KEY& objKey); + private: HumanCarParsing m_human_car_parsing; HumanParsing m_human_parsing; 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 2b8463f..911a60e 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 @@ -783,12 +783,13 @@ int main(int argc, char* argv[]) total_index++ ; } - } while(0) ; + + } while(1) ; - printf("-------------------Begin rt_view_task 1 !----------------------\n"); - rt_view_task(handle, 0); + // printf("-------------------Begin rt_view_task 1 !----------------------\n"); + // rt_view_task(handle, 0); - while (getchar() == 'q'); + while (getchar() != 'q'); /* -- libgit2 0.21.4