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 9135c83..428aaff 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 @@ -132,7 +132,15 @@ static long long get_cur_time_ms(){ std::function show_gpu_img_func = show_gpu_image_; void check_thread(void* handle); -DWORD ThreadProcess(LPVOID param); + +static void algorthim_process_thread(void* arg) { + CMutliSourceVideoProcess* _this=(CMutliSourceVideoProcess*)arg; + if(_this != nullptr){ + _this->algorthim_process(); + } else { + LOG_ERROR("算法处理线程启动失败 !"); + } +} //std::ofstream g_os("./cudaMem.txt", std::ofstream::out | std::ofstream::trunc); @@ -140,57 +148,6 @@ CMutliSourceVideoProcess::CMutliSourceVideoProcess() { } -// dump�ļ� -//static LONG WINAPI CustomExceptionCrashHandler(_In_ EXCEPTION_POINTERS *CONST pException) -//{ -// char dumpPath[MAX_PATH]; -// -// BOOL tempDump = FALSE; -// do { -// -// if (0 == GetTempPath(_countof(dumpPath), dumpPath)) -// break; -// -// // %temp%Ŀ¼���½�dump�ļ��� -// if (!PathAppend(dumpPath, "dump")) -// break; -// CreateDirectory(dumpPath, NULL); -// // dump�ļ�����dump�ļ��ļ��� ���Զ����޸� -// if (!PathAppend(dumpPath, "HSTProcessor")) -// break; -// -// SYSTEMTIME lclTm; -// GetLocalTime(&lclTm); -// char ext[29]; -// // dump�ļ�������ʱ���� -// if (FAILED(StringCchPrintf(ext, _countof(ext), ".%04hu%02hu%02hu%02hu%02hu%02hu.unhdlexc.dmp", lclTm.wYear, lclTm.wMonth, lclTm.wDay, lclTm.wHour, lclTm.wMinute, lclTm.wSecond))) -// break; -// if (FAILED(StringCchCat(dumpPath, _countof(dumpPath), ext))) -// break; -// -// tempDump = TRUE; -// } while (FALSE); -// HANDLE CONST dumpFile = CreateFile(dumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); -// if (INVALID_HANDLE_VALUE == dumpPath) -// { -// return EXCEPTION_EXECUTE_HANDLER; -// } -// -// MINIDUMP_EXCEPTION_INFORMATION dumpInfo; -// dumpInfo.ThreadId = GetCurrentThreadId(); -// dumpInfo.ExceptionPointers = pException; -// dumpInfo.ClientPointers = TRUE; -// -// if (FAILED(MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL))) -// { -// CloseHandle(dumpFile); -// } -// CloseHandle(dumpFile); -// -// return EXCEPTION_EXECUTE_HANDLER; -//} - - CMutliSourceVideoProcess::~CMutliSourceVideoProcess() { //��־����ʼ�� @@ -345,7 +302,7 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN 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_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); if (ret == SUCCESS) //�ɹ� { licence_status = 0; @@ -634,12 +591,13 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh if (!ProcessFlag) { m_bProcessExit = false; - ProcessThread = std::thread(ThreadProcess, this); + ProcessThread = std::thread(algorthim_process_thread, this); ProcessFlag = true; } - - printf("-----------------------add task: %d-----------------------\n", tasks.size() - 1); + AddTaskSucFlag = 1; + + LOG_INFO("add task: {}", new_task.taskID); return true; } @@ -766,61 +724,6 @@ void CMutliSourceVideoProcess::OperatorTask() } } - -int CMutliSourceVideoProcess::SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value) -{ - if (0 == obj_value.index.index && obj_value.snapShotLittle.width == HP_WIDTH && obj_value.snapShotLittle.height == HP_HEIGHT) - { - if (m_face_det_config == SY_CONFIG_OPEN) - { - m_snaphot_helper.save_face_snapshot(obj_key); - } - - if (m_hp_analysis_config == SY_CONFIG_OPEN || m_hf_recg_config == SY_CONFIG_OPEN) - { - m_snaphot_helper.save_snapshot(obj_key); - m_snaphot_helper.hp_analysis(obj_key); - } - else - { - m_snaphot_helper.save_without_analysis(obj_key); - } - } - else if ((1 == obj_value.index.index || 2 == obj_value.index.index) && obj_value.snapShotLittle.width == HCP_WIDTH && obj_value.snapShotLittle.height == HCP_HEIGHT) - { - if (m_hcp_analysis_config == SY_CONFIG_OPEN || m_hcf_recg_config == SY_CONFIG_OPEN) - { - m_snaphot_helper.save_snapshot(obj_key); - m_snaphot_helper.hcp_analysis(obj_key); - } - else - { - m_snaphot_helper.save_without_analysis(obj_key); - } - } - else if ((8 == obj_value.index.index || (obj_value.index.index >= 4 && obj_value.index.index <= 6)) && obj_value.snapShotLittle.width == VEHICLE_WIDTH && obj_value.snapShotLittle.height == VEHICLE_HEIGHT) - { - //VEHICLEAnalysis(obj_key, obj_value); - if (m_vehicle_analysis_config == SY_CONFIG_OPEN || m_vcf_recg_config == SY_CONFIG_OPEN) - { - m_snaphot_helper.save_snapshot(obj_key); - m_snaphot_helper.vehicle_analysis(obj_key); - } - else - { - m_snaphot_helper.save_without_analysis(obj_key); - } - - } - else - { - m_snaphot_helper.save_without_analysis(obj_key); - } - - return 0; -} - - //#define LOG_INFO void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_ObjInfo *obj, int taskFrameCount, int taskId) { @@ -866,7 +769,7 @@ void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(int objCount, VPT_Obj } } -DWORD ThreadProcess(LPVOID param) +void CMutliSourceVideoProcess::algorthim_process() { set k; int count = 0; @@ -874,12 +777,10 @@ DWORD ThreadProcess(LPVOID param) DxGPUFrame frame = {}; - CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)param; - - cudaSetDevice(pThreadParam->mgpuid); + cudaSetDevice(mgpuid); CUdevice cuDevice; - cuDeviceGet(&cuDevice, pThreadParam->mgpuid); + cuDeviceGet(&cuDevice, mgpuid); CUcontext context; cuCtxCreate(&context, 0, cuDevice); cuCtxPushCurrent(context); @@ -892,9 +793,9 @@ DWORD ThreadProcess(LPVOID param) long long last_time = get_cur_time_ms(); { - while (!pThreadParam->m_bProcessExit) + while (!m_bProcessExit) { - if (pThreadParam->licence_status <= -3) + if (licence_status <= -3) { printf("authority failed!\n"); break; @@ -902,24 +803,23 @@ DWORD ThreadProcess(LPVOID param) double time_val, time_val_p = 0; { - std::lock_guard l(pThreadParam->taskMutex); - pThreadParam->OperatorTask(); + std::lock_guard l(taskMutex); + OperatorTask(); } - pThreadParam->taskCondVar.notify_all(); + taskCondVar.notify_all(); - int curTaskSize = pThreadParam->tasks.size(); + int curTaskSize = tasks.size(); count = 0; static int ncount = 0; map> finishTaskDeleteObj; int curPlayTaskCount = 0; - //�жϵ�ǰPLAY����Ľ���״̬��������ڽ����쳣��·������������·���� for (int i = 0; i < curTaskSize; i++) { - if ((pThreadParam->tasks[i].taskState == PLAY || pThreadParam->tasks[i].taskState == DECODEERROR)) + if ((tasks[i].taskState == PLAY || tasks[i].taskState == DECODEERROR)) { - if (!pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) + if (!tasks[i].taskTcuvid->DxDecoderIsRun()) { cudaError_t cudaStatus = cudaGetLastError(); if (cudaStatus != cudaSuccess) { @@ -927,18 +827,18 @@ DWORD ThreadProcess(LPVOID param) } cout << "***************** Task " << i << " is Finished *****************" << endl; - pThreadParam->tasks[i].taskState = FINISH; + tasks[i].taskState = FINISH; - pThreadParam->FinishTask(pThreadParam->tasks[i].taskID); + FinishTask(tasks[i].taskID); - pThreadParam->tasks[i].taskTcuvid->DxCloseDecoder(); - delete pThreadParam->tasks[i].taskTcuvid; - pThreadParam->tasks[i].taskTcuvid = NULL; - int taskid = pThreadParam->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(pThreadParam->m_snaphot_helper.analysisThreadMutex); - while (std::find_if(pThreadParam->m_snaphot_helper.finished_analysis_ss_info.begin(), pThreadParam->m_snaphot_helper.finished_analysis_ss_info.end(), [&taskid](const std::pair & item) ->bool { + 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; @@ -948,7 +848,7 @@ DWORD ThreadProcess(LPVOID param) return false; } - }) != pThreadParam->m_snaphot_helper.finished_analysis_ss_info.end()) + }) != m_snaphot_helper.finished_analysis_ss_info.end()) { lock.unlock(); std::this_thread::yield(); @@ -957,27 +857,27 @@ DWORD ThreadProcess(LPVOID param) } //�ص�֪ͨ�û� ��·����������� - if (pThreadParam->taskFinishCallbackFunc != nullptr) + if (taskFinishCallbackFunc != nullptr) { - std::lock_guard l(pThreadParam->m_snaphot_helper.callback_tx); - pThreadParam->taskFinishCallbackFunc(pThreadParam->tasks[i].taskID); + std::lock_guard l(m_snaphot_helper.callback_tx); + taskFinishCallbackFunc(tasks[i].taskID); } - pThreadParam->TaskinPlay--; + TaskinPlay--; } } - if (pThreadParam->tasks[i].taskState == FINISH) + if (tasks[i].taskState == FINISH) count++; } //�������������FINISH״̬ - if (count >= pThreadParam->tasks.size()) //have no decode video, break + if (count >= tasks.size()) //have no decode video, break { { - std::lock_guard l(pThreadParam->taskMutex); + std::lock_guard l(taskMutex); //�ж���������ȴ������Ƿ����µ��������� - if (pThreadParam->HasNewTask()) + if (HasNewTask()) { continue; } @@ -991,38 +891,38 @@ DWORD ThreadProcess(LPVOID param) //continue; //printf("0708\n"); - //pThreadParam->ProcessFlag = false; + //ProcessFlag = false; break; } } } //��ǰû��PLAY������ ѭ���ȴ� - curPlayTaskCount = pThreadParam->TaskinPlay; + curPlayTaskCount = TaskinPlay; if (curPlayTaskCount <= 0) { Sleep(30); continue; } k.clear(); - pThreadParam->TaskinPlayID.clear(); + TaskinPlayID.clear(); //��ȡ�������� getdata_flag: for (int i = 0; i < curTaskSize; i++) { - if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) + if (k.find(i) == k.end() && tasks[i].taskState == PLAY && tasks[i].taskTcuvid->DxDecoderIsRun()) { - if(pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&pThreadParam->tasks[i].task_algorithm_data) == 0) { + if(tasks[i].taskTcuvid->DxLockFrame(&tasks[i].task_algorithm_data) == 0) { k.insert(i); - pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); + TaskinPlayID.insert(tasks[i].taskID); } } - else if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && !pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) + else if (k.find(i) == k.end() && tasks[i].taskState == PLAY && !tasks[i].taskTcuvid->DxDecoderIsRun()) { - pThreadParam->tasks[i].taskState = DECODEERROR; + tasks[i].taskState = DECODEERROR; curPlayTaskCount--; - FinishTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID); + FinishTaskTracker(VPT_Handle, tasks[i].taskID); } } @@ -1053,19 +953,19 @@ DWORD ThreadProcess(LPVOID param) ///////////////////////////////////////////////////////////// vector> deleteObjectID; - set::iterator iter = pThreadParam->TaskinPlayID.begin(); + set::iterator iter = TaskinPlayID.begin(); int cur_batch_size = 0; - cur_batch_size = pThreadParam->section_batch_size; + cur_batch_size = section_batch_size; if (0) { - if (pThreadParam->section_batch_size == 20) - cur_batch_size = pThreadParam->section_batch_size; + if (section_batch_size == 20) + cur_batch_size = section_batch_size; else { - if (curPlayTaskCount <= 2 * pThreadParam->section_batch_size) - cur_batch_size = pThreadParam->section_batch_size; + if (curPlayTaskCount <= 2 * section_batch_size) + cur_batch_size = section_batch_size; else if (curPlayTaskCount >= 2 * MAX_BATCH) cur_batch_size = MAX_BATCH; else @@ -1077,7 +977,7 @@ DWORD ThreadProcess(LPVOID param) vector> unUsedResult; vector vec_frameIndex; - unUsedResult.resize(pThreadParam->VPTResult.size()); + unUsedResult.resize(VPTResult.size()); int cycleTimes = curPlayTaskCount / cur_batch_size + (curPlayTaskCount % cur_batch_size == 0 ? 0 : 1); for (int c = 0; c < cycleTimes; c++) { @@ -1087,7 +987,7 @@ DWORD ThreadProcess(LPVOID param) vec_frameIndex.clear(); for (int i = 0; i < batchsize; i++) { - DxGPUFrame task_algorithm_data = pThreadParam->tasks[*iter].task_algorithm_data; + 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; @@ -1099,7 +999,7 @@ DWORD ThreadProcess(LPVOID param) vector> tempDeleteObjectID; tempDeleteObjectID.resize(batchsize); - int flag = VPT_Process_GPU(pThreadParam->GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, pThreadParam->VPTResult, tempDeleteObjectID, unUsedResult); + int flag = VPT_Process_GPU(GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, VPTResult, tempDeleteObjectID, unUsedResult); process_times++ ; for (auto iter : tempDeleteObjectID) @@ -1114,89 +1014,89 @@ DWORD ThreadProcess(LPVOID param) long long result_analysis_time = get_cur_time_ms(); - iter = pThreadParam->TaskinPlayID.begin(); + iter = TaskinPlayID.begin(); for (int i = 0; i < curPlayTaskCount; i++) { - pThreadParam->tasks[*iter].taskFrameCount = pThreadParam->tasks[*iter].task_algorithm_data.timestamp; + tasks[*iter].taskFrameCount = tasks[*iter].task_algorithm_data.timestamp; //若该路任务当前帧未检测到目标,返回ID为-1的目标表明未检测到目标 - if (pThreadParam->VPTResult[i].objCount == 0) + if (VPTResult[i].objCount == 0) { - pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskFrameCount, *iter); + callTaskObjInfoCallbackFunc(0, nullptr, tasks[*iter].taskFrameCount, *iter); } //实时查看模块,若存在实时查看,把当前视频画面cp回内存 bool view = false; - int frameHeight = pThreadParam->tasks[*iter].task_algorithm_data.height; - int frameWidth = pThreadParam->tasks[*iter].task_algorithm_data.width; + int frameHeight = tasks[*iter].task_algorithm_data.height; + int frameWidth = tasks[*iter].task_algorithm_data.width; - if (*iter == pThreadParam->viewTaskID) + if (*iter == viewTaskID) { - cudaMemcpy(pThreadParam->tasks[*iter].frameImage.data, pThreadParam->tasks[*iter].task_algorithm_data.frame, 3 * pThreadParam->tasks[*iter].task_algorithm_data.width * pThreadParam->tasks[*iter].task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); + cudaMemcpy(tasks[*iter].frameImage.data, tasks[*iter].task_algorithm_data.frame, 3 * tasks[*iter].task_algorithm_data.width * tasks[*iter].task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); view = true; } //跟踪帧也需要返回跟踪的结果 - if (pThreadParam->tasks[*iter].taskLastFrameCount > 0) + if (tasks[*iter].taskLastFrameCount > 0) { vector OneUnUsedResult = unUsedResult[i]; if (OneUnUsedResult.size() == 0) { - pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskLastFrameCount + 1, *iter); + callTaskObjInfoCallbackFunc(0, nullptr, tasks[*iter].taskLastFrameCount + 1, *iter); } for (int k = 0; k < OneUnUsedResult.size(); ++k) { if (OneUnUsedResult[k].objCount == 0) { - pThreadParam->callTaskObjInfoCallbackFunc(0, nullptr, pThreadParam->tasks[*iter].taskLastFrameCount + k + 1, *iter); + callTaskObjInfoCallbackFunc(0, nullptr, tasks[*iter].taskLastFrameCount + k + 1, *iter); } else { //cout << "OneUnUsedResult.size = " << OneUnUsedResult.size() << " k=" << k << " OneUnUsedResult[k].objCount = " << OneUnUsedResult[k].objCount << endl; - pThreadParam->callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, pThreadParam->tasks[*iter].taskLastFrameCount + k + 1, *iter); + callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, tasks[*iter].taskLastFrameCount + k + 1, *iter); } } } - pThreadParam->tasks[*iter].taskLastFrameCount = pThreadParam->tasks[*iter].taskFrameCount; + tasks[*iter].taskLastFrameCount = tasks[*iter].taskFrameCount; - unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{};// = new unsigned char*[pThreadParam->VPTResult[i].objCount]; - int snapshot_left[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_right[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_top[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_bottom[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_dst_width[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; - int snapshot_dst_height[MAX_OBJ_COUNT]{};// = new int[pThreadParam->VPTResult[i].objCount]; + 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; - pThreadParam->callTaskObjInfoCallbackFunc(pThreadParam->VPTResult[i].objCount, pThreadParam->VPTResult[i].obj, pThreadParam->tasks[*iter].taskFrameCount, *iter); - for (int c = 0; c < pThreadParam->VPTResult[i].objCount; c++) + callTaskObjInfoCallbackFunc(VPTResult[i].objCount, VPTResult[i].obj, tasks[*iter].taskFrameCount, *iter); + for (int c = 0; c < VPTResult[i].objCount; c++) { - OBJ_KEY newObj = { (*iter), pThreadParam->VPTResult[i].obj[c].id }; + OBJ_KEY newObj = { (*iter), VPTResult[i].obj[c].id }; int index = 0; - if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) - index = pThreadParam->VPTResult[i].obj[c].index; + if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) + index = VPTResult[i].obj[c].index; else - index = pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index; + index = m_snaphot_helper.snapShotInfo[newObj].index.index; //实时查看模块 绘制目标框到画面上 if (view) { //cout << "---- vew ---- "; - int p1 = pThreadParam->VPTResult[i].obj[c].left - 10 > 0 ? pThreadParam->VPTResult[i].obj[c].left - 10 : 0; - int p2 = pThreadParam->VPTResult[i].obj[c].top - 15 > 0 ? pThreadParam->VPTResult[i].obj[c].top - 15 : 0; + 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(pThreadParam->tasks[*iter].frameImage, Rect(pThreadParam->VPTResult[i].obj[c].left, pThreadParam->VPTResult[i].obj[c].top, - pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left, - pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top), Scalar(158, 52, 254), 3, 1, 0); + cv::rectangle(tasks[*iter].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(pThreadParam->tasks[*iter].frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); + putTextZH(tasks[*iter].frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); #else - string resss = "" + to_string(pThreadParam->VPTResult[i].obj[c].id) + " " + ObjTypesEnglish[pThreadParam->VPTResult[i].obj[c].index]; - cv::putText(pThreadParam->tasks[*iter].frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); + string resss = "" + to_string(VPTResult[i].obj[c].id) + " " + ObjTypesEnglish[VPTResult[i].obj[c].index]; + cv::putText(tasks[*iter].frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); #endif } @@ -1204,54 +1104,54 @@ DWORD ThreadProcess(LPVOID param) int boundary = 10; int boundaryLittle = 4; - int cur_real_width = (pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left); - int cur_real_height = (pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top); - int cur_real_index = pThreadParam->VPTResult[i].obj[c].index; + int cur_real_width = (VPTResult[i].obj[c].right - VPTResult[i].obj[c].left); + int cur_real_height = (VPTResult[i].obj[c].bottom - VPTResult[i].obj[c].top); + int cur_real_index = VPTResult[i].obj[c].index; //第一次添加快照 - if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) + if (m_snaphot_helper.snapShotInfo.find(newObj) == m_snaphot_helper.snapShotInfo.end()) { //DxAppendLog(DxLOG_INFO, "30"); - if (LegalMinArea(cur_real_width, cur_real_height, pThreadParam->tasks[*iter].task_min_boxsize[cur_real_index])) + if (LegalMinArea(cur_real_width, cur_real_height, tasks[*iter].task_min_boxsize[cur_real_index])) { //DxAppendLog(DxLOG_INFO, "31"); //--------------------- 保存快照视频截图 -----------------------------// - int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left - boundaryLittle)); - int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top - boundaryLittle)); - int right = min({ frameWidth - 1, (int)(pThreadParam->VPTResult[i].obj[c].right + boundaryLittle) }); - int bottom = min({ frameHeight - 1, (int)(pThreadParam->VPTResult[i].obj[c].bottom + boundaryLittle) }); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].frameCount = pThreadParam->tasks[*iter].taskFrameCount; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].isupdate = true; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lost = 0; + int left = max(0, (int)(VPTResult[i].obj[c].left - boundaryLittle)); + int top = max(0, (int)(VPTResult[i].obj[c].top - boundaryLittle)); + int right = min({ frameWidth - 1, (int)(VPTResult[i].obj[c].right + boundaryLittle) }); + int bottom = min({ frameHeight - 1, (int)(VPTResult[i].obj[c].bottom + boundaryLittle) }); + m_snaphot_helper.snapShotInfo[newObj].frameCount = tasks[*iter].taskFrameCount; + m_snaphot_helper.snapShotInfo[newObj].isupdate = true; + m_snaphot_helper.snapShotInfo[newObj].lost = 0; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index = pThreadParam->VPTResult[i].obj[c].index; + m_snaphot_helper.snapShotInfo[newObj].index.count++; + m_snaphot_helper.snapShotInfo[newObj].index.index = VPTResult[i].obj[c].index; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->VPTResult[i].obj[c].confidence; + m_snaphot_helper.snapShotInfo[newObj].confidence = VPTResult[i].obj[c].confidence; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left = left; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top = top; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right = right; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); + m_snaphot_helper.snapShotInfo[newObj].box.left = left; + m_snaphot_helper.snapShotInfo[newObj].box.top = top; + m_snaphot_helper.snapShotInfo[newObj].box.right = right; + m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; + m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[0] = left < minDistance[0] + SCALE_OUT ? 0 : 1; //left - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[1] = top < minDistance[1] + SCALE_OUT ? 0 : 1; //top - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[2] = right > frameWidth - minDistance[2] - SCALE_OUT ? 0 : 1; //right - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags[3] = bottom > frameHeight - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom + m_snaphot_helper.snapShotInfo[newObj].flags[0] = left < minDistance[0] + SCALE_OUT ? 0 : 1; //left + m_snaphot_helper.snapShotInfo[newObj].flags[1] = top < minDistance[1] + SCALE_OUT ? 0 : 1; //top + m_snaphot_helper.snapShotInfo[newObj].flags[2] = right > frameWidth - minDistance[2] - SCALE_OUT ? 0 : 1; //right + m_snaphot_helper.snapShotInfo[newObj].flags[3] = bottom > frameHeight - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame = NULL; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.frame = NULL; + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame = NULL; + m_snaphot_helper.snapShotInfo[newObj].snapShot.frame = NULL; - if (pThreadParam->tasks[*iter].folderName != NULL) + if (tasks[*iter].folderName != NULL) { //DxAppendLog(DxLOG_INFO, "32"); - FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; - pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); + FRAME_KEY frame_id = { (*iter),tasks[*iter].taskFrameCount }; + m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, tasks[*iter].task_algorithm_data); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.height = frameHeight; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.width = frameWidth; + m_snaphot_helper.snapShotInfo[newObj].snapShot.height = frameHeight; + m_snaphot_helper.snapShotInfo[newObj].snapShot.width = frameWidth; } @@ -1261,18 +1161,18 @@ DWORD ThreadProcess(LPVOID param) int vRight = 0; int vBottom = 0; - vLeft = max(0, pThreadParam->VPTResult[i].obj[c].left - boundary); - vTop = max(0, pThreadParam->VPTResult[i].obj[c].top - boundary); - vRight = min({ frameWidth - 1, pThreadParam->VPTResult[i].obj[c].right + boundary }); - vBottom = min({ frameHeight - 1, pThreadParam->VPTResult[i].obj[c].bottom + boundary }); + vLeft = max(0, VPTResult[i].obj[c].left - boundary); + vTop = max(0, VPTResult[i].obj[c].top - boundary); + vRight = min({ frameWidth - 1, VPTResult[i].obj[c].right + boundary }); + vBottom = min({ frameHeight - 1, VPTResult[i].obj[c].bottom + boundary }); //DxAppendLog(DxLOG_INFO, "34"); - if (pThreadParam->tasks[*iter].folderNameLittle != NULL) + if (tasks[*iter].folderNameLittle != NULL) { //DxAppendLog(DxLOG_INFO, "35"); int cur_width = 0; int cur_height = 0; - if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + if (0 == m_snaphot_helper.snapShotInfo[newObj].index.index) { cur_width = HP_WIDTH; cur_height = HP_HEIGHT; @@ -1280,12 +1180,12 @@ DWORD ThreadProcess(LPVOID param) human_idx.emplace_back(copy_obj_count); human_obj_keys.emplace_back (newObj); } - else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + else if (1 == m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == m_snaphot_helper.snapShotInfo[newObj].index.index) { cur_width = HCP_WIDTH; cur_height = HCP_HEIGHT; } - else if (8 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index <= 6)) + else if (8 == m_snaphot_helper.snapShotInfo[newObj].index.index || (m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && m_snaphot_helper.snapShotInfo[newObj].index.index <= 6)) { cur_width = VEHICLE_WIDTH; cur_height = VEHICLE_HEIGHT; @@ -1298,11 +1198,11 @@ DWORD ThreadProcess(LPVOID param) if (cur_width != 0 && cur_height != 0) { - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, IMG_CHANNELS * cur_width * cur_height * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = cur_height; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = cur_width; + cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, IMG_CHANNELS * cur_width * cur_height * sizeof(unsigned char)); + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = cur_height; + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = cur_width; - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; + snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; snapshot_left[copy_obj_count] = vLeft; snapshot_top[copy_obj_count] = vTop; snapshot_right[copy_obj_count] = vRight; @@ -1318,59 +1218,59 @@ DWORD ThreadProcess(LPVOID param) { //DxAppendLog(DxLOG_INFO, "36"); bool updateShotInfo = false; - int oldIndex = pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].frameCount = pThreadParam->tasks[*iter].taskFrameCount; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].isupdate = true; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lost = 0; + int oldIndex = m_snaphot_helper.snapShotInfo[newObj].index.index; + m_snaphot_helper.snapShotInfo[newObj].frameCount = tasks[*iter].taskFrameCount; + m_snaphot_helper.snapShotInfo[newObj].isupdate = true; + m_snaphot_helper.snapShotInfo[newObj].lost = 0; - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count == 0) + if (m_snaphot_helper.snapShotInfo[newObj].index.count == 0) { - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index = pThreadParam->VPTResult[i].obj[c].index; + m_snaphot_helper.snapShotInfo[newObj].index.count++; + m_snaphot_helper.snapShotInfo[newObj].index.index = VPTResult[i].obj[c].index; } else { - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index == pThreadParam->VPTResult[i].obj[c].index) - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; + if (m_snaphot_helper.snapShotInfo[newObj].index.index == VPTResult[i].obj[c].index) + m_snaphot_helper.snapShotInfo[newObj].index.count++; else - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count--; + m_snaphot_helper.snapShotInfo[newObj].index.count--; } - if (oldIndex != pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + if (oldIndex != m_snaphot_helper.snapShotInfo[newObj].index.index) { updateShotInfo = true; } - int left = max(0, (int)(pThreadParam->VPTResult[i].obj[c].left - boundaryLittle)); - int top = max(0, (int)(pThreadParam->VPTResult[i].obj[c].top - boundaryLittle)); - int right = min(frameWidth - 1, (int)(pThreadParam->VPTResult[i].obj[c].right + boundaryLittle)); - int bottom = min(frameHeight - 1, (int)(pThreadParam->VPTResult[i].obj[c].bottom + boundaryLittle)); + int left = max(0, (int)(VPTResult[i].obj[c].left - boundaryLittle)); + int top = max(0, (int)(VPTResult[i].obj[c].top - boundaryLittle)); + int right = min(frameWidth - 1, (int)(VPTResult[i].obj[c].right + boundaryLittle)); + int bottom = min(frameHeight - 1, (int)(VPTResult[i].obj[c].bottom + boundaryLittle)); - int maxArea = (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left)*(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top); + int maxArea = (m_snaphot_helper.snapShotInfo[newObj].box.right - m_snaphot_helper.snapShotInfo[newObj].box.left)*(m_snaphot_helper.snapShotInfo[newObj].box.bottom - m_snaphot_helper.snapShotInfo[newObj].box.top); - if ((LegalArea(maxArea, pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea, left, top, right, bottom) - && LegalPos(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].flags, left, top, right, bottom, frameHeight, frameWidth) - && LegalMinArea(cur_real_width, cur_real_height, pThreadParam->tasks[*iter].task_min_boxsize[cur_real_index])) || updateShotInfo) + if ((LegalArea(maxArea, m_snaphot_helper.snapShotInfo[newObj].lastArea, left, top, right, bottom) + && LegalPos(m_snaphot_helper.snapShotInfo[newObj].flags, left, top, right, bottom, frameHeight, frameWidth) + && LegalMinArea(cur_real_width, cur_real_height, tasks[*iter].task_min_boxsize[cur_real_index])) || updateShotInfo) { //DxAppendLog(DxLOG_INFO, "37"); - int boundary_w = (pThreadParam->VPTResult[i].obj[c].right - pThreadParam->VPTResult[i].obj[c].left) * 0.1; - int boundary_h = (pThreadParam->VPTResult[i].obj[c].bottom - pThreadParam->VPTResult[i].obj[c].top)* 0.1; + int boundary_w = (VPTResult[i].obj[c].right - VPTResult[i].obj[c].left) * 0.1; + int boundary_h = (VPTResult[i].obj[c].bottom - VPTResult[i].obj[c].top)* 0.1; int boundary_left = boundary_w, boundary_right = boundary_w, boundary_top = boundary_h, boundary_bottom = boundary_h; - ExpandMargin((left - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left), - (bottom - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom), + ExpandMargin((left - m_snaphot_helper.snapShotInfo[newObj].box.left), + (bottom - m_snaphot_helper.snapShotInfo[newObj].box.bottom), boundary_w, boundary_h, boundary_left, boundary_right, boundary_top, boundary_bottom); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.left = left; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.top = top; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.right = right; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; + m_snaphot_helper.snapShotInfo[newObj].box.left = left; + m_snaphot_helper.snapShotInfo[newObj].box.top = top; + m_snaphot_helper.snapShotInfo[newObj].box.right = right; + m_snaphot_helper.snapShotInfo[newObj].box.bottom = bottom; //printf("ori: %d %d %d %d\n", left, top, right - left, bottom - top); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->VPTResult[i].obj[c].confidence; - if (pThreadParam->tasks[*iter].folderName != NULL) + m_snaphot_helper.snapShotInfo[newObj].confidence = VPTResult[i].obj[c].confidence; + if (tasks[*iter].folderName != NULL) { - FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; - pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); + FRAME_KEY frame_id = { (*iter),tasks[*iter].taskFrameCount }; + m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, tasks[*iter].task_algorithm_data); } @@ -1380,27 +1280,27 @@ DWORD ThreadProcess(LPVOID param) int vRight = 0; int vBottom = 0; - vLeft = max(0, pThreadParam->VPTResult[i].obj[c].left - boundary_left); - vTop = max(0, pThreadParam->VPTResult[i].obj[c].top - boundary_top); - vRight = min(frameWidth - 1, pThreadParam->VPTResult[i].obj[c].right + boundary_right); - vBottom = min(frameHeight - 1, pThreadParam->VPTResult[i].obj[c].bottom + boundary_bottom); - if (pThreadParam->tasks[*iter].folderNameLittle != NULL) + vLeft = max(0, VPTResult[i].obj[c].left - boundary_left); + vTop = max(0, VPTResult[i].obj[c].top - boundary_top); + vRight = min(frameWidth - 1, VPTResult[i].obj[c].right + boundary_right); + vBottom = min(frameHeight - 1, VPTResult[i].obj[c].bottom + boundary_bottom); + if (tasks[*iter].folderNameLittle != NULL) { - if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + if (0 == m_snaphot_helper.snapShotInfo[newObj].index.index) { - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) + if (m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) { - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT; + cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char)); + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH; + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT; } human_idx.push_back(copy_obj_count); human_obj_keys.emplace_back(newObj); - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; + snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; snapshot_left[copy_obj_count] = vLeft; snapshot_top[copy_obj_count] = vTop; snapshot_right[copy_obj_count] = vRight; @@ -1410,19 +1310,19 @@ DWORD ThreadProcess(LPVOID param) snapshot_dst_height[copy_obj_count++] = HP_HEIGHT; } - else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) + else if (1 == m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == m_snaphot_helper.snapShotInfo[newObj].index.index) { //DxAppendLog(DxLOG_INFO, "42"); - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) + if (m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) { //DxAppendLog(DxLOG_INFO, "43"); - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT; + cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char)); + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH; + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT; } - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; + snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; snapshot_left[copy_obj_count] = vLeft; snapshot_top[copy_obj_count] = vTop; snapshot_right[copy_obj_count] = vRight; @@ -1432,19 +1332,19 @@ DWORD ThreadProcess(LPVOID param) snapshot_dst_height[copy_obj_count++] = HCP_HEIGHT; } - else if (8 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index <= 6)) + else if (8 == m_snaphot_helper.snapShotInfo[newObj].index.index || (m_snaphot_helper.snapShotInfo[newObj].index.index >= 4 && m_snaphot_helper.snapShotInfo[newObj].index.index <= 6)) { //DxAppendLog(DxLOG_INFO, "43.1"); - if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT) + if (m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT) { //DxAppendLog(DxLOG_INFO, "44"); - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = VEHICLE_HEIGHT; + cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char)); + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH; + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = VEHICLE_HEIGHT; } - snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; + snapshot_image_data[copy_obj_count] = (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; snapshot_left[copy_obj_count] = vLeft; snapshot_top[copy_obj_count] = vTop; snapshot_right[copy_obj_count] = vRight; @@ -1462,20 +1362,20 @@ DWORD ThreadProcess(LPVOID param) int cur_height = vBottom - vTop; if (cur_width != 0 && cur_height != 0) { //---------------------------------------- - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 - cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char)); - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = vBottom - vTop; - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = vRight - vLeft; + cudaFree(m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 + cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char)); + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = vBottom - vTop; + m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = vRight - vLeft; //printf("begin partMemCopy: %d %d %d %d %d %d\n", vLeft, vTop, vRight, vBottom, frameWidth, frameHeight); - partMemCopy((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, - (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom); + partMemCopy((unsigned char*)tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, + (unsigned char*)m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, vLeft, vTop, vRight, vBottom); } } } } - pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); + m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); } } @@ -1483,14 +1383,14 @@ DWORD ThreadProcess(LPVOID param) //若待抠图的快照数不为0 则进行批量抠图 if (0 != copy_obj_count) { - cudaSetDevice(pThreadParam->mgpuid); + cudaSetDevice(mgpuid); cuCtxPushCurrent(context); - PartMemResizeBatch((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight, + PartMemResizeBatch((unsigned char*)tasks[*iter].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 (pThreadParam->m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty()) + if (m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty()) { //需要做人脸检测 int human_count = human_idx.size(); @@ -1511,7 +1411,7 @@ DWORD ThreadProcess(LPVOID param) face_det_result[fd_i].info = new fd_info[10]; //内存由外部申请 } - if (pThreadParam->m_face_det_module->face_det_module_process(human_img, human_count, face_det_result, ori_points) == SUCCESS) + if (m_face_det_module->face_det_module_process(human_img, human_count, face_det_result, ori_points) == SUCCESS) { //printf("finish face_det_module_process: %d\n", human_count); for (int idx = 0; idx < human_count; idx++) @@ -1543,7 +1443,7 @@ DWORD ThreadProcess(LPVOID param) } fd_info& cur_det_info = cur_det_res.info[face_idx]; - if (pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame == nullptr) + if (m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame == nullptr) { sy_rect face_ori_rect = { (int)(snapshot_left[ii] + cur_det_info.face_position.left_ ), (int)(snapshot_top[ii] + cur_det_info.face_position.top_), @@ -1551,8 +1451,8 @@ DWORD ThreadProcess(LPVOID param) 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)pThreadParam->tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); - int new_bottom = min((int)pThreadParam->tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); + int new_right = min((int)tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); + int new_bottom = min((int)tasks[*iter].task_algorithm_data.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; @@ -1560,18 +1460,18 @@ DWORD ThreadProcess(LPVOID param) int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; - cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); + cudaError_t cudaStatus = cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); if (cudaStatus != cudaSuccess) { fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); break; } - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; - memcpy((void*)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); + m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; + m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; + memcpy((void*)&m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 - fd_info& tmp_info = pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; + fd_info& tmp_info = m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; for (int p = 0; p < FACIALFEAPOINTSIZE; p++) { @@ -1581,14 +1481,14 @@ DWORD ThreadProcess(LPVOID param) tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); } - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = + m_snaphot_helper.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*)pThreadParam->tasks[*iter].task_algorithm_data.frame, pThreadParam->tasks[*iter].task_algorithm_data.width, pThreadParam->tasks[*iter].task_algorithm_data.height, - (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); + cudacommon::CropImgGpu((unsigned char*)tasks[*iter].task_algorithm_data.frame, tasks[*iter].task_algorithm_data.width, tasks[*iter].task_algorithm_data.height, + (unsigned char*)m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); - //show_gpu_img_func(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace); + //show_gpu_img_func(m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace); } else { @@ -1598,12 +1498,12 @@ DWORD ThreadProcess(LPVOID param) //更新人脸快照条件:① 角度满足条件 ② 面积比之前人脸面积大 if (validAngle(cur_det_res.info[face_idx].roll, cur_det_res.info[face_idx].yaw, cur_det_res.info[face_idx].pitch, 15.0, 20.0) - && betterArea(face_ori_rect, pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position)) + && betterArea(face_ori_rect, m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position)) { 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)pThreadParam->tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); - int new_bottom = min((int)pThreadParam->tasks[*iter].task_algorithm_data.height - 1, (face_ori_rect.top_ + 2 * face_ori_rect.height_)); + int new_right = min((int)tasks[*iter].task_algorithm_data.width - 1, (face_ori_rect.left_ + 2 * face_ori_rect.width_)); + int new_bottom = min((int)tasks[*iter].task_algorithm_data.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; @@ -1612,19 +1512,19 @@ DWORD ThreadProcess(LPVOID param) //更新快照 int face_img_length = 3 * face_expand_rect.width_ * face_expand_rect.height_; - cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame); - cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); + cudaFree(m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame); + cudaError_t cudaStatus = cudaMalloc((void**)&m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_img_length * sizeof(unsigned char)); if (cudaStatus != cudaSuccess) { fprintf(stderr, "here cudaMalloc frame[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); break; } - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; - memcpy((void*)&pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); + m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.width = face_expand_rect.width_; + m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.height = face_expand_rect.height_; + memcpy((void*)&m_snaphot_helper.snapShotInfo[cur_obj_key].face_info, (void*)&cur_det_info, sizeof(fd_info)); //矫正坐标 从行人抠图检测结果 -> 人脸外扩抠图坐标 - fd_info& tmp_info = pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; + fd_info& tmp_info = m_snaphot_helper.snapShotInfo[cur_obj_key].face_info; for (int p = 0; p < FACIALFEAPOINTSIZE; p++) { @@ -1634,15 +1534,15 @@ DWORD ThreadProcess(LPVOID param) tmp_info.facial_fea_point[p].y_ - tmp_info.face_position.top_ + (face_ori_rect.top_ - face_expand_rect.top_); } - pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info.face_position = + m_snaphot_helper.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*)pThreadParam->tasks[*iter].task_algorithm_data.frame, pThreadParam->tasks[*iter].task_algorithm_data.width, pThreadParam->tasks[*iter].task_algorithm_data.height, - (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); + cudacommon::CropImgGpu((unsigned char*)tasks[*iter].task_algorithm_data.frame, tasks[*iter].task_algorithm_data.width, tasks[*iter].task_algorithm_data.height, + (unsigned char*)m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace.frame, face_expand_rect.left_, face_expand_rect.top_, face_expand_rect.width_, face_expand_rect.height_); - //show_gpu_image_withfdinfo_(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, cur_det_info); + //show_gpu_image_withfdinfo_(m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, cur_det_info); - //show_gpu_image_withfdinfo_(pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, pThreadParam->m_snaphot_helper.snapShotInfo[cur_obj_key].face_info); + //show_gpu_image_withfdinfo_(m_snaphot_helper.snapShotInfo[cur_obj_key].snapShotFace, m_snaphot_helper.snapShotInfo[cur_obj_key].face_info); } } } @@ -1663,11 +1563,11 @@ DWORD ThreadProcess(LPVOID param) //实时查看 绘制目标轨迹 回调函数返回 if (view) { - DrawTracker(pThreadParam->VPT_Handle, *iter, &pThreadParam->tasks[*iter].frameImage); - if (pThreadParam->tasks[*iter].taskRealTimeCallbackFunc != nullptr) - pThreadParam->tasks[*iter].taskRealTimeCallbackFunc(pThreadParam->tasks[*iter].frameImage.data, pThreadParam->tasks[*iter].frameImage.rows, pThreadParam->tasks[*iter].frameImage.cols); + DrawTracker(VPT_Handle, *iter, &tasks[*iter].frameImage); + if (tasks[*iter].taskRealTimeCallbackFunc != nullptr) + tasks[*iter].taskRealTimeCallbackFunc(tasks[*iter].frameImage.data, tasks[*iter].frameImage.rows, tasks[*iter].frameImage.cols); } - // pThreadParam->tasks[*iter].taskFrameCount += pThreadParam->skip_frame_; + // tasks[*iter].taskFrameCount += skip_frame_; iter++; } @@ -1677,9 +1577,9 @@ DWORD ThreadProcess(LPVOID param) #endif - auto task_iter = pThreadParam->TaskinPlayID.begin(); + auto task_iter = TaskinPlayID.begin(); - pThreadParam->AttributionAnalysis = false; + AttributionAnalysis = false; long long second_analysis_time = get_cur_time_ms(); @@ -1689,20 +1589,20 @@ DWORD ThreadProcess(LPVOID param) { OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; - if (pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) + if (m_snaphot_helper.snapShotInfo.find(deleteObj) == m_snaphot_helper.snapShotInfo.end()) continue; - auto iter = pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj); + auto iter = m_snaphot_helper.snapShotInfo.find(deleteObj); iter->second.finishTracker = true; - pThreadParam->SaveResultInFile(iter->first, iter->second); + m_snaphot_helper.SaveResultInFile(iter->first, iter->second); } task_iter++; } - for (auto task_id: pThreadParam->TaskinPlayID) { - cudaFree(pThreadParam->tasks[task_id].task_algorithm_data.frame); + for (auto task_id: TaskinPlayID) { + cudaFree(tasks[task_id].task_algorithm_data.frame); } @@ -1710,7 +1610,7 @@ DWORD ThreadProcess(LPVOID param) vector().swap(deleteObjectID[i]); vector>().swap(deleteObjectID); - pThreadParam->m_snaphot_helper.object_attri_analysis(); + m_snaphot_helper.object_attri_analysis(); #ifdef LOG_INFO2 long long second_analysis_time2 = get_cur_time_ms(); @@ -1743,8 +1643,8 @@ DWORD ThreadProcess(LPVOID param) long long costTime1 = get_cur_time_ms() - begintime1; LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times); - pThreadParam->m_snaphot_helper.snapShotInfo.clear(); - pThreadParam->ProcessFlag = false; + m_snaphot_helper.snapShotInfo.clear(); + ProcessFlag = false; if (batch_img != NULL) { @@ -1754,8 +1654,6 @@ DWORD ThreadProcess(LPVOID param) cuCtxPopCurrent(nullptr); cuCtxDestroy(context); - - return 0; } int CMutliSourceVideoProcess::GetRuningNb() { @@ -1779,9 +1677,9 @@ void check_thread(void* handle) char * time = wtime; #endif - CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)handle; + CMutliSourceVideoProcess *_this = (CMutliSourceVideoProcess *)handle; - while (!pThreadParam->m_bExit) + while (!_this->m_bExit) { //printf("xxx check status on process...\n"); #ifdef _MSC_VER @@ -1792,14 +1690,14 @@ void check_thread(void* handle) #endif if (res < 0) { - pThreadParam->licence_status = pThreadParam->licence_status - 1; + _this->licence_status = _this->licence_status - 1; printf("CMutliSourceVideoProcess licence error, ret: %d \n", res); } else { - if (pThreadParam->licence_status < 0) + if (_this->licence_status < 0) { - pThreadParam->licence_status = 0; + _this->licence_status = 0; } } std::this_thread::sleep_for(std::chrono::seconds(300)); 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 8deaa68..5ca32c7 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 @@ -225,11 +225,12 @@ public: void ViewTask(const int taskID); void FinishViewTask(); int FinishProcessThread(); - int SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value); void FinishDecode(const int taskID); int GetRuningNb(); + void algorthim_process(); + private: //bool ChangeTask; //HANDLE handle_process; 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 1012583..bdc4b5c 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 @@ -73,7 +73,7 @@ int HumanCarParsing::init(int gpuid, char* auth_license) int HumanCarParsing::process(sy_img * batch_img, int batch_size, hcp_analysis_result *&result) { - LOG_INFO("batch_size: {}", batch_size); + LOG_DEBUG("batch_size: {}", batch_size); hcp_batch(handle, batch_img, batch_size, result); for (int b = 0; b < batch_size; b++) 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 f2da446..f07c029 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 @@ -90,7 +90,7 @@ 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 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) { hp_analysis_cf = hp_analysis_config; hcp_analysis_cf = hcp_analysis_config; @@ -98,6 +98,7 @@ void snapshot_helper::snapshot_helper_init(int gpuid, double gpu_total_memory, c hf_recg_cf = hf_recg_config; hcf_recg_cf = hcf_recg_config; vcf_recg_cf = vcf_recg_config; + face_detect_cf = face_detect_config; char* dbpath_utf8 = nullptr; #ifdef _MSC_VER //dbpath_utf8 = GbkToUtf8(dbpath); @@ -2018,3 +2019,56 @@ int snapshot_helper::save_snapshot(bool is_image, bool on_image_display, OBJ_KEY } return 1; } + +int snapshot_helper::SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value) +{ + if (0 == obj_value.index.index && obj_value.snapShotLittle.width == HP_WIDTH && obj_value.snapShotLittle.height == HP_HEIGHT) + { + if (face_detect_cf == SY_CONFIG_OPEN) + { + save_face_snapshot(obj_key); + } + + if (hp_analysis_cf == SY_CONFIG_OPEN || hf_recg_cf == SY_CONFIG_OPEN) + { + save_snapshot(obj_key); + hp_analysis(obj_key); + } + else + { + save_without_analysis(obj_key); + } + } + else if ((1 == obj_value.index.index || 2 == obj_value.index.index) && obj_value.snapShotLittle.width == HCP_WIDTH && obj_value.snapShotLittle.height == HCP_HEIGHT) + { + if (hcp_analysis_cf == SY_CONFIG_OPEN || hcf_recg_cf == SY_CONFIG_OPEN) + { + save_snapshot(obj_key); + hcp_analysis(obj_key); + } + else + { + save_without_analysis(obj_key); + } + } + else if ((8 == obj_value.index.index || (obj_value.index.index >= 4 && obj_value.index.index <= 6)) && obj_value.snapShotLittle.width == VEHICLE_WIDTH && obj_value.snapShotLittle.height == VEHICLE_HEIGHT) + { + //VEHICLEAnalysis(obj_key, obj_value); + if (vehicle_analysis_cf == SY_CONFIG_OPEN || vcf_recg_cf == SY_CONFIG_OPEN) + { + save_snapshot(obj_key); + vehicle_analysis(obj_key); + } + else + { + save_without_analysis(obj_key); + } + + } + else + { + save_without_analysis(obj_key); + } + + return 0; +} \ 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 59948a3..8e4abe0 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 @@ -51,26 +51,6 @@ struct AABBBOX int bottom; }; -//struct OBJ_KEY { -// int videoID; -// int objID; -// -// bool operator< (OBJ_KEY const& _A) const -// { -// if (videoID < _A.videoID) return true; -// if (videoID == _A.videoID) return objID < _A.objID; -// -// return false; -// } -// bool operator== (OBJ_KEY const& _A) const -// { -// if (videoID == _A.videoID && objID == _A.objID) -// return true; -// else -// return false; -// } -//}; - struct OBJ_INDEX { int index; int count; //用于对index的计数 @@ -140,12 +120,6 @@ enum { VC_ALL_ANALYSIS }; -//enum class VC_ANALYSIS_TYPE { -// VC_ANALYSIS, -// VR_VF_ANALYSIS, -// VPDR_ANALYSIS -//}; - enum class V_ANALYSIS_TYPE { VC_ANALYSIS, VR_VF_ANALYSIS, @@ -157,54 +131,6 @@ extern string ObjTypesEnglish[]; class snapshot_helper { -private: - queue count_person; - queue count_bike; - queue count_vehicle; - //map snapShotInfo_hpf; - //map snapShotInfo_hcpf; - - vector count_vehicle_v; //车的二次属性分析拆为三部分时,不再使用队列,只能使用数组 - - vector vehicle_result_v; - - sy_img * batch_hp = nullptr; - sy_img * batch_hcp = nullptr; - sy_img * batch_vehicle = nullptr; - sy_img * batch_vehicle_vf = nullptr; - - void * hp_handle = nullptr; - void * vc_handle = nullptr; - void * vp_handle = nullptr; - void * vr_handle = nullptr; - void * vrr_handle = nullptr; - void * nvf_handle = nullptr; - void * vhd_handle = nullptr; - void * vf_handle = nullptr; - sy_command hp_analysis_cf; - sy_command hcp_analysis_cf; - sy_command vehicle_analysis_cf; - - sy_command hf_recg_cf; - sy_command hcf_recg_cf; - sy_command vcf_recg_cf; - - void * hf_handle = nullptr; - void * hcf_handle = nullptr; - sy_command vehicle_recg_cf; - sy_command vehicle_plate_det_recg_cf; - int count_vehivle_finishanalysis = 0; - int OBJ_SCALE = 2; - int OBJ_BATCH_COUNT = 0; - int OBJ_BATCH_COUNT_VEHICLE = 0; - - int hp_wait_count, hcp_wait_count, vehicle_wait_count; - int wait_framecount; - - std::thread* ProcessSnapshotThread; - std::vector m_vec_writeThread; - bool m_bExit {false}; - public: void snapshot_thread_process(); void snapshot_imagewrite_thread_process(); @@ -227,16 +153,13 @@ public: //VC_ANALYSIS_TYPE vc_analysis; 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 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_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); - int save_snapshot(bool is_image, bool on_image_display, OBJ_KEY obj_key, char* filename, char* mode, float* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom); - int save_snapshot(bool is_image, bool on_image_display, OBJ_KEY obj_key, char* filename, char* mode, unsigned char* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom); - int save_snapshot(OBJ_KEY obj_key); - int save_face_snapshot(OBJ_KEY obj_key); + + int SaveResultInFile(const OBJ_KEY & obj_key, const OBJ_VALUE & obj_value); - void save_without_analysis(OBJ_KEY obj_key); void erase_snapshotImage(OBJ_KEY obj_key); //整体的三种二次属性分析 void hp_analysis(OBJ_KEY obj_key); @@ -248,14 +171,69 @@ public: bool vehicle_color_analysis(); bool vehicle_recg_analysis(); bool vehicle_plate_dr_analysis(); - void finish_task_ss_analysis(int task_id, sy_command hp_analysis_config, sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config); - //针对车拆开的二次属性分析 - void VehicleRecog_Process(sy_img * batch_img, int batchsize, vr_result *&vresult, OBJ_KEY* obj_keys); + void object_attri_analysis(); void snapshot_res_callback(OBJ_KEY obj_key,/* OBJ_VALUE obj_value,*/ void* analysisRes = NULL); private: + int save_snapshot(bool is_image, bool on_image_display, OBJ_KEY obj_key, char* filename, char* mode, float* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom); + int save_snapshot(bool is_image, bool on_image_display, OBJ_KEY obj_key, char* filename, char* mode, unsigned char* imgData, int width, int height, int taskID, int objID, int recFlag, int left, int top, int right, int bottom); + int save_snapshot(OBJ_KEY obj_key); + int save_face_snapshot(OBJ_KEY obj_key); + + void save_without_analysis(OBJ_KEY obj_key); + + //针对车拆开的二次属性分析 + void VehicleRecog_Process(sy_img * batch_img, int batchsize, vr_result *&vresult, OBJ_KEY* obj_keys); + +private: HumanCarParsing m_human_car_parsing; + + queue count_person; + queue count_bike; + queue count_vehicle; + + vector count_vehicle_v; //车的二次属性分析拆为三部分时,不再使用队列,只能使用数组 + + vector vehicle_result_v; + + sy_img * batch_hp = nullptr; + sy_img * batch_hcp = nullptr; + sy_img * batch_vehicle = nullptr; + sy_img * batch_vehicle_vf = nullptr; + + void * hp_handle = nullptr; + void * vc_handle = nullptr; + void * vp_handle = nullptr; + void * vr_handle = nullptr; + void * vrr_handle = nullptr; + void * nvf_handle = nullptr; + void * vhd_handle = nullptr; + void * vf_handle = nullptr; + sy_command hp_analysis_cf; + sy_command hcp_analysis_cf; + sy_command vehicle_analysis_cf; + sy_command hf_recg_cf; + sy_command hcf_recg_cf; + sy_command vcf_recg_cf; + sy_command vehicle_recg_cf; + sy_command vehicle_plate_det_recg_cf; + sy_command face_detect_cf; + + void * hf_handle = nullptr; + void * hcf_handle = nullptr; + + int count_vehivle_finishanalysis = 0; + int OBJ_SCALE = 2; + int OBJ_BATCH_COUNT = 0; + int OBJ_BATCH_COUNT_VEHICLE = 0; + + int hp_wait_count, hcp_wait_count, vehicle_wait_count; + int wait_framecount; + + std::thread* ProcessSnapshotThread; + std::vector m_vec_writeThread; + bool m_bExit {false}; }; \ No newline at end of file