Commit f79fec75f3947a6fa6a61e9d48c004ea71fdb97b

Authored by Hu Chunming
1 parent d07e3a22

代码优化

vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp
... ... @@ -114,21 +114,10 @@ int DxDecoderWrap::DxCloseDecoder()
114 114 }
115 115  
116 116  
117   -int DxDecoderWrap::DxGetResolution( int * width, int * height )
  117 +int DxDecoderWrap::DxGetResolution( int &width, int &height )
118 118 {
119   -
120 119 if(m_pDec) {
121   - int w,h;
122   - m_pDec->getResolution(w, h);
123   -
124   - if ( width ) {
125   - *width = w;
126   - }
127   -
128   - if ( height ) {
129   - *height = h;
130   - }
131   -
  120 + m_pDec->getResolution(width, height);
132 121 return 0;
133 122 }
134 123  
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h
... ... @@ -56,7 +56,7 @@ public:
56 56  
57 57 int DxGetFrameCount();
58 58  
59   - int DxGetResolution( int * width, int * height );
  59 + int DxGetResolution( int &width, int &height );
60 60  
61 61 bool DxFrameIsEmpty();
62 62 int DxLockFrame( DxGPUFrame * frame );
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/ImageSaveGPU.cpp
... ... @@ -3,28 +3,6 @@
3 3 #include "logger.hpp"
4 4  
5 5  
6   -//int saveJPEG(const char *szOutputFile, float* d_srcRGB, int img_width, int img_height)
7   -//{
8   -// return jpegNPP(szOutputFile, d_srcRGB, img_width, img_height);
9   -// //return 0;
10   -//}
11   -//
12   -//int saveJPEG(const char *szOutputFile, unsigned char* d_srcRGB, int img_width, int img_height)
13   -//{
14   -// return jpegNPP(szOutputFile, d_srcRGB, img_width, img_height);
15   -// //return 0;
16   -//}
17   -//
18   -//int saveJPEG(const char *szOutputFile, unsigned char* d_srcRGB)
19   -//{
20   -// return jpegNPP(szOutputFile, d_srcRGB);
21   -//}
22   -//
23   -//int saveJPEG(const char *szOutputFile, float* d_srcRGB)
24   -//{
25   -// return jpegNPP(szOutputFile, d_srcRGB);
26   -//}
27   -
28 6 int resizeFrame(float* d_srcRGB, int src_width, int src_height, float* d_dstRGB, int dst_width, int dst_height)
29 7 {
30 8 cudaError_t cudaStatus = cuda_common::ResizeImage(d_srcRGB, src_width, src_height, d_dstRGB, dst_width, dst_height);
... ... @@ -36,18 +14,6 @@ int resizeFrame(float* d_srcRGB, int src_width, int src_height, float* d_dstRGB,
36 14 return 0;
37 15 }
38 16  
39   -//int initTables()
40   -//{
41   -// initTable();
42   -// return 0;
43   -//}
44   -//
45   -//int initTables(int flag, int width, int height)
46   -//{
47   -// initTable(0, width, height);
48   -// return 0;
49   -//}
50   -
51 17 int drawImageOnGPU(float* d_srcRGB, int src_width, int src_height, int left, int top, int right, int bottom)
52 18 {
53 19 cuda_common::DrawImage(d_srcRGB, src_width, src_height, left, top, right, bottom);
... ... @@ -66,12 +32,6 @@ int drawLineOnGPU(float* d_srcRGB, int src_width, int src_height, int begin_x, i
66 32 return 0;
67 33 }
68 34  
69   -//int releaseJpegSaver()
70   -//{
71   -// releaseJpegNPP();
72   -// return 0;
73   -//}
74   -
75 35 int partMemCopy(unsigned char* d_srcRGB, int src_width, int src_height, unsigned char* d_dstRGB, int left, int top, int right, int bottom)
76 36 {
77 37 cudaError_t cudaStatus = cuda_common::PartMemCopy(d_srcRGB, src_width, src_height, d_dstRGB, left, top, right, bottom);
... ... @@ -82,8 +42,7 @@ int partMemCopy(unsigned char* d_srcRGB, int src_width, int src_height, unsigned
82 42  
83 43 return 0;
84 44 }
85   -//#include <fstream>
86   -//extern std::ofstream g_os;
  45 +
87 46 int PartMemResizeBatch(unsigned char * d_srcRGB, int src_width, int src_height, unsigned char** d_dstRGB,
88 47 int count, int* vleft, int * vtop, int* vright, int* vbottom, int *dst_w, int *dst_h,
89 48 float submeanb, float submeang, float submeanr,
... ... @@ -101,23 +60,4 @@ int PartMemResizeBatch(unsigned char * d_srcRGB, int src_width, int src_height,
101 60 }
102 61  
103 62 return 0;
104   -}
105   -
106   -
107   -//int PartMemResizeBatch(float * d_srcRGB, int src_width, int src_height, unsigned char* d_dstRGB,
108   -// int count, int* vleft, int * vtop, int* vright, int* vbottom, int dst_w, int dst_h,
109   -// float submeanb, float submeang, float submeanr,
110   -// float varianceb, float varianceg, float variancer)
111   -//
112   -//{
113   -// cudaError_t cudaStatus = cuda_common::PartMemResizeBatch(
114   -// d_srcRGB, src_width, src_height, d_dstRGB, count, vleft, vtop, vright, vbottom, dst_w, dst_h,
115   -// submeanb, submeang, submeanr,
116   -// varianceb, varianceg, variancer);
117   -// if (cudaStatus != cudaSuccess) {
118   -// fprintf(stderr, "cuda_common::PartMemCopy failed: %s\n", cudaGetErrorString(cudaStatus));
119   -// return -1;
120   -// }
121   -//
122   -// return 0;
123   -//}
124 63 \ No newline at end of file
  64 +}
125 65 \ No newline at end of file
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp
... ... @@ -419,13 +419,6 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID)
419 419 tasks[i].folderNameLittle = nullptr;
420 420 }
421 421  
422   -
423   - if (tasks[i].taskDataToRT)
424   - {
425   - free(tasks[i].taskDataToRT);
426   - tasks[i].taskDataToRT = nullptr;
427   - }
428   -
429 422 tasks[i].frameImage.release();
430 423  
431 424  
... ... @@ -543,15 +536,19 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh
543 536 return false;
544 537 }
545 538  
546   - int tmp_total_frame = new_task.taskTcuvid->DxGetFrameCount();
  539 + int total_frame = new_task.taskTcuvid->DxGetFrameCount();
547 540  
548   - printf("finish add codec. tmp_total_frame: %d \n", tmp_total_frame);
  541 + int width = 0;
  542 + int height = 0;
  543 + new_task.taskTcuvid->DxGetResolution(width, height);
549 544  
  545 + LOG_INFO("[{}] - finish add codec. w:{} h:{} total_frame:", cfg.name.c_str(), width, height, total_frame);
  546 +
  547 + new_task.frameImage = cv::Mat::zeros(height, width, CV_8UC3);
550 548 new_task.taskState = PLAY;
551 549 new_task.task_algorithm_data.frame = NULL;
552 550 new_task.taskFrameCount = 0;
553 551 new_task.taskLastFrameCount = 0;
554   - new_task.taskDataToRT = NULL;
555 552  
556 553 new_task.taskObjCallbackFunc = nullptr;
557 554 if (objCallbackFunc != nullptr)
... ... @@ -561,7 +558,7 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh
561 558 if (realTimeCallbackFunc != nullptr)
562 559 new_task.taskRealTimeCallbackFunc = std::bind(realTimeCallbackFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
563 560  
564   - new_task.taskTotalFrameCount = tmp_total_frame;
  561 + new_task.taskTotalFrameCount = total_frame;
565 562 if (resultFolderLittle == NULL)
566 563 {
567 564 new_task.folderNameLittle = NULL;
... ... @@ -620,10 +617,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh
620 617 CreateResultFolder(new_task.folderNameFace, "");
621 618 }
622 619  
623   - // printf("finish create folder\n");
624   -
625   - //Sleep(10);
626   - //std::cout << "CreateResultFolder" << std::endl;
627 620 TASK_INFO new_task_info = {};
628 621 new_task_info.image_folder = new_task.folderName;
629 622 new_task_info.snapshot_folder = new_task.folderNameLittle;
... ... @@ -638,6 +631,8 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh
638 631 TaskinPlay++;
639 632 tasks.push_back(new_task);
640 633  
  634 + AddTaskTracker(VPT_Handle, new_task.taskID, width, height);
  635 +
641 636 if (!ProcessFlag) {
642 637 ProcessThread = boost::thread(ThreadProcess, this);
643 638 ProcessFlag = true;
... ... @@ -1492,8 +1487,10 @@ DWORD ThreadProcess(LPVOID param)
1492 1487 if (0 != copy_obj_count)
1493 1488 {
1494 1489 cudaSetDevice(pThreadParam->mgpuid);
  1490 + cuCtxPushCurrent(context);
1495 1491 PartMemResizeBatch((unsigned char*)pThreadParam->tasks[*iter].task_algorithm_data.frame, frameWidth, frameHeight,
1496 1492 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);
  1493 + cuCtxPopCurrent(&context);
1497 1494  
1498 1495 //最新刚添加的人脸检测模块,针对存在的行人快照进行人脸检测+人脸快照框的优选
1499 1496 if (pThreadParam->m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty())
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp.qx
... ... @@ -410,13 +410,6 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID)
410 410 tasks[i].folderNameLittle = nullptr;
411 411 }
412 412  
413   -
414   - if (tasks[i].taskDataToRT)
415   - {
416   - free(tasks[i].taskDataToRT);
417   - tasks[i].taskDataToRT = nullptr;
418   - }
419   -
420 413 tasks[i].frameImage.release();
421 414  
422 415  
... ... @@ -553,7 +546,6 @@ bool CMutliSourceVideoProcess::AddTask(const char* videoFileName, const char* re
553 546 new_task.task_algorithm_data.frame = NULL;
554 547 new_task.taskFrameCount = 0;
555 548 new_task.taskLastFrameCount = 0;
556   - new_task.taskDataToRT = NULL;
557 549  
558 550 new_task.taskObjCallbackFunc = nullptr;
559 551 if (objCallbackFunc != nullptr)
... ... @@ -1039,14 +1031,13 @@ DWORD ThreadProcess(LPVOID param)
1039 1031 if (cudaStatus != cudaSuccess) {
1040 1032 fprintf(stderr, "here cudaMalloc m_pRGBData[0] failed! error: %s\n", cudaGetErrorString(cudaStatus));
1041 1033 break;
1042   - }
  1034 + }
1043 1035  
1044 1036 pThreadParam->tasks[i].task_algorithm_data.height = frame.height;
1045 1037 pThreadParam->tasks[i].task_algorithm_data.width = frame.width;
1046 1038 pThreadParam->tasks[i].task_algorithm_data.size = frame.size;
1047 1039  
1048 1040 pThreadParam->tasks[i].frameImage = cv::Mat::zeros(frame.height, frame.width, CV_8UC3);
1049   - pThreadParam->tasks[i].taskDataToRT = (float*)malloc(3 * frame.height * frame.width * sizeof(unsigned char));
1050 1041 AddTaskTracker(pThreadParam->VPT_Handle, pThreadParam->tasks[i].taskID, 1, 1);
1051 1042 }
1052 1043  
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h
... ... @@ -147,7 +147,6 @@ struct Task{
147 147 TaskState taskState;
148 148 DxDecoderWrap *taskTcuvid;
149 149 DxGPUFrame task_algorithm_data; //����¿�ܲ���resize�Ĵ���������ʱ��backup��ԭͼ��С��ͼƬ�ͽ��㷨�������
150   - float* taskDataToRT;
151 150 bool taskHasBackup;
152 151 //VideoHeightWidth taskHeightWidthRatio;
153 152 VideoHeightWidth taskHeightWidth;
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp
... ... @@ -404,49 +404,48 @@ int VPT_Process_GPU(void * handle, sy_img * batch_img, int startBatch, int batch
404 404  
405 405 for (int i = startBatch; i < tools->taskTrackers.size(); i++)
406 406 {
407   - if (!tools->taskTrackers[i].tracker.GetState()) {
  407 + TaskTracker task_tracker = tools->taskTrackers[i];
  408 + if (!task_tracker.tracker.GetState()) {
408 409 continue;
409 410 }
410 411  
411   - //cout << "task index : " << i << " lastFrameIndex: " << tools->taskTrackers[i].lastFrameIndex << " cur_frameIndex:" << vec_frameIndex[detectIndex] << endl;
412   - int width = 1920; int height = 1080;
413   - if (tools->taskTrackers[i].lastFrameIndex <= 0) {
  412 + if (task_tracker.lastFrameIndex <= 0) {
414 413 // 第一帧,只做带检测框的跟踪
415   - int objCount = tools->taskTrackers[i].tracker.update(/*tools->param.w*/width* tools->taskTrackers[i].ratioWidth, /*tools->param.h*/height* tools->taskTrackers[i].ratioHeight, true, detectResult[detectIndex], result[resIndex].obj, deleteObjectID[detectIndex]);
  414 + int objCount = task_tracker.tracker.update(task_tracker.ratioWidth, task_tracker.ratioHeight, true, detectResult[detectIndex], result[resIndex].obj, deleteObjectID[detectIndex]);
416 415 result[resIndex].objCount = objCount;
417 416 vector<vector<float>>().swap(detectResult[detectIndex]);
418 417 detectResult[detectIndex].clear();
419 418  
420   - tools->taskTrackers[i].lastFrameIndex = vec_frameIndex[detectIndex];
  419 + task_tracker.lastFrameIndex = vec_frameIndex[detectIndex];
421 420 continue;
422 421 }
423 422  
424   - int update_times = vec_frameIndex[detectIndex] - tools->taskTrackers[i].lastFrameIndex - 1;
  423 + int update_times = vec_frameIndex[detectIndex] - task_tracker.lastFrameIndex - 1;
425 424 if (update_times < 0)
426 425 {
427   - cout << "FrameIndex error !! lastFrameIndex= "<< tools->taskTrackers[i].lastFrameIndex <<" cur_frameindex = " << vec_frameIndex[detectIndex] << endl;
  426 + cout << "FrameIndex error !! lastFrameIndex= "<< task_tracker.lastFrameIndex <<" cur_frameindex = " << vec_frameIndex[detectIndex] << endl;
428 427 }
429   - // cout << "lastFrameIndex= " << tools->taskTrackers[i].lastFrameIndex << " cur_frameindex = " << vec_frameIndex[detectIndex] << endl;
  428 + // cout << "lastFrameIndex= " << task_tracker.lastFrameIndex << " cur_frameindex = " << vec_frameIndex[detectIndex] << endl;
430 429 // cout << "update_times = " << update_times << endl;
431 430  
432 431 for (int j = 0; j < update_times; j++)
433 432 { // 无检测框跟踪
434   - //cout << "taskTrackers size: " << tools->taskTrackers.size() << " batchsize:" << detectResult.size() << " update_times: "<< update_times << endl;
  433 + //cout << "taskTrackers size: " << task_tracker.size() << " batchsize:" << detectResult.size() << " update_times: "<< update_times << endl;
435 434 VPT_Result unresult;
436 435 VPT_ObjInfo obj[MAX_OBJ_COUNT];
437   - unresult.objCount = tools->taskTrackers[i].tracker.update(/*tools->param.w*/width* tools->taskTrackers[i].ratioWidth, /*tools->param.h*/height* tools->taskTrackers[i].ratioHeight, false, detectResult[detectIndex], unresult.obj, deleteObjectID[detectIndex]);
  436 + unresult.objCount =task_tracker.tracker.update(task_tracker.ratioWidth, task_tracker.ratioHeight, false, detectResult[detectIndex], unresult.obj, deleteObjectID[detectIndex]);
438 437 check_VPT_Result(unresult);
439 438 unUsedResult[resIndex].push_back(unresult);
440 439 }
441 440  
442 441 //有检测框输入的跟踪
443   - int objCount = tools->taskTrackers[i].tracker.update(/*tools->param.w*/width* tools->taskTrackers[i].ratioWidth, /*tools->param.h*/height* tools->taskTrackers[i].ratioHeight, true, detectResult[detectIndex], result[resIndex].obj, deleteObjectID[detectIndex]);
  442 + int objCount = task_tracker.tracker.update(task_tracker.ratioWidth, task_tracker.ratioHeight, true, detectResult[detectIndex], result[resIndex].obj, deleteObjectID[detectIndex]);
444 443 result[resIndex].objCount = objCount;
445 444 vector<vector<float>>().swap(detectResult[detectIndex]);
446 445 detectResult[detectIndex].clear();
447 446  
448 447 // 记录帧序号
449   - tools->taskTrackers[i].lastFrameIndex = vec_frameIndex[detectIndex];
  448 + task_tracker.lastFrameIndex = vec_frameIndex[detectIndex];
450 449  
451 450 check_VPT_Result(result[resIndex]);
452 451  
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/FaceDetModule.cpp
... ... @@ -102,15 +102,10 @@ int face_det_module::face_det_module_init(int gpuid, char* auth_license)
102 102  
103 103 int face_det_module::face_det_module_process(sy_img* img, int batchsize, fd_result *face_det_result, sy_point* original_size)
104 104 {
105   - //static int framcount = 0;
106   - //printf("framcount: %d\n", framcount++);
107 105 if (sy_process_param_check(m_face_det_handle, img, batchsize) == FAILED)
108 106 return FAILED;
109 107  
110 108 sy_img *cpu_img = new sy_img[batchsize];
111   - //unsigned char** data = new unsigned char*[batchsize];
112   - cv::Mat *human_image = new cv::Mat[batchsize];
113   - cv::Mat *human_image_ori = new cv::Mat[batchsize];
114 109  
115 110 for (int b = 0; b < batchsize; b++) {
116 111 cpu_img[b].c_ = 3;
... ... @@ -134,33 +129,16 @@ int face_det_module::face_det_module_process(sy_img* img, int batchsize, fd_resu
134 129 for (int b = 0; b < batchsize; b++)
135 130 {
136 131 int real_count = 0;
137   - // cv::Mat tmp_img(img[b].h_, img[b].w_, CV_8UC3, cpu_img[b].data_);
138 132 for (int c = 0; c < face_det_result[b].count; c++)
139 133 {
140 134 if (face_det_result[b].info[c].score >= 0.5)
141 135 {
142   - /*printf("score: %f\n", face_det_result[b].info[c].score);
143   - cv::rectangle(tmp_img, cv::Rect(face_det_result[b].info[0].face_position.left_,
144   - face_det_result[b].info[0].face_position.top_,
145   - face_det_result[b].info[0].face_position.width_,
146   - face_det_result[b].info[0].face_position.height_), cv::Scalar(25, 250, 25), 2, 8, 0);
147   - cv::imshow("face", tmp_img);
148   - cv::waitKey(0);*/
149   -
150   - /*printf("face det: %d %d %d %d %d %d\n", face_det_result[b].info[0].face_position.left_,
151   - face_det_result[b].info[0].face_position.top_,
152   - face_det_result[b].info[0].face_position.width_,
153   - face_det_result[b].info[0].face_position.height_,
154   - face_det_result[b].info[0].facial_fea_point[0].x_,
155   - face_det_result[b].info[0].facial_fea_point[0].y_);*/
156   -
157 136 memcpy((void*)&face_det_result[b].info[real_count], (void*)&face_det_result[b].info[c], sizeof(fd_info));
158 137 real_count++;
159 138 }
160 139 }
161 140 face_det_result[b].count = real_count;
162 141 }
163   -
164 142  
165 143 for (int b = 0; b < batchsize; b++) {
166 144 if(cpu_img[b].data_) {
... ... @@ -168,8 +146,6 @@ int face_det_module::face_det_module_process(sy_img* img, int batchsize, fd_resu
168 146 }
169 147 }
170 148 if (cpu_img) delete[] cpu_img;
171   - if (human_image) delete[] human_image;
172   - if (human_image_ori) delete[] human_image_ori;
173 149  
174 150 return ret;
175 151 }
... ...