#include "MutliSourceVideoProcess.h" #include "authority.h" #ifdef _MSC_VER #include #include #include "putText.h" #endif #include #include #include #include //********************************************************// //1.为什么有时候返回的index=2,却未做人骑车的分析:因为index在后来变为了2,但是此时的快照并不优于之前的快照,所以快照未更新,快照图像大小并不为112*224 #ifdef _MSC_VER #define productSN "4ACFCBE67EF645AB8F0B4CFCDD1926F1" //WINDOWS定义产品系列号 #else #define productSN "4FD45501D5104F0C8C4BE530FC872F46" //LINUX定义产品系列号 //#define productSN "7CF8B4797F9E441686145BED07F662DE" //LINUX定义产品系列号 #endif //#define LOG_INFO //是否开启测速打印 #define SKIP_FRMAE 5 //跳帧帧数 #define EXTIME 500 void check_thread(void* handle); DWORD ThreadProcess(LPVOID param); long long total = 0; long long total_free = 0; CMutliSourceVideoProcess::CMutliSourceVideoProcess() { } CMutliSourceVideoProcess::~CMutliSourceVideoProcess() { } int CMutliSourceVideoProcess::FinishProcessThread() { if (thrd_status == 0) { thrd.interrupt(); thrd.join(); thrd_status = -1; } ProcessThread.interrupt(); //interrupt thread ProcessThread.join(); //waiting thread finish VPT_Release(VPT_Handle); m_snaphot_helper.snapshot_helper_release(); DxDecoderInterface::UninitDecoderModule(); return 1; } int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc, VIDEO_FINISH_CALLBACK tFinishCallbackFunc) { // checkGpuMem(); licence_status = -1; thrd_status = -1; int ret = SUCCESS; //printf("=====================授权ERROR==================\n"); //printf("=====================授权ERROR==================\n"); //printf("=====================授权ERROR==================\n"); #ifdef _WIN32 if (SUCCESS == (ret = sy_licence(productSN))) #elif __linux__ char* wtime = new char[15]{}; memset(wtime, 0, 15); if (SUCCESS == (ret = sy_licence(productSN, wtime))) #endif { cuInit(0); int device_count = 0; cuDeviceGetCount(&device_count); if (vptParam.gpuid >= device_count) { printf("\nGPU_ID PARAM WRONG!\n"); return GPUID_PARAM_ERROR; } CUdevice dev = 0; size_t memSize = 0; dev = vptParam.gpuid; CUresult rlt = CUDA_SUCCESS; rlt = cuDeviceTotalMem(&memSize, dev); gpu_total_memory = (float)memSize / (1024 * 1024); if (gpu_total_memory < 9000) //8G显存,小内存方案 section_batch_size = 5; else section_batch_size = 10; VPTProcess_PARAM param{}; param.c = 3; param.gpuid = vptParam.gpuid; mgpuid = vptParam.gpuid; VPT_Handle = NULL; ret = VPT_Init(VPT_Handle, param); if (0 != ret) return ret; viewTaskID = -1; ChangeTask = false; TaskinPlay = 0; TotalTask = 0; capacity = 20; VPTResult.resize(capacity); //dwThreadID = 0; ProcessFlag = false; SourceFlag = false; mModeSnapshotVideo = "cpu"; mModeSnapshotLittle = "cpu"; taskFinishCallbackFunc = NULL; if (tFinishCallbackFunc != NULL) taskFinishCallbackFunc = std::bind(tFinishCallbackFunc, this, std::placeholders::_1); if (tObjInfoCallbackFunc != NULL) taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1); minDistance[0] = minDistance[2] = 35; //left right minDistance[1] = minDistance[3] = 50; //top bottom m_hp_analysis_config = vptParam.hp_analysis_config; m_hcp_analysis_config = vptParam.hcp_analysis_config; m_vehicle_analysis_config = vptParam.vehicle_analysis_config; m_hf_recg_config = vptParam.hf_recg_config; m_hcf_recg_config = vptParam.hcf_recg_config; m_vcf_recg_config = vptParam.vcf_recg_config; m_snaphot_helper.snapshot_helper_init(vptParam.gpuid, gpu_total_memory, vptParam.vrdbpath, 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); if (ret == SUCCESS) //成功 { licence_status = 0; thrd = boost::thread(check_thread, this); thrd_status = 0; } } else { return AUTHOR_ERROR; } #ifdef __linux__ if (wtime) { delete[] wtime; wtime = NULL; } #endif return ret; } void CMutliSourceVideoProcess::FinishDecode(const int taskID) { boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(400)); for (int i = 0; i < tasks.size(); i++) { if (tasks[i].taskID == taskID && tasks[taskID].taskTcuvid != NULL) { tasks[taskID].taskState == FINISH; tasks[taskID].taskTcuvid->DxCloseDecoder(); delete tasks[taskID].taskTcuvid; tasks[taskID].taskTcuvid = NULL; printf("-----------------------finish task: %d-----------------------\n", taskID); break; } } } void CMutliSourceVideoProcess::FinishTask(const int taskID) { for (int i = 0; i < tasks.size(); i++) { if (tasks[i].taskID == taskID) { //printf("first begin finish\n"); if (tasks[i].taskState == PLAY) TaskinPlay--; tasks[i].taskState = FINISH; tasks[i].taskFileSource = NULL; tasks[i].taskObjCallbackFunc = NULL; tasks[i].taskRealTimeCallbackFunc = NULL; //printf("begin finish task\n"); m_snaphot_helper.finish_task_ss_analysis(taskID, m_hp_analysis_config, m_hcp_analysis_config, m_vehicle_analysis_config, m_hf_recg_config, m_hcf_recg_config, m_vcf_recg_config); //是否开启车辆特征识别); if (tasks[i].folderName) { delete tasks[i].folderName; tasks[i].folderName = NULL; } if (tasks[i].folderNameLittle) { delete tasks[i].folderNameLittle; tasks[i].folderNameLittle = NULL; } if (tasks[i].taskDataToRT) { free(tasks[i].taskDataToRT); tasks[i].taskDataToRT = NULL; } tasks[i].frameImage.release(); if (tasks[i].task_algorithm_data.frame) { cudaFree(tasks[i].task_algorithm_data.frame); ++total_free; tasks[i].task_algorithm_data.frame = NULL; } //printf("finish delete\n"); FinishTaskTracker(VPT_Handle, taskID); //printf("finish tracker\n"); if (viewTaskID == taskID) viewTaskID = -1; break; } } } void CMutliSourceVideoProcess::PauseTask(const int taskID) { for (int i = 0; i < tasks.size(); i++) { if (tasks[i].taskID == taskID) { if (tasks[i].taskState == PLAY) TaskinPlay--; tasks[i].taskState = PAUSE; PauseTaskTracker(VPT_Handle, taskID); tasks[i].taskTcuvid->PauseDecoder(); if (viewTaskID == taskID) viewTaskID = -1; printf("-----------------------pasue task: %d-----------------------\n", taskID); break; } } } void CMutliSourceVideoProcess::RestartTask(const int taskID) { for (int i = 0; i < tasks.size(); i++) { if (tasks[i].taskID == taskID) { tasks[i].taskState = PLAY; TaskinPlay++; RestartTaskTraker(VPT_Handle, taskID); tasks[i].taskTcuvid->ResumeDecoder(); printf("-----------------------restart task: %d-----------------------\n", taskID); break; } } } void CMutliSourceVideoProcess::ViewTask(const int taskID) { if (tasks.size() > taskID && tasks[taskID].taskState == PLAY) { viewTaskID = taskID; printf("-----------------------view task: %d-----------------------\n", taskID); } else printf("Only can view playing task!"); } void CMutliSourceVideoProcess::FinishViewTask() { viewTaskID = -1; printf("-----------------------finish view task-----------------------\n"); } bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, sy_rect minBoxsize[DETECTTYPE], VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* = NULL*/, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* = NULL*/) { //checkGpuMem(); using std::placeholders::_1; // printf("begin real add task\n"); if (TaskinPlay >= capacity) { //cout << "********************** resize capacity *************************" << endl; capacity *= 2; VPTResult.resize(capacity); } string rtsp = "rtsp"; string sVideoFileName = videoFileName; int tmp_total_frame = -1; if (sVideoFileName.find(rtsp) >= sVideoFileName.length()) //is a rtsp? { //std::cout<<"The video name : "<DxOpenDecoder(new_task.taskFileSource, SKIP_FRMAE) != 0) { cout << "Add Task Failed! Please check you video file name!" << endl; delete new_task.taskTcuvid; new_task.taskTcuvid = NULL; AddTaskSucFlag = -1; return false; } // printf("finish add codec\n"); new_task.taskState = PLAY; new_task.task_algorithm_data.frame = NULL; new_task.taskFrameCount = 0; new_task.taskDataToRT = NULL; //new_task.taskObjCallbackFunc = NULL; if (objCallbackFunc != NULL) new_task.taskObjCallbackFunc = std::bind(objCallbackFunc, this, std::placeholders::_1); //new_task.taskRealTimeCallbackFunc = NULL; if (realTimeCallbackFunc != NULL) new_task.taskRealTimeCallbackFunc = std::bind(realTimeCallbackFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); new_task.taskTotalFrameCount = tmp_total_frame; if (resultFolderLittle == NULL) { new_task.folderNameLittle = NULL; } else { new_task.folderNameLittle = new char[strlen(resultFolderLittle) + 1]{}; strcpy(new_task.folderNameLittle, resultFolderLittle); int length = strlen(new_task.folderNameLittle); if (new_task.folderNameLittle[length - 1] != '\\' && new_task.folderNameLittle[length - 1] != '/') { new_task.folderNameLittle[length] = '/'; new_task.folderNameLittle[length + 1] = '\0'; } CreateResultFolder(new_task.folderNameLittle, ""); } if (resultFolder == NULL) { new_task.folderName = NULL; } else { new_task.folderName = new char[strlen(resultFolder) + 2]{}; strcpy(new_task.folderName, resultFolder); int length = strlen(new_task.folderName); if (new_task.folderName[length - 1] != '\\' && new_task.folderName[length - 1] != '/') { new_task.folderName[length] = '/'; new_task.folderName[length + 1] = '\0'; } CreateResultFolder(new_task.folderName, ""); } // printf("finish create folder\n"); //Sleep(10); //std::cout << "CreateResultFolder" << std::endl; TASK_INFO new_task_info = {}; new_task_info.image_folder = new_task.folderName; new_task_info.snapshot_folder = new_task.folderNameLittle; new_task_info.task_total_framecount = new_task.taskTotalFrameCount; new_task_info.obj_callback = new_task.taskObjCallbackFunc; m_snaphot_helper.add_task_info(new_task.taskID, new_task_info); TotalTask++; TaskinPlay++; tasks.push_back(new_task); // printf("finish push tasks\n"); //return 1; //std::cout<<__LINE__<<"of"<<__FILE__<<"debug\n"; if (!ProcessFlag) { /*for (int num = 0; num < 5; ++num) {*/ //create_thread()是一个工厂函数,可以创建thead对象并运行线程,同时加入内部的list // group.create_thread(boost::bind(&runchild , num)) ; //saveSnapshotsThreadGroup.create_thread(boost::bind(SnapshotThreadProcess, this, 0)); //} ProcessThread = boost::thread(ThreadProcess, this); //std::cout << "begin algorithm" << std::endl; ProcessFlag = true; } printf("-----------------------add task: %d-----------------------\n", tasks.size() - 1); AddTaskSucFlag = 1; return true; } int CMutliSourceVideoProcess::AddOperator(task_param tparam) //int CMutliSourceVideoProcess::AddOperator(const char* videoFileName, const char* resultFolderLittle, const char* resultFolder, VIDEO_OBJECT_SNAPSHOT_CALLBACK objCallbackFunc/* =NULL */, VIDEO_REALTIME_CALLBACK realTimeCallbackFunc/* =NULL */) { AddTaskSucFlag = 0; bool temp_process_flag = true; { boost::mutex::scoped_lock lock(process_thread_mutex); if (!ProcessFlag) { // printf("add first task\n"); AddTask(tparam.video_filename, tparam.result_folder_little, tparam.result_folder, tparam.minBoxsize, tparam.obj_snapshot_callback_func, tparam.rt_view_callback_func); boost::thread::sleep(boost::get_system_time() + boost::posix_time::microseconds(500)); } else { // printf("add first task in operator queue\n"); Operator newOper; newOper.changeTaskID = 0; newOper.changeTaskOperator = TaskOperator(0); newOper.videoFileName = tparam.video_filename; newOper.resultFolderLittleName = tparam.result_folder_little; newOper.resultFolderName = tparam.result_folder; newOper.taskObjCallbackFunc = tparam.obj_snapshot_callback_func; newOper.taskRealTimeCallbackFunc = tparam.rt_view_callback_func; memcpy(newOper.minBoxsize, tparam.minBoxsize, sizeof(sy_rect)* DETECTTYPE); //TaskOperatorQ.push(newOper); TaskOperatorQ.push_back(newOper); SetChangeTaskFlag(true); // printf("finish first task in operator queue\n"); } } int addRes = -1; int newTaskID = TaskID++; int timeout = 100000; while (timeout--) { if (AddTaskSucFlag == 1) { addRes = newTaskID; break; } else if (AddTaskSucFlag == -1) { addRes = -1; TaskID--; break; } /*for (int i = 0; i < tasks.size(); i++) { if (tasks[i].taskID == newTaskID) { addRes = newTaskID; } } if (addRes == newTaskID) break;*/ boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(100)); } if (timeout <= 0) { Operator newOper = TaskOperatorQ.back(); if (strcmp(newOper.videoFileName, tparam.video_filename) == 0) { TaskOperatorQ.pop_back(); } cout << "Failed Add New Task! Algorithm Process Error! " << endl; } return addRes; //return TaskID++; } void CMutliSourceVideoProcess::AddOperator(int taskID, int taskOper) { if (taskOper > 0 && taskOper < 4) { Operator newOper = {}; newOper.changeTaskID = taskID; newOper.changeTaskOperator = TaskOperator(taskOper); newOper.videoFileName = NULL; //TaskOperatorQ.push(newOper); TaskOperatorQ.push_back(newOper); } } void CMutliSourceVideoProcess::OperatorTask() { while (!TaskOperatorQ.empty()) { Operator newOperator = TaskOperatorQ.front(); TaskOperatorQ.pop_front(); switch (newOperator.changeTaskOperator) { case ADDTASK: AddTask(newOperator.videoFileName, newOperator.resultFolderLittleName, newOperator.resultFolderName, newOperator.minBoxsize, newOperator.taskObjCallbackFunc, newOperator.taskRealTimeCallbackFunc); break; case PAUSETASK: PauseTask(newOperator.changeTaskID); break; case RESTARTTASK: RestartTask(newOperator.changeTaskID); break; case FINISHTASK: FinishTask(newOperator.changeTaskID); break; default: break; } } } 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_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; } //int CMutliSourceVideoProcess::SaveResultInFile(OBJ_KEY obj_key, OBJ_VALUE obj_value) //{ ////#ifdef LOG_INFO ////#ifdef _MSC_VER //// LARGE_INTEGER nFreq, nBeginTime, nEndTime; //// LARGE_INTEGER nSaveBeginTime, nSaveEndTime; //// //// QueryPerformanceFrequency(&nFreq); //// QueryPerformanceCounter(&nBeginTime); //// double time_val = 0.0; ////#else //// gettimeofday(&t1, NULL); //// ////#endif ////#endif // // /********************************************************** // * // * Snapshot Attribution Analysis // * // ************************************************************/ // //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); // // if (0 == obj_value.index.index && obj_value.snapShotLittle.width == HP_WIDTH && obj_value.snapShotLittle.height == HP_HEIGHT) // { // 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, obj_value, AttributionAnalysis, false); // } // 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, obj_value, AttributionAnalysis, false); // } // 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_color_analysis(obj_key, obj_value, AttributionAnalysis); // m_snaphot_helper.vehicle_recg_analysis(obj_key, obj_value, AttributionAnalysis); // m_snaphot_helper.vf_feature(obj_key, obj_value, AttributionAnalysis); // if(!AttributionAnalysis) // m_snaphot_helper.vehicle_plate_dr_analysis(obj_key, obj_value, AttributionAnalysis); // } // else // { // m_snaphot_helper.save_without_analysis(obj_key); // } // // } // else //这一帧不进行任何分析的时候 进行车牌检测识别 并返回结果 // { // m_snaphot_helper.save_without_analysis(obj_key); // } // ////#ifdef LOG_INFO ////#ifdef _MSC_VER //// QueryPerformanceCounter(&nEndTime); //// time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; //// std::printf("SaveResultInFile: %.2f ms \n", time_val); ////#else //// /* //// gettimeofday(&t2, NULL); //// time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; //// printf("HumanParsing_Process = %lf ms\n", time_val); //// */ ////#endif ////#endif // // return 0; //} DWORD CMutliSourceVideoProcess::ImageThreadProcess() { } extern long long costSave; DWORD ThreadProcess(LPVOID param) { cudaError_t cudaStatus = {}; set k; int count = 0; sy_img * batch_img = new sy_img[20]{}; DxGPUFrame frame = {}; #ifdef _MSC_VER LARGE_INTEGER nFreq, nBeginTime, nEndTime; LARGE_INTEGER nSaveBeginTime, nSaveEndTime; QueryPerformanceFrequency(&nFreq); #else struct timeval first_time, second_time; struct timeval first_time_total, second_time_total; #endif CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)param; cudaSetDevice(pThreadParam->mgpuid); cuda_common::setColorSpace2(ITU709, 0); cudaMalloc((void**)&pThreadParam->FrameTemp, 3 * 4096 * 4096 * sizeof(unsigned char)); ++total; long long costTime = 0; long long costTime1 = 0; long long costTime2 = 0; long long costTime3 = 0; //std::ofstream os("D:\\vptlog.txt", std::ofstream::out | std::ofstream::trunc); //os << unitbuf; //try { vector ObjectID; while (1) { auto begintime1 = std::chrono::system_clock::now(); if (pThreadParam->licence_status <= -3) { printf("authority failed!\n"); break; } //os << 1 << std::endl; /********************************************************** * * initial & check the count of decode videos * ************************************************************/ #ifdef _MSC_VER QueryPerformanceCounter(&nBeginTime); QueryPerformanceCounter(&nSaveBeginTime); #else gettimeofday(&first_time, NULL); gettimeofday(&first_time_total, NULL); #endif //os << 2 << std::endl; double time_val, time_val_p = 0; if (pThreadParam->GetChangeTask()) { pThreadParam->OperatorTask(); pThreadParam->SetChangeTaskFlag(false); } //os << 3 << std::endl; int curTaskSize = pThreadParam->tasks.size(); count = 0; map> finishTaskDeleteObj; int curPlayTaskCount = 0; for (int i = 0; i < curTaskSize; i++) { if ((pThreadParam->tasks[i].taskState == PLAY || pThreadParam->tasks[i].taskState == DECODEERROR)) { if (!pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) { cudaError_t cudaStatus = cudaGetLastError(); if (cudaStatus != cudaSuccess) { printf("begin finish last error: %s\n", cudaGetErrorString(cudaStatus)); } cout << "***************** Task " << i << "is Finished *****************" << endl; pThreadParam->tasks[i].taskState = FINISH; pThreadParam->FinishTask(pThreadParam->tasks[i].taskID); pThreadParam->tasks[i].taskTcuvid->DxCloseDecoder(); delete pThreadParam->tasks[i].taskTcuvid; pThreadParam->tasks[i].taskTcuvid = NULL; int taskid = pThreadParam->tasks[i].taskID; 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 { if (item.first.videoID == taskid) { return true; } else { return false; } }) != pThreadParam->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 (pThreadParam->taskFinishCallbackFunc != NULL) pThreadParam->taskFinishCallbackFunc(pThreadParam->tasks[i].taskID); pThreadParam->TaskinPlay--; } } if (pThreadParam->tasks[i].taskState == FINISH) count++; } //os << 4 << std::endl; if (count >= pThreadParam->tasks.size()) //have no decode video, break { { boost::mutex::scoped_lock lock(pThreadParam->process_thread_mutex); if (pThreadParam->GetChangeTask()) { continue; } else { //printf("802 set ProcessFlag false\n"); pThreadParam->ProcessFlag = false; break; } } } curPlayTaskCount = pThreadParam->TaskinPlay; if (curPlayTaskCount <= 0) { Sleep(30); continue; } k.clear(); pThreadParam->TaskinPlayID.clear(); costTime1 += std::chrono::duration_cast(std::chrono::system_clock::now() - begintime1).count(); //delete by lm 20180803 CUresult result = cuCtxPushCurrent(pThreadParam->cuCtx); //os << 5 << std::endl; auto begintime2 = std::chrono::system_clock::now(); getdata_flag: for (int i = 0; i < curTaskSize; i++) { //os << 5 << std::endl; if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) { //os << 6<< std::endl; if (pThreadParam->tasks[i].taskTcuvid->DxLockFrame(&frame) == 0) { //os << 7 << std::endl; if (!pThreadParam->tasks[i].task_algorithm_data.frame && frame.width > 0 && frame.height > 0) { //os << 8 << std::endl; //std::cout << " size: " << frame.size << "," << frame.width << "," << frame.height << " " << 3 * frame.size * frame.height << "\n"; cudaError_t cudaStatus = cudaMalloc((void**)&pThreadParam->tasks[i].task_algorithm_data.frame, 3 * frame.size * frame.height * sizeof(float)); ++total; if (cudaStatus != cudaSuccess) { fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus)); //os << 9 << std::endl; break; } pThreadParam->tasks[i].task_algorithm_data.height = frame.height; pThreadParam->tasks[i].task_algorithm_data.width = frame.width; pThreadParam->tasks[i].task_algorithm_data.size = frame.size; pThreadParam->tasks[i].frameImage = cv::Mat::zeros(frame.height, frame.width, CV_8UC3); pThreadParam->tasks[i].taskDataToRT = (float*)malloc(3 * frame.height * frame.width * sizeof(float)); AddTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID, 1, 1); //os << 10 << std::endl; } //copy decode data //os << 11 << std::endl; if (pThreadParam->tasks[i].task_algorithm_data.frame) { //os << 12 << std::endl; cudaStatus = cudaMemcpy(pThreadParam->tasks[i].task_algorithm_data.frame, frame.frame, 1.5 * frame.size * frame.height * sizeof(unsigned char), cudaMemcpyDeviceToDevice); if (cudaStatus != cudaSuccess) { //os << 13 << std::endl; fprintf(stderr, "cudaMemcpy failed: %s\n", cudaGetErrorString(cudaStatus)); } cuda_common::NV12ToRGBnot((CUdeviceptr)pThreadParam->tasks[i].task_algorithm_data.frame, pThreadParam->tasks[i].task_algorithm_data.size, (unsigned char *)pThreadParam->FrameTemp, pThreadParam->tasks[i].task_algorithm_data.width, pThreadParam->tasks[i].task_algorithm_data.height); cudaMemcpy(pThreadParam->tasks[i].task_algorithm_data.frame, pThreadParam->FrameTemp, 3 * pThreadParam->tasks[i].task_algorithm_data.width * pThreadParam->tasks[i].task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToDevice); k.insert(i); pThreadParam->TaskinPlayID.insert(pThreadParam->tasks[i].taskID); } else { //os << 14 << std::endl; std::cout << "NOT ALLOC: pThreadParam->tasks[i].taskDataToBackup.frame" << pThreadParam->tasks[i].task_algorithm_data.frame << std::endl; } pThreadParam->tasks[i].taskTcuvid->DxUnlockFrame(); } } else if (k.find(i) == k.end() && pThreadParam->tasks[i].taskState == PLAY && !pThreadParam->tasks[i].taskTcuvid->DxDecoderIsRun()) { //os << 15 << " " << pThreadParam->tasks[i].taskID << std::endl; pThreadParam->tasks[i].taskState = DECODEERROR; curPlayTaskCount--; FinishTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID); } } //os << 16 << std::endl; if (curPlayTaskCount <= 0) { //os << 17 << std::endl; Sleep(30); continue; } if (k.size() < curPlayTaskCount) { boost::this_thread::sleep(boost::posix_time::milliseconds(1)); //os << 18 << std::endl; goto getdata_flag; } //os << 19 << std::endl; cudaDeviceSynchronize(); //os << 20 << std::endl; //printf("finish decode\n"); #ifdef LOG_INFO #ifdef _MSC_VER QueryPerformanceCounter(&nEndTime); time_val_p = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; printf("part1 (decode time)(ms): %.2f \n", time_val_p); QueryPerformanceCounter(&nBeginTime); #else gettimeofday(&second_time, NULL); double time_val_p = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; printf("part1 (decode time)(ms) = %lf\n", time_val_p / 1000.0); gettimeofday(&first_time, NULL); #endif #endif //------------------------------ 统一BATCH处理 --------------------------------// ////////////////////////////////////////////////////////////// //// //// compose data -> batch //// ///////////////////////////////////////////////////////////// //----- 1/ 20batchsize VPT -----// //vector> deleteObjectID; //deleteObjectID.resize(curPlayTaskCount); //set::iterator iter = pThreadParam->TaskinPlayID.begin(); //for (int i = 0; i < curPlayTaskCount; i++) //{ // int w = pThreadParam->tasks[*iter].taskDataToBackup.width; // int h = pThreadParam->tasks[*iter].taskDataToBackup.height; // int npitch = pThreadParam->tasks[*iter].taskDataToBackup.size; // batch_img[i].set_data(w, h, npitch, (unsigned char *)pThreadParam->tasks[*iter].taskDataToBackup.frame); // iter++; //} /////////////////////////////////////////// //////// //////// algorithm process //////// ////////////////////////////////////////// //int flag = VPT_Process_GPU(pThreadParam->GetVPT_Handle(), batch_img, 0, curPlayTaskCount, pThreadParam->VPTResult, deleteObjectID); //----- 2/ 10+10 batchsize VPT -----// vector> deleteObjectID; set::iterator iter = pThreadParam->TaskinPlayID.begin(); /* if (pThreadParam->TaskinPlayID.size() != 12) { continue; } printf("begin 1000 VPT_Process_GPU\n"); std::this_thread::sleep_for(std::chrono::seconds(20));*/ int cur_batch_size = 0; if (pThreadParam->section_batch_size == 10) cur_batch_size = pThreadParam->section_batch_size; //如果是大显存 直接按照batch size是10的跑 else //小显存,batch size开始以5来跑,如果达到20了,以10来跑,中间的以batch/2来跑 { if (curPlayTaskCount <= 2 * pThreadParam->section_batch_size) cur_batch_size = pThreadParam->section_batch_size; else if (curPlayTaskCount >= 2 * MAX_BATCH) cur_batch_size = MAX_BATCH; else cur_batch_size = curPlayTaskCount / 2 + (curPlayTaskCount % 2); } //os << 21 << std::endl; //printf("cur_batch_size: %d\n", cur_batch_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; for (int i = 0; i < batchsize; i++) //先处理第一个MAX_BATCH { int w = pThreadParam->tasks[*iter].task_algorithm_data.width; int h = pThreadParam->tasks[*iter].task_algorithm_data.height; int npitch = pThreadParam->tasks[*iter].task_algorithm_data.size; batch_img[i].set_data(w, h, 3, (unsigned char *)pThreadParam->tasks[*iter].task_algorithm_data.frame); iter++; } vector> tempDeleteObjectID; tempDeleteObjectID.resize(batchsize); //for (int i = 0; i < 1000; ++i) { int flag = VPT_Process_GPU(pThreadParam->GetVPT_Handle(), batch_img, startbatch, batchsize, pThreadParam->VPTResult, tempDeleteObjectID); } for (auto iter : tempDeleteObjectID) { deleteObjectID.push_back(iter); } vector>().swap(tempDeleteObjectID); } //os << 22 << std::endl; /* printf("end 1000 VPT_Process_GPU\n"); std::this_thread::sleep_for(std::chrono::seconds(20));*/ #ifdef LOG_INFO #ifdef _MSC_VER QueryPerformanceCounter(&nEndTime); time_val_p = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; printf("part2(vpt process)(ms): %.2f \n", time_val_p); QueryPerformanceCounter(&nBeginTime); #else gettimeofday(&second_time, NULL); time_val_p = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; printf("part2 (vpt process)(ms) = %lf\n", time_val_p / 1000.0); gettimeofday(&first_time, NULL); #endif #endif // auto iter1 = pThreadParam->TaskinPlayID.begin(); // for (int i = 0; i < curPlayTaskCount; i++) // { // for (int c = 0; c < pThreadParam->VPTResult[i].objCount; c++) // { // int id = pThreadParam->VPTResult[i].obj[c].id; // if (std::find(ObjectID.begin(), ObjectID.end(), OBJ_KEY{ *iter1, id }) != ObjectID.end()) // { // cerr << " ID repeat :" << *iter1 << id <VPTResult[i].objCount); if (pThreadParam->VPTResult[i].objCount == 0) { video_object_info newObjInfo; newObjInfo.task_id = *iter; newObjInfo.task_frame_count = pThreadParam->tasks[*iter].taskFrameCount; newObjInfo.object_id = -1; newObjInfo.left = 0; newObjInfo.right = 0; newObjInfo.top = 0; newObjInfo.bottom = 0; newObjInfo.index = 0; newObjInfo.confidence = 0; if (pThreadParam->taskObjInfoCallbackFunc != NULL) pThreadParam->taskObjInfoCallbackFunc(&newObjInfo); } //os << 23 << std::endl; //实时查看模块 bool view = false; int frameHeight = pThreadParam->tasks[*iter].task_algorithm_data.height; int frameWidth = pThreadParam->tasks[*iter].task_algorithm_data.width; if (*iter == pThreadParam->viewTaskID) { //os << 24 << std::endl; cudaStatus = cudaMemcpy(pThreadParam->tasks[*iter].taskDataToRT, pThreadParam->tasks[*iter].task_algorithm_data.frame, 3 * frameHeight * frameWidth * sizeof(float), cudaMemcpyDeviceToHost); for (int i = 0; i < frameHeight; i++) { uchar *pts = pThreadParam->tasks[*iter].frameImage.ptr(i); for (int j = 0; j < frameWidth; j++) { //BBB...GGG...RRR... //pts[3 * j] = saturate_cast(pThreadParam->tasks[*iter].taskDataToRT[i * frameWidth + j]);/// 255.0f; //pts[3 * j + 1] = saturate_cast(pThreadParam->tasks[*iter].taskDataToRT[frameWidth * frameHeight + i * frameWidth + j]);// / 255.0f; //pts[3 * j + 2] = saturate_cast(pThreadParam->tasks[*iter].taskDataToRT[frameWidth * frameHeight * 2 + i * frameWidth + j]);// / 255.0f; //BGRBGRBGR...... pts[3 * j] = saturate_cast(pThreadParam->tasks[*iter].taskDataToRT[i * frameWidth * 3 + j * 3]);// / 255.0f; pts[3 * j + 1] = saturate_cast(pThreadParam->tasks[*iter].taskDataToRT[i * frameWidth * 3 + j * 3 + 1]);// / 255.0f ; pts[3 * j + 2] = saturate_cast(pThreadParam->tasks[*iter].taskDataToRT[i * frameWidth * 3 + j * 3 + 2]);// / 255.0f ; } } //os << 25 << std::endl; view = true; } 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]; int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 //os << 26 << std::endl; for (int c = 0; c < pThreadParam->VPTResult[i].objCount; c++) { OBJ_KEY newObj = { (*iter), pThreadParam->VPTResult[i].obj[c].id }; //os << 27 << std::endl; video_object_info newObjInfo; newObjInfo.task_id = *iter; newObjInfo.task_frame_count = pThreadParam->tasks[*iter].taskFrameCount; newObjInfo.object_id = pThreadParam->VPTResult[i].obj[c].id; newObjInfo.left = pThreadParam->VPTResult[i].obj[c].left; newObjInfo.right = pThreadParam->VPTResult[i].obj[c].right; newObjInfo.top = pThreadParam->VPTResult[i].obj[c].top; newObjInfo.bottom = pThreadParam->VPTResult[i].obj[c].bottom; if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) newObjInfo.index = pThreadParam->VPTResult[i].obj[c].index; else newObjInfo.index = pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index; newObjInfo.confidence = pThreadParam->VPTResult[i].obj[c].confidence; if (pThreadParam->taskObjInfoCallbackFunc != NULL) { //os << 28 << std::endl; pThreadParam->taskObjInfoCallbackFunc(&newObjInfo); } 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; 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); //cout << pThreadParam->VPTResult[i].obj[c].left << " " << pThreadParam->VPTResult[i].obj[c].top << " " << //pThreadParam->VPTResult[i].obj[c].right << " " << pThreadParam->VPTResult[i].obj[c].bottom << endl; #ifdef _MSC_VER string resss = "" + to_string(newObjInfo.index) + " " + ObjTypes[newObjInfo.index]; putTextZH(pThreadParam->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); #endif } //os << 29 << std::endl; 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; if (pThreadParam->m_snaphot_helper.snapShotInfo.find(newObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) { //os << 30 << std::endl; if (LegalMinArea(cur_real_width, cur_real_height, pThreadParam->tasks[*iter].task_min_boxsize[cur_real_index])) { //os << 31 << std::endl; //--------------------- 保存快照视频截图 -----------------------------// 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; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index = pThreadParam->VPTResult[i].obj[c].index; //pThreadParam->snapShotInfo[newObj].index = pThreadParam->VPTResult[i].obj[c].index; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->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); 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 pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame = NULL; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.frame = NULL; if (pThreadParam->tasks[*iter].folderName != NULL) { //os << 32 << std::endl; auto begintime = std::chrono::system_clock::now(); FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); /*std::async(std::launch::async, [&newObj, &frame_id, iter, pThreadParam]() { pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); });*/ //cudaError_t cudastate = cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.frame, frameWidth * frameHeight * IMG_CHANNELS * sizeof(unsigned char)); //if (cudaStatus != cudaSuccess) { // //os << 33 << std::endl; // fprintf(stderr, "cudaMemcpy failed: %s\n", cudaGetErrorString(cudaStatus)); //} //cudaMemcpy(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.frame, pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth * frameHeight * IMG_CHANNELS * sizeof(unsigned char), cudaMemcpyDeviceToDevice); pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.height = frameHeight; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.width = frameWidth; costTime +=std::chrono::duration_cast(std::chrono::system_clock::now() - begintime).count(); } //--------------------- 保存快照抠图 -----------------------------/ int vLeft = 0; int vTop = 0; 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 }); //os << 34 << std::endl; //delete by lm 20180803 CUresult result = cuCtxPushCurrent(pThreadParam->cuCtx); if (pThreadParam->tasks[*iter].folderNameLittle != NULL) { //os << 35 << std::endl; int cur_width = 0; int cur_height = 0; if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) { cur_width = HP_WIDTH; cur_height = HP_HEIGHT; } else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->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)) { cur_width = VEHICLE_WIDTH; cur_height = VEHICLE_HEIGHT; } else //其余类别 { cur_width = VEHICLE_WIDTH; cur_height = VEHICLE_HEIGHT; /* cur_width = vRight - vLeft; cur_height = vBottom - vTop;*/ } if (cur_width != 0 && cur_height != 0) { ++total; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame = pThreadParam->m_snaphot_helper.snapShotCache.get_frame(); pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = cur_height; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = cur_width; //printf("first add: %d %d %d %d %d %d\n", pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height, //cur_width, cur_height, i, newObjInfo.taskID); snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; snapshot_left[copy_obj_count] = vLeft; snapshot_top[copy_obj_count] = vTop; snapshot_right[copy_obj_count] = vRight; snapshot_bottom[copy_obj_count] = vBottom; snapshot_dst_width[copy_obj_count] = cur_width; snapshot_dst_height[copy_obj_count++] = cur_height; //partMemResizeImage((float*)pThreadParam->tasks[*iter].taskDataToBackup.frame, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height, // (unsigned char*)pThreadParam->snapShotInfo[newObj].snapShotLittle.frame, &vLeft, &vTop, &vRight, &vBottom, cur_width, cur_height, 0, 0, 0, 1, 1, 1); } } //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); } } else { //os << 36 << std::endl; 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; if (pThreadParam->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; } else { if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index == pThreadParam->VPTResult[i].obj[c].index) pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count++; else pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.count--; } if (oldIndex != pThreadParam->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 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); 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) { //os << 37 << std::endl; 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_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), 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; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].confidence = pThreadParam->VPTResult[i].obj[c].confidence; if (pThreadParam->tasks[*iter].folderName != NULL) { auto begintime = std::chrono::system_clock::now(); FRAME_KEY frame_id = { (*iter),pThreadParam->tasks[*iter].taskFrameCount }; /* std::async(std::launch::async, [&newObj, &frame_id, iter, pThreadParam]() { pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); });*/ pThreadParam->m_snaphot_helper.ImgSaveCache.insert(newObj, frame_id, pThreadParam->tasks[*iter].task_algorithm_data); costTime += std::chrono::duration_cast(std::chrono::system_clock::now() - begintime).count(); /*cudaMemcpy(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShot.frame, pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth * frameHeight * IMG_CHANNELS * sizeof(unsigned char), cudaMemcpyDeviceToDevice); cudaError_t cudaStatus = cudaGetLastError(); if (cudaStatus != cudaSuccess) { printf("cudaMemcpy launch failed: %s\n", cudaGetErrorString(cudaStatus)); }*/ } //--------------------- 保存快照抠图 -----------------------------// int vLeft = 0; int vTop = 0; 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); //os << 38 << std::endl; //delete by lm 20180803 CUresult result = cuCtxPushCurrent(pThreadParam->cuCtx); if (pThreadParam->tasks[*iter].folderNameLittle != NULL) { //os << 39 << std::endl; if (0 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) { //os << 40 << std::endl; if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) { //os << 41 << std::endl; //cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 //++total_free; //cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HP_WIDTH * HP_HEIGHT * sizeof(unsigned char)); //++total; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HP_WIDTH; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HP_HEIGHT; } //printf("update: %d %d %d %d %d %d %d %d %d\n", 0, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height, //pThreadParam->snapShotInfo[newObj].snapShotLittle.width, pThreadParam->snapShotInfo[newObj].snapShotLittle.height, HP_WIDTH, HP_HEIGHT, i, newObjInfo.objectID); snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; snapshot_left[copy_obj_count] = vLeft; snapshot_top[copy_obj_count] = vTop; snapshot_right[copy_obj_count] = vRight; snapshot_bottom[copy_obj_count] = vBottom; snapshot_dst_width[copy_obj_count] = HP_WIDTH; snapshot_dst_height[copy_obj_count++] = HP_HEIGHT; //partMemResizeImage((float*)pThreadParam->tasks[*iter].taskDataToBackup.frame, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height, // (unsigned char*)pThreadParam->snapShotInfo[newObj].snapShotLittle.frame, &vLeft, &vTop, &vRight, &vBottom, HP_WIDTH, HP_HEIGHT, 0, 0, 0, 1, 1, 1); } else if (1 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index || 2 == pThreadParam->m_snaphot_helper.snapShotInfo[newObj].index.index) { //os << 42 << std::endl; if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) { //os << 43 << std::endl; //cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 //++total_free; //cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * HCP_WIDTH * HCP_HEIGHT * sizeof(unsigned char)); //++total; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = HCP_WIDTH; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = HCP_HEIGHT; } //printf("update: %d %d %d %d %d %d %d\n", 1, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height, //pThreadParam->snapShotInfo[newObj].snapShotLittle.width, pThreadParam->snapShotInfo[newObj].snapShotLittle.height, HCP_WIDTH, HCP_HEIGHT); snapshot_image_data[copy_obj_count] = (unsigned char*)pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame; snapshot_left[copy_obj_count] = vLeft; snapshot_top[copy_obj_count] = vTop; snapshot_right[copy_obj_count] = vRight; snapshot_bottom[copy_obj_count] = vBottom; snapshot_dst_width[copy_obj_count] = HCP_WIDTH; snapshot_dst_height[copy_obj_count++] = HCP_HEIGHT; //partMemResizeImage((float*)pThreadParam->tasks[*iter].taskDataToBackup.frame, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height, // (unsigned char*)pThreadParam->snapShotInfo[newObj].snapShotLittle.frame, &vLeft, &vTop, &vRight, &vBottom, HCP_WIDTH, HCP_HEIGHT, 0, 0, 0, 1, 1, 1); } 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)) { //os << 43.1 << std::endl; if (pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width != VEHICLE_WIDTH || pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height != VEHICLE_HEIGHT) { //os << 44 << std::endl; //cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 //++total_free; //cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * VEHICLE_WIDTH * VEHICLE_HEIGHT * sizeof(unsigned char)); //++total; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = VEHICLE_WIDTH; pThreadParam->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_left[copy_obj_count] = vLeft; snapshot_top[copy_obj_count] = vTop; snapshot_right[copy_obj_count] = vRight; snapshot_bottom[copy_obj_count] = vBottom; snapshot_dst_width[copy_obj_count] = VEHICLE_WIDTH; snapshot_dst_height[copy_obj_count++] = VEHICLE_HEIGHT; //printf("before update: %d %d %d %d %d %d %d %d %d %d\n", 4, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height, //pThreadParam->snapShotInfo[newObj].snapShotLittle.width, pThreadParam->snapShotInfo[newObj].snapShotLittle.height, vLeft[0], vTop[0], vRight[0], vBottom[0], *iter); //partMemResizeImage((float*)pThreadParam->tasks[*iter].taskDataToBackup.frame, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height, // (unsigned char*)pThreadParam->snapShotInfo[newObj].snapShotLittle.frame, &vLeft, &vTop, &vRight, &vBottom, VEHICLE_WIDTH, VEHICLE_HEIGHT, 0, 0, 0, 1, 1, 1); } else { //os << 45 << std::endl; //cudaFree(pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame); //释放显存 //++total_free; //cudaMalloc((void**)&pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.frame, 3 * (vBottom - vTop)*(vRight - vLeft) * sizeof(unsigned char)); //++total; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.height = VEHICLE_WIDTH; pThreadParam->m_snaphot_helper.snapShotInfo[newObj].snapShotLittle.width = VEHICLE_HEIGHT; //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((float*)pThreadParam->tasks[*iter].taskDataToBackup.frame, pThreadParam->tasks[*iter].taskDataToBackup.width, pThreadParam->tasks[*iter].taskDataToBackup.height, //(float*)pThreadParam->snapShotInfo[newObj].snapShotLittle.frame, left, top, right, bottom); } //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); } pThreadParam->m_snaphot_helper.snapShotInfo[newObj].lastArea = (bottom - top)*(right - left); } //copy_obj_count++; } //QueryPerformanceCounter(&nBeginTime); //os << 46 << std::endl; if (0 != copy_obj_count) { //os << 47 << std::endl; PartMemResizeBatch((unsigned char*)pThreadParam->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); } if (view) { DrawTracker(pThreadParam->VPT_Handle, *iter, &pThreadParam->tasks[*iter].frameImage); if (pThreadParam->tasks[*iter].taskRealTimeCallbackFunc != NULL) pThreadParam->tasks[*iter].taskRealTimeCallbackFunc(pThreadParam->tasks[*iter].frameImage.data, pThreadParam->tasks[*iter].frameImage.rows, pThreadParam->tasks[*iter].frameImage.cols); } pThreadParam->tasks[*iter].taskFrameCount += SKIP_FRMAE; iter++; //os << 48 << std::endl; } #ifdef LOG_INFO #ifdef _MSC_VER QueryPerformanceCounter(&nEndTime); time_val_p = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; printf("part3(snapshot process)(ms): %.2f \n", time_val_p); QueryPerformanceCounter(&nBeginTime); #else gettimeofday(&second_time, NULL); time_val_p = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; printf("part3 (snapshot process)(ms) = %lf\n", time_val_p / 1000.0); gettimeofday(&first_time, NULL); #endif #endif costTime2 += std::chrono::duration_cast(std::chrono::system_clock::now() - begintime2).count(); auto begintime3 = std::chrono::system_clock::now(); auto task_iter = pThreadParam->TaskinPlayID.begin(); pThreadParam->AttributionAnalysis = false; //该帧结束,还未进行过二次属性分析 //os << 49 << std::endl; int total_img = 0; for (int i = 0; i < curPlayTaskCount; i++) { for (int j = 0; j < deleteObjectID[i].size(); j++) { total_img += deleteObjectID[i].size(); OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; //cerr << "deleteObj " << *task_iter << " " << deleteObjectID[i][j] << endl; if (pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj) == pThreadParam->m_snaphot_helper.snapShotInfo.end()) continue; auto iter = pThreadParam->m_snaphot_helper.snapShotInfo.find(deleteObj); iter->second.finishTracker = true; pThreadParam->SaveResultInFile(iter->first, iter->second); //if (iter->second.snapShot.frame) // cudaFree(iter->second.snapShot.frame); ////delete by lm 20180803 CUresult result = cuCtxPushCurrent(pThreadParam->cuCtx); //if (iter->second.snapShotLittle.frame) // cudaFree(iter->second.snapShotLittle.frame); ////delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); //iter = pThreadParam->snapShotInfo.erase(iter);//modified by dyq } task_iter++; } //printf("curPlayTaskCount: %d, total img: %d\n", curPlayTaskCount, total_img); //os << 50 << std::endl; for (int i = 0; i < deleteObjectID.size(); i++) vector().swap(deleteObjectID[i]); vector>().swap(deleteObjectID); //开始进行一次二次属性分析 pThreadParam->m_snaphot_helper.object_attri_analysis(); cudaError_t cudaStatus = cudaGetLastError(); if (cudaStatus != cudaSuccess) { printf("object_attri_analysis last error: %s\n", cudaGetErrorString(cudaStatus)); } #ifdef _MSC_VER #ifdef LOG_INFO QueryPerformanceCounter(&nEndTime); time_val_p = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; printf("part4 (secondary analyze)(ms): %.2f \n", time_val_p); #endif QueryPerformanceCounter(&nSaveEndTime); time_val = (double)(nSaveEndTime.QuadPart - nSaveBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; //printf("process/frame time_val(ms): %.2f\n", time_val); #else #ifdef LOG_INFO gettimeofday(&second_time, NULL); time_val_p = (second_time.tv_sec - first_time.tv_sec) * 1000000 + second_time.tv_usec - first_time.tv_usec; printf("part4 (secondary analyze)(ms) = %lf\n", time_val_p / 1000.0); #endif gettimeofday(&second_time_total, NULL); time_val = (second_time_total.tv_sec - first_time_total.tv_sec) * 1000000 + second_time_total.tv_usec - first_time_total.tv_usec; // printf("process/frame time_val(ms) = %.2f\n", time_val / 1000.0); #endif boost::this_thread::sleep(boost::posix_time::milliseconds(1)); costTime3 += std::chrono::duration_cast(std::chrono::system_clock::now() - begintime3).count(); } } //catch (exception &e) { //os << 51 << e.what()<< std::endl; /* std::cout << e.what() << std::endl; exit(-1);*/ } std::cout << "==================== Process Thread is Finished: " << std::endl; Sleep(1000); printf("image time : %d\n", costTime); printf("save time :%d\n", costSave); printf("part1 time : %d\n", costTime1); printf("part2 time :%d\n", costTime2); printf("part3 time :%d\n", costTime3); printf("total cudamalloc size: %d\n", total); printf("total cudafree size: %d\n", total_free); //os << 52 <m_snaphot_helper.snapShotInfo.size() << std::endl; pThreadParam->m_snaphot_helper.snapShotInfo.clear(); { boost::mutex::scoped_lock lock(pThreadParam->process_thread_mutex); pThreadParam->ProcessFlag = false; // printf("1499 set ProcessFlag false\n"); } if (batch_img != NULL) { delete[] batch_img; batch_img = NULL; } return 0; } void check_thread(void* handle) { int res = -1; #ifdef __linux__ char* wtime = new char[15]{}; memset(wtime, 0, 15); #endif CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)handle; while (1) { //printf("xxx check status on process...\n"); #ifdef _WIN32 res = sy_licence(productSN); #elif __linux__ res = sy_licence(productSN, wtime); //printf("--------------wtime in thread: %s, status: %d\n", wtime, licence_status); #endif if (res < 0) { pThreadParam->licence_status = pThreadParam->licence_status - 1; } else { if (pThreadParam->licence_status < 0) { pThreadParam->licence_status = 0; } } boost::this_thread::sleep(boost::posix_time::seconds(600)); //10min //boost::this_thread::sleep(boost::posix_time::milliseconds(10); } #ifdef __linux__ if (wtime) { delete[] wtime; wtime = NULL; } #endif } //DWORD SnapshotThreadProcess(LPVOID param, int index) //{ // CMutliSourceVideoProcess *pThreadParam = (CMutliSourceVideoProcess *)param; // // int startIndex = index * 4; //每个线程处理4路 // int endIndex = (index + 1) * 4; // try // { // while (true) // { // if (!pThreadParam->snapshotProcessQueue.empty()) // { // SNAPSHOT_PROCESS_UNIT ssunit; // { // boost::mutex::scoped_lock lock(pThreadParam->threadMutex); // ssunit = pThreadParam->snapshotProcessQueue.front(); // pThreadParam->snapshotProcessQueue.pop(); // } // // int resCount = ssunit.imgSmall.size(); // // for (int i = 0; i < resCount; i++) // { // cudaFree(ssunit.imgSmall[i].frame); // cudaFree(ssunit.imgBig[i].frame); // } // // vector().swap(ssunit.imgSmall); // vector().swap(ssunit.imgBig); // vector().swap(ssunit.imgVPTResult); // // cout << "snapshotProcessQueue size: " << pThreadParam->snapshotProcessQueue.size() << endl; // // pThreadParam->beginSaveSnapshot = false; // } // // boost::this_thread::sleep(boost::posix_time::milliseconds(10)); // } // } // catch (...) // { // std::cout << "Save Process Thread is Finished" << std::endl; // } // // return 0; //} //char filename[260]; //for (int ii = 0; ii < copy_obj_count; ii++) //{ // unsigned char* cpu_data = new unsigned char[3 * snapshot_dst_width[ii] * snapshot_dst_height[ii]]; // cudaMemcpy(cpu_data, snapshot_image_data[ii], 3 * snapshot_dst_width[ii] * snapshot_dst_height[ii] * sizeof(unsigned char), cudaMemcpyDeviceToHost); // cv::Mat img(snapshot_dst_height[ii], snapshot_dst_width[ii], CV_8UC3, cpu_data); // // sprintf(filename, "ss/%d.jpg", ii); // cv::imwrite(filename, img); //} //int CMutliSourceVideoProcess::SaveSnapshot(char* mode, unsigned char* imgData, int width, int height, int taskID, int objID, int recFlag, int left = 0, int top = 0, int right = 0, int bottom = 0) //{ // char snapShotName[260]; // // if (recFlag) /*save video screenshot*/ // { // sprintf(snapShotName, "%s/%d.jpg", tasks[taskID].folderName, objID); // } // // else /*save obj snapshot*/ // { // sprintf(snapShotName, "%s/%d.jpg", tasks[taskID].folderNameLittle, objID); // } // // if (strcmp(mode, "cpu") == 0 && recFlag) /*CPU save video screenshot*/ // { // cv::Mat newVideoImg(height, width, CV_8UC3, imgData); // imwrite(snapShotName, newVideoImg); // // //for (int j = 0; j < height; j++) // //{ // // uchar *pts = objSnapshot.ptr(j); // // for (int i = 0; i < width; i++) // // { // // // pts[3 * i] = saturate_cast(imgData[j*width + i]); //b // // // pts[3 * i + 1] = saturate_cast(imgData[height*width + j*width + i]); //g // // // pts[3 * i + 2] = saturate_cast(imgData[2 * height*width + j*width + i]); //r // // // pts[3 * i] = saturate_cast(imgData[j*width * 3 + i * 3]); //b // // pts[3 * i + 1] = saturate_cast(imgData[j*width * 3 + i * 3 + 1]); //g // // pts[3 * i + 2] = saturate_cast(imgData[j*width * 3 + i * 3 + 2]); //r // // } // //} // // //cv::rectangle(objSnapshot, cv::Rect(left, top, right - left, bottom - top), cv::Scalar(0, 255, 0), 1, 1, 0); // //imwrite(snapShotName, objSnapshot); // } // else if (strcmp(mode, "cpu") == 0 && !recFlag) /*CPU save obj snapshot*/ // { // cv::Mat newSnapshot(height, width, CV_8UC3, imgData); // //imwrite(snapShotName, newSnapshot); // // // SNAPSHOT_IMAGE_UNIT cur_image; // cur_image.file_name = snapShotName; // cur_image.original_size.original_width = (right - left); // cur_image.original_size.original_height = (bottom - top); // newSnapshot.copyTo(cur_image.image); // //cv::imwrite(snapShotName, cur_image.image); // { // boost::mutex::scoped_lock lock(threadMutex); // snapshotImageQueue.push(cur_image); // } // newSnapshot.release(); // } // else if (strcmp(mode, "gpu") == 0 && recFlag) /*GPU save video screenshot*/ // { // //delete by lm 20180803 CUresult result = cuCtxPushCurrent(cuCtx); // drawImageOnGPU(imgData, width, height, left, top, right, bottom); // // // showGpuMat(imgData, height, width); // // if (saveJPEG(snapShotName, imgData) != 0) // { // SaveSnapshot("cpu", imgData, width, height, taskID, objID, recFlag, left, top, right, bottom); // //std::cout << "saving: " << snapShotName; // } // //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); // } // else // { // //delete by lm 20180803 CUresult result = cuCtxPushCurrent(cuCtx); // //showGpuMat(imgData, height, width); // // if (saveJPEG(snapShotName, imgData, width, height) != 0) // { // SaveSnapshot("cpu", imgData, width, height, taskID, objID, recFlag, left, top, right, bottom); // //std::cout << "saving: " << snapShotName; // } // //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); // } // // return 1; //} // // //int CMutliSourceVideoProcess::SaveSnapshot(char* mode, float* imgData, int width, int height, int taskID, int objID, int recFlag, int left = 0, int top = 0, int right = 0, int bottom = 0) //{ // char snapShotName[260]; // // if (recFlag) /*save video screenshot*/ // { // sprintf(snapShotName, "%s/%d.jpg", tasks[taskID].folderName, objID); // } // // else /*save obj snapshot*/ // { // sprintf(snapShotName, "%s/%d.jpg", tasks[taskID].folderNameLittle, objID); // } // // if (strcmp(mode, "cpu") == 0 && recFlag) /*CPU save video screenshot*/ // { // cv::Mat newVideoImg(height, width, CV_32FC3, imgData); // imwrite(snapShotName, newVideoImg); // //for (int j = 0; j < height; j++) // //{ // // uchar *pts = objSnapshot.ptr(j); // // for (int i = 0; i < width; i++) // // { // // // pts[3 * i] = saturate_cast(imgData[j*width + i]); //b // // // pts[3 * i + 1] = saturate_cast(imgData[height*width + j*width + i]); //g // // // pts[3 * i + 2] = saturate_cast(imgData[2 * height*width + j*width + i]); //r // // // pts[3 * i] = saturate_cast(imgData[j*width * 3 + i * 3]); //b // // pts[3 * i + 1] = saturate_cast(imgData[j*width * 3 + i * 3 + 1]); //g // // pts[3 * i + 2] = saturate_cast(imgData[j*width * 3 + i * 3 + 2]); //r // // } // //} // // //cv::rectangle(objSnapshot, cv::Rect(left, top, right - left, bottom - top), cv::Scalar(0, 255, 0), 1, 1, 0); // //imwrite(snapShotName, objSnapshot); // } // else if (strcmp(mode, "cpu") == 0 && !recFlag) /*CPU save obj snapshot*/ // { // cv::Mat newSnapshot(height, width, CV_32FC3, imgData); // //imwrite(snapShotName, newSnapshot); // newSnapshot.release(); // // SNAPSHOT_IMAGE_UNIT cur_image; // cur_image.file_name = snapShotName; // newSnapshot.copyTo(cur_image.image); // // { // boost::mutex::scoped_lock lock(threadMutex); // snapshotImageQueue.push(cur_image); // } // // } // else if (strcmp(mode, "gpu") == 0 && recFlag) /*GPU save video screenshot*/ // { // //delete by lm 20180803 CUresult result = cuCtxPushCurrent(cuCtx); // drawImageOnGPU(imgData, width, height, left, top, right, bottom); // // // // if (saveJPEG(snapShotName, imgData) != 0) // { // SaveSnapshot("cpu", imgData, width, height, taskID, objID, recFlag, left, top, right, bottom); // } // //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); // } // else // { // //delete by lm 20180803 CUresult result = cuCtxPushCurrent(cuCtx); // if (saveJPEG(snapShotName, imgData, width, height) != 0) // { // SaveSnapshot("cpu", imgData, width, height, taskID, objID, recFlag, left, top, right, bottom); // } // //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); // } // // return 1; //} //void CMutliSourceVideoProcess::SnapshotResCallbackFunc(OBJ_KEY obj_key, OBJ_VALUE obj_value, void* analysisRes) //{ // char snapShotName[260]; // // video_object_snapshot newVideoObj; // newVideoObj.task_id = obj_key.videoID; // newVideoObj.object_id = obj_key.objID; // int cur_task_id = newVideoObj.task_id; // newVideoObj.left = obj_value.box.left * tasks[cur_task_id].taskHeightWidthRatio.width; // newVideoObj.right = obj_value.box.right * tasks[cur_task_id].taskHeightWidthRatio.width; // newVideoObj.top = obj_value.box.top * tasks[cur_task_id].taskHeightWidthRatio.height; // newVideoObj.bottom = obj_value.box.bottom * tasks[cur_task_id].taskHeightWidthRatio.height; // newVideoObj.confidence = obj_value.confidence; // // if (tasks[cur_task_id].folderName != NULL) // sprintf(snapShotName, "%s%d.jpg", tasks[cur_task_id].folderName, newVideoObj.object_id); // else // sprintf(snapShotName, ""); // // strcpy(newVideoObj.video_image_path, snapShotName); // // if (tasks[cur_task_id].folderNameLittle != NULL) // sprintf(snapShotName, "%s%d.jpg", tasks[newVideoObj.task_id].folderNameLittle, newVideoObj.object_id); // else // sprintf(snapShotName, ""); // strcpy(newVideoObj.snapshot_image_path, snapShotName); // // strcpy(newVideoObj.obj_type, ObjTypes[obj_value.index.index].c_str()); // newVideoObj.object_type_index = obj_value.index.index;// add by dyq // // if (tasks[obj_key.videoID].taskTotalFrameCount == -1 || tasks[obj_key.videoID].taskTotalFrameCount == 0) // newVideoObj.progress = 0; // else // newVideoObj.progress = (double)tasks[obj_key.videoID].taskFrameCount / tasks[obj_key.videoID].taskTotalFrameCount; // // newVideoObj.analysisRes = NULL; // // if (NULL != analysisRes) // { // if (0 == obj_value.index.index) // { // newVideoObj.analysisRes = new hp_res; // memcpy(newVideoObj.analysisRes, analysisRes, sizeof(hp_res)); // } // else if (1 == obj_value.index.index || 2 == obj_value.index.index) // { // newVideoObj.analysisRes = new hcp_res; // memcpy(newVideoObj.analysisRes, analysisRes, sizeof(hcp_res)); // } // 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) // { // newVideoObj.analysisRes = new vehicle_res; // memcpy(newVideoObj.analysisRes, analysisRes, sizeof(vehicle_res)); // } // } // // // if (tasks[cur_task_id].taskObjCallbackFunc != NULL) // tasks[cur_task_id].taskObjCallbackFunc(&newVideoObj); // // if (newVideoObj.analysisRes != NULL) // { // delete newVideoObj.analysisRes; // newVideoObj.analysisRes = NULL; // } //} // // //void CMutliSourceVideoProcess::HPAnalysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool flag) //若flag==true立即进行二次属性分析 //{ // while (flag && !count_person.empty()) // { // const int cur_batch_size = OBJ_BATCH_COUNT < count_person.size() ? OBJ_BATCH_COUNT : count_person.size(); // vector erase_obj_key; // // for (int i = 0; i < cur_batch_size; i++) // { // OBJ_KEY cur_obj_key = count_person.front(); // erase_obj_key.push_back(cur_obj_key); // batch_hp[i].set_data(HP_WIDTH, HP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // count_person.pop(); // } // // hp_res *result = new hp_res[OBJ_BATCH_COUNT]; // HumanParsing_Process(GetHP_Handle(), batch_hp, OBJ_BATCH_COUNT, result); // // //删除已经进行保存和二次属性分析的目标 // int resIndex = 0; // for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(iter_key); // // if (iter == snapShotInfo.end()) // resIndex++; //cout << iter_key.videoID << " " << iter_key.objID << " cant find" << endl; // else // { // hp_res curRes; // memcpy(&curRes, &result[resIndex++], sizeof(hp_res)); // //CPUSaveImage(iter_key, snapShotInfo[iter_key]); // SnapshotResCallbackFunc(iter_key, snapShotInfo[iter_key], &curRes); // // if (iter->second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // } // snapShotInfo.erase(iter);//modified by dyq // } // } // // erase_obj_key.clear(); // vector().swap(erase_obj_key); // // if (result != NULL) // { // delete[] result; // result = NULL; // } // } // // if (!flag) // { // count_person.push(obj_key); // // if (count_person.size() >= OBJ_BATCH_COUNT && !AttributionAnalysis) // { // //#ifdef LOG_INFO // std::cout << "------ begin HumanParsing_Process -----" << std::endl; //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // // AttributionAnalysis = true; //进行了二次属性分析 // vector erase_obj_key; // // // for (int i = 0; i < OBJ_BATCH_COUNT; i++) // { // OBJ_KEY cur_obj_key = count_person.front(); // erase_obj_key.push_back(cur_obj_key); // batch_hp[i].set_data(HP_WIDTH, HP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // count_person.pop(); // } // // hp_res *result = new hp_res[OBJ_BATCH_COUNT]; // HumanParsing_Process(GetHP_Handle(), batch_hp, OBJ_BATCH_COUNT, result); // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // std::printf("HumanParsing_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("HumanParsing_Process = %lf ms\n", time_val); // */ //#endif //#endif // // // //删除已经进行保存和二次属性分析的目标 // int resIndex = 0; // for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(iter_key); // // if (iter == snapShotInfo.end()) // resIndex++; //cout << iter_key.videoID << " " << iter_key.objID << " cant find" << endl; // else // { // hp_res curRes; // memcpy(&curRes, &result[resIndex++], sizeof(hp_res)); // //CPUSaveImage(iter_key, snapShotInfo[iter_key]); // SnapshotResCallbackFunc(iter_key, snapShotInfo[iter_key], &curRes); // if (iter->second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // } // snapShotInfo.erase(iter);//modified by dyq // } // } // // erase_obj_key.clear(); // vector().swap(erase_obj_key); // // if (result != NULL) // { // delete[] result; // result = NULL; // } // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // std::printf("total: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("HumanParsing_Process = %lf ms\n", time_val); // */ //#endif // std::cout << "----- end HumanParsing_Process -----" << std::endl; //#endif // } // } // // //} //void CMutliSourceVideoProcess::HCPAnalysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool flag) //若flag==true立即进行二次属性分析 //{ // while (flag && !count_bike.empty()) // { // const int cur_batch_size = OBJ_BATCH_COUNT < count_bike.size() ? OBJ_BATCH_COUNT : count_bike.size(); // vector erase_obj_key; // // for (int i = 0; i < cur_batch_size; i++) // { // OBJ_KEY cur_obj_key = count_bike.front(); // erase_obj_key.push_back(cur_obj_key); // batch_hcp[i].set_data(HP_WIDTH, HP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // count_bike.pop(); // } // // hcp_res *result = new hcp_res[OBJ_BATCH_COUNT]; // HumanCarParsing_Process(GetHCP_Handle(), batch_hcp, OBJ_BATCH_COUNT, result); // // int resIndex = 0; // for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(iter_key); // if (iter == snapShotInfo.end()) // resIndex++; // else // { // hcp_res curRes; // memcpy(&curRes, &result[resIndex++], sizeof(hcp_res)); // //CPUSaveImage(iter_key, snapShotInfo[iter_key]); // SnapshotResCallbackFunc(iter_key, snapShotInfo[iter_key], &curRes); // if (iter->second.snapShotLittle.frame) // cudaFree(iter->second.snapShotLittle.frame); // snapShotInfo.erase(iter);//modified by dyq // } // } // // erase_obj_key.clear(); // vector().swap(erase_obj_key); // // if (result != NULL) // { // delete[] result; // result = NULL; // } // } // // if (!flag) // { // count_bike.push(obj_key); // // if (count_bike.size() >= OBJ_BATCH_COUNT && !AttributionAnalysis) // { // AttributionAnalysis = true; // vector erase_obj_key; //#ifdef LOG_INFO // std::cout << "----- begin HumanCarParsing_Process -----" << endl; //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // for (int i = 0; i < OBJ_BATCH_COUNT; i++) // { // OBJ_KEY cur_obj_key = count_bike.front(); // erase_obj_key.push_back(cur_obj_key); // batch_hcp[i].set_data(HCP_WIDTH, HCP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // count_bike.pop(); // } // // hcp_res *result = new hcp_res[OBJ_BATCH_COUNT]; // HumanCarParsing_Process(GetHCP_Handle(), batch_hcp, OBJ_BATCH_COUNT, result); // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("HumanCarParsing_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("HumanCarParsing_Process = %lf ms\n", time_val); // */ //#endif // cout << "----- end HumanCarParsing_Process -----" << endl; //#endif // int resIndex = 0; // for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(iter_key); // // if (iter == snapShotInfo.end()) // resIndex++; // else // { // hcp_res curRes; // memcpy(&curRes, &result[resIndex++], sizeof(hcp_res)); // //CPUSaveImage(iter_key, snapShotInfo[iter_key]); // SnapshotResCallbackFunc(iter_key, snapShotInfo[iter_key], &curRes); // if (iter->second.snapShotLittle.frame) // cudaFree(iter->second.snapShotLittle.frame); // snapShotInfo.erase(iter);//modified by dyq // } // } // // erase_obj_key.clear(); // vector().swap(erase_obj_key); // // if (result != NULL) // { // delete[] result; // result = NULL; // } // } // } //} //void CMutliSourceVideoProcess::VEHICLECOLORAnalysis(OBJ_KEY obj_key, OBJ_VALUE obj_value) //{ // count_vehicle_v.push_back(obj_key); // // int count_vehicle_unanalysis = count_vehicle_v.size() - count_vehivle_finishanalysis; //当前数组中还有多少个未进行二次属性分析 // // if (count_vehicle_unanalysis >= OBJ_BATCH_COUNT_VEHICLE && !AttributionAnalysis) // { // AttributionAnalysis = true; // //#ifdef LOG_INFO // cout << "----- begin VehicleColor_Process -----" << endl; // //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // for (int i = count_vehivle_finishanalysis; i < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; i++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[i]; // batch_vehicle[i - count_vehivle_finishanalysis].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // } // // vc_result *vcresult = new vc_result[OBJ_BATCH_COUNT_VEHICLE]; // VehicleColor_Process(GetVC_Handle(), batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vcresult); // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("VehicleColor_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("VehicleColor_Process = %lf ms\n", time_val); // */ //#endif //#endif // // int resIndex = 0; // for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // //for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(count_vehicle_v[i + count_vehivle_finishanalysis]); // if (iter == snapShotInfo.end()) // { // resIndex++; // //cout << " cant find" << endl; // } // else // { // vehicle_res curRes; // // memcpy(&curRes.vc_res, &vcresult[resIndex], sizeof(vc_result)); // // vehicle_result.push_back(curRes); // // resIndex++; // } // } // } //} //void CMutliSourceVideoProcess::VEHICLERECGAnalysis(OBJ_KEY obj_key, OBJ_VALUE obj_value) //{ // int count_vehicle_unanalysis = count_vehicle_v.size() - count_vehivle_finishanalysis; //当前数组中还有多少个未进行二次属性分析 // // if (count_vehicle_unanalysis >= OBJ_BATCH_COUNT_VEHICLE && !AttributionAnalysis) // { // AttributionAnalysis = true; // //#ifdef LOG_INFO // cout << "----- begin VehicleColor_Process -----" << endl; // //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // for (int i = count_vehivle_finishanalysis; i < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; i++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[i]; // batch_vehicle[i - count_vehivle_finishanalysis].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // } // // vr_result *vrresult = NULL; // VehicleRecognition_Process(GetVR_Handle(), batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vrresult); // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("VehicleColor_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("VehicleColor_Process = %lf ms\n", time_val); // */ //#endif //#endif // // // int resIndex = 0; // for (int i = count_vehivle_finishanalysis; i < count_vehivle_finishanalysis + OBJ_BATCH_COUNT_VEHICLE; i++) // //for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(count_vehicle_v[i]); // // if (iter == snapShotInfo.end()) // resIndex++; //cout << iter_key.videoID << " " <second.snapShot.frame) // // cudaFree(iter->second.snapShot.frame); // ////delete by lm 20180803 CUresult result = cuCtxPushCurrent(pThreadParam->cuCtx); // // //if (iter->second.snapShotLittle.frame) // // cudaFree(iter->second.snapShotLittle.frame); // ////delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); // // //snapShotInfo.erase(iter);//modified by dyq // resIndex++; // } // } // count_vehivle_finishanalysis += OBJ_BATCH_COUNT_VEHICLE; // //vehicle_res.erase(vehicle_res.begin(), vehicle_res.begin() + OBJ_BATCH_COUNT_VEHICLE); // // if (vrresult != NULL) // { // for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // { // if (vrresult[i].vehicle_brand != NULL) // { // delete[] vrresult[i].vehicle_brand; // vrresult[i].vehicle_brand = NULL; // } // if (vrresult[i].vehicle_subbrand != NULL) // { // delete[] vrresult[i].vehicle_subbrand; // vrresult[i].vehicle_subbrand = NULL; // } // if (vrresult[i].vehicle_issue_year != NULL) // { // delete[] vrresult[i].vehicle_issue_year; // vrresult[i].vehicle_issue_year = NULL; // } // if (vrresult[i].vehicle_type != NULL) // { // delete[] vrresult[i].vehicle_type; // vrresult[i].vehicle_type = NULL; // } // if (vrresult[i].freight_ton != NULL) // { // delete[] vrresult[i].freight_ton; // vrresult[i].freight_ton = NULL; // } // } // delete[] vrresult; // vrresult = NULL; // } // } //} //void CMutliSourceVideoProcess::VEHICLEPLATEAnalysis(OBJ_KEY obj_key, OBJ_VALUE obj_value) //{ // if (count_vehivle_finishanalysis >= OBJ_BATCH_COUNT_VEHICLE && count_vehicle_v.size() >= OBJ_BATCH_COUNT_VEHICLE && !AttributionAnalysis) // { // AttributionAnalysis = true; // //#ifdef LOG_INFO // cout << "----- begin VEHICLEPLATEAnalysis -----" << endl; // //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // { // OBJ_KEY cur_obj_key = count_vehicle_v[i]; // batch_vehicle[i].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // } // // vplate_result *vp_result = new vplate_result[OBJ_BATCH_COUNT_VEHICLE]; // VehiclePlateDetectRecog_Process(GetVP_Handle(), batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vp_result); // // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("VEHICLEPLATEAnalysis: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("VehicleColor_Process = %lf ms\n", time_val); // */ //#endif //#endif // // int resIndex = 0; // for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // //for (auto iter_key : erase_obj_key) // { // // auto iter = snapShotInfo.find(count_vehicle_v[i]); // // if (iter == snapShotInfo.end()) // { // resIndex++; // } // // else // { // vehicle_res &curRes = vehicle_result[i]; // // //VP // memcpy(&curRes.vp_res, &vp_result[resIndex], sizeof(vplate_result)); // // //CPUSaveImage(count_vehicle_v[i], snapShotInfo[count_vehicle_v[i]]); // SnapshotResCallbackFunc(count_vehicle_v[i], snapShotInfo[count_vehicle_v[i]], &curRes); // // if (curRes.vr_res.vehicle_brand != NULL) // { // delete[] curRes.vr_res.vehicle_brand; // curRes.vr_res.vehicle_brand = NULL; // } // if (curRes.vr_res.vehicle_subbrand != NULL) // { // delete[] curRes.vr_res.vehicle_subbrand; // curRes.vr_res.vehicle_subbrand = NULL; // } // if (curRes.vr_res.vehicle_issue_year != NULL) // { // delete[] curRes.vr_res.vehicle_issue_year; // curRes.vr_res.vehicle_issue_year = NULL; // } // if (curRes.vr_res.vehicle_type != NULL) // { // delete[] curRes.vr_res.vehicle_type; // curRes.vr_res.vehicle_type = NULL; // } // if (curRes.vr_res.freight_ton != NULL) // { // delete[] curRes.vr_res.freight_ton; // curRes.vr_res.freight_ton = NULL; // } // // if (iter->second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // } // // //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); // snapShotInfo.erase(iter);//modified by dyq // resIndex++; // } // } // // // // vehicle_result.erase(vehicle_result.begin(), vehicle_result.begin() + OBJ_BATCH_COUNT_VEHICLE); // count_vehicle_v.erase(count_vehicle_v.begin(), count_vehicle_v.begin() + OBJ_BATCH_COUNT_VEHICLE); // // count_vehivle_finishanalysis -= OBJ_BATCH_COUNT_VEHICLE; //前OBJ_BATCH_COUNT_VEHICLE个快照已经完成二次属性分析 // // if (vp_result != NULL) // { // /*for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // { // if (vp_result[i] != NULL) // { // delete[] vp_result[i]; // vp_result[i] = NULL; // } // }*/ // delete[] vp_result; // vp_result = NULL; // } // } //} //void CMutliSourceVideoProcess::VEHICLEAnalysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool flag) //若flag==true立即进行二次属性分析 //{ // while (flag && !count_vehicle_v.empty()) // { // const int cur_batch_size = OBJ_BATCH_COUNT_VEHICLE < count_vehicle_v.size() ? OBJ_BATCH_COUNT : count_vehicle_v.size(); // vector erase_obj_key; // // for (int i = 0; i < cur_batch_size; i++) // { // OBJ_KEY cur_obj_key = count_bike.front(); // erase_obj_key.push_back(cur_obj_key); // batch_hcp[i].set_data(HP_WIDTH, HP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // count_bike.pop(); // } // // hcp_res *result = new hcp_res[OBJ_BATCH_COUNT]; // HumanCarParsing_Process(GetHCP_Handle(), batch_hcp, OBJ_BATCH_COUNT, result); // // int resIndex = 0; // for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(iter_key); // if (iter == snapShotInfo.end()) // resIndex++; // else // { // hcp_res curRes; // memcpy(&curRes, &result[resIndex++], sizeof(hcp_res)); // CPUSaveImage(iter_key, snapShotInfo[iter_key]); // SnapshotResCallbackFunc(iter_key, snapShotInfo[iter_key], &curRes); // if (iter->second.snapShotLittle.frame) // cudaFree(iter->second.snapShotLittle.frame); // snapShotInfo.erase(iter);//modified by dyq // } // } // // erase_obj_key.clear(); // vector().swap(erase_obj_key); // // if (result != NULL) // { // delete[] result; // result = NULL; // } // } // // // count_vehicle.push(obj_key); // if (count_vehicle.size() >= OBJ_BATCH_COUNT_VEHICLE && !AttributionAnalysis) // { // AttributionAnalysis = true; // vector erase_obj_key; //#ifdef LOG_INFO // cout << "----- begin VehicleColor_Process -----" << endl; // //#ifdef _MSC_VER // LARGE_INTEGER nFreq, nBeginTime, nEndTime; // LARGE_INTEGER nSaveBeginTime, nSaveEndTime; // // QueryPerformanceFrequency(&nFreq); // QueryPerformanceCounter(&nBeginTime); // double time_val = 0.0; //#else // gettimeofday(&t1, NULL); // //#endif //#endif // for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // { // OBJ_KEY cur_obj_key = count_vehicle.front(); // erase_obj_key.push_back(cur_obj_key); // batch_vehicle[i].set_data(VEHICLE_WIDTH, VEHICLE_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame); // count_vehicle.pop(); // } // // vc_result *vcresult = new vc_result[OBJ_BATCH_COUNT_VEHICLE]; // VehicleColor_Process(GetVC_Handle(), batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vcresult); // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("VehicleColor_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("VehicleColor_Process = %lf ms\n", time_val); // */ //#endif // //#ifdef _MSC_VER // QueryPerformanceCounter(&nBeginTime); //#else // gettimeofday(&t1, NULL); // //#endif //#endif // vplate_result *vp_result = NULL; // VehiclePlateDetectRecog_Process(GetVP_Handle(), batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vp_result); // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("VehiclePlateDetectRecog_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("VehiclePlateDetectRecog_Process = %lf ms\n", time_val); // */ //#endif // //#ifdef _MSC_VER // QueryPerformanceCounter(&nBeginTime); //#else // gettimeofday(&t1, NULL); // //#endif //#endif // vr_result *vrresult = NULL; // VehicleRecognition_Process(GetVR_Handle(), batch_vehicle, OBJ_BATCH_COUNT_VEHICLE, vrresult); // //#ifdef LOG_INFO //#ifdef _MSC_VER // QueryPerformanceCounter(&nEndTime); // time_val = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) * 1000 / (double)nFreq.QuadPart; // printf("VehicleRecognition_Process: %.2f ms \n", time_val); //#else // /* // gettimeofday(&t2, NULL); // time_val = ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000.0; // printf("VehicleRecognition_Process = %lf ms\n", time_val); // */ //#endif // cout << "----- end VehicleRecog_Process -----" << endl; //#endif // // cout << "----- end VehicleColor_Process -----" << endl; // // int resIndex = 0; // for (auto iter_key : erase_obj_key) // { // auto iter = snapShotInfo.find(iter_key); // // if (iter == snapShotInfo.end()) // resIndex++; //cout << iter_key.videoID << " " <second.snapShot.frame) // cudaFree(iter->second.snapShot.frame); // //delete by lm 20180803 CUresult result = cuCtxPushCurrent(pThreadParam->cuCtx); // // if (iter->second.snapShotLittle.frame) // { // cudaFree(iter->second.snapShotLittle.frame); // } // // //delete by lm 20180803 checkCudaErrors(cuCtxPopCurrent(NULL)); // // snapShotInfo.erase(iter);//modified by dyq // resIndex++; // } // } // // if (vp_result != NULL) // { // /*for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // { // if (vp_result[i] != NULL) // { // delete[] vp_result[i]; // vp_result[i] = NULL; // } // }*/ // delete[] vp_result; // vp_result = NULL; // } // // if (vrresult != NULL) // { // for (int i = 0; i < OBJ_BATCH_COUNT_VEHICLE; i++) // { // if (vrresult[i].vehicle_brand != NULL) // { // delete[] vrresult[i].vehicle_brand; // vrresult[i].vehicle_brand = NULL; // } // if (vrresult[i].vehicle_subbrand != NULL) // { // delete[] vrresult[i].vehicle_subbrand; // vrresult[i].vehicle_subbrand = NULL; // } // if (vrresult[i].vehicle_issue_year != NULL) // { // delete[] vrresult[i].vehicle_issue_year; // vrresult[i].vehicle_issue_year = NULL; // } // if (vrresult[i].vehicle_type != NULL) // { // delete[] vrresult[i].vehicle_type; // vrresult[i].vehicle_type = NULL; // } // if (vrresult[i].freight_ton != NULL) // { // delete[] vrresult[i].freight_ton; // vrresult[i].freight_ton = NULL; // } // } // delete[] vrresult; // vrresult = NULL; // } // // erase_obj_key.clear(); // vector().swap(erase_obj_key); // } // //}