Commit 938566bdf588fcdf4646ec38f164a1b3c63fa47c

Authored by Hu Chunming
1 parent 97243f56

删除无用代码;优化解码线程退出,避免任务结束时丢帧;代码优化

.vscode/launch.json
... ... @@ -2,29 +2,11 @@
2 2 "version": "0.2.0",
3 3 "configurations": [
4 4 {
5   - "name": "(gdb) Launch",
  5 + "name": "mvpt",
6 6 "type": "cppdbg",
7 7 "request": "launch",
8 8 "program": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512/test",
9   - "args": ["file:///home/cmhu/data/video/Street.uvf?fastdecode=on","6","0","./db/mvpt.bin"],
10   - "stopAtEntry": false,
11   - "cwd": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512",
12   - "environment": [],
13   - "externalConsole": false,
14   - "MIMode": "gdb",
15   - "setupCommands": [
16   - {
17   - "description": "Enable pretty-printing for gdb",
18   - "text": "-enable-pretty-printing",
19   - "ignoreFailures": true
20   - }
21   - ]
22   - },{
23   - "name": "test_ffnvdecoder",
24   - "type": "cppdbg",
25   - "request": "launch",
26   - "program": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512/test",
27   - "args": ["/home/cmhu/data/video/Street.uvf","6","0","./db/mvpt.bin"],
  9 + "args": ["/home/cmhu/data/video/123456-6.mp4","1","0","./db/mvpt.bin"],
28 10 "stopAtEntry": false,
29 11 "cwd": "${workspaceFolder}/Linux_3rdparty/video_structure_sdk_20220512",
30 12 "environment": [],
... ...
.vscode/settings.json
... ... @@ -78,7 +78,8 @@
78 78 "numbers": "cpp",
79 79 "semaphore": "cpp",
80 80 "stop_token": "cpp",
81   - "variant": "cpp"
  81 + "variant": "cpp",
  82 + "*.inc": "cpp"
82 83 },
83 84 "git.ignoreLimitWarning": true
84 85 }
85 86 \ No newline at end of file
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp
... ... @@ -64,6 +64,7 @@ int DxDecoderWrap::DxOpenDecoder( const char * uri, unsigned int skip )
64 64 if(1 == m_decMode) {
65 65 m_pDec->setDecKeyframe(true);
66 66 }
  67 + m_bReal = m_pDec->isRealStream();
67 68 m_pDec->start();
68 69 LOG_INFO("[{}][{}]- 解码器初始化成功", m_name.c_str(), uri);
69 70 return 0;
... ... @@ -232,6 +233,10 @@ void DxDecoderWrap::post_decode_callback(GPUFrame * decodedFrame) {
232 233 break;
233 234 } else {
234 235 m_queue_frames_mutex.unlock();
  236 + if (m_bReal) {
  237 + // 实时流不等待,直接弃帧
  238 + return;
  239 + }
235 240 std::this_thread::sleep_for(std::chrono::milliseconds(10));
236 241 }
237 242 }
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h
... ... @@ -75,6 +75,7 @@ public:
75 75  
76 76 private:
77 77 bool m_bClose;
  78 + bool m_bReal;
78 79  
79 80 FFDecConfig m_cfg;
80 81 string m_name;
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp
... ... @@ -45,7 +45,6 @@ FFNvDecoder::FFNvDecoder()
45 45 m_bReal = true;
46 46  
47 47 m_decode_thread = 0;
48   - m_post_decode_thread = 0;
49 48  
50 49 m_bFinished = false;
51 50 m_dec_keyframe = false;
... ... @@ -192,6 +191,8 @@ void FFNvDecoder::decode_thread()
192 191 pkt = av_packet_alloc();
193 192 av_init_packet( pkt );
194 193  
  194 + m_bExitDisplay = false;
  195 + pthread_t m_post_decode_thread = 0;
195 196 pthread_create(&m_post_decode_thread,0,
196 197 [](void* arg)
197 198 {
... ... @@ -255,6 +256,7 @@ void FFNvDecoder::decode_thread()
255 256 if (result < 0){
256 257 av_packet_unref(pkt);
257 258 LOG_ERROR("[{}] - Failed to send pkt: {}", m_dec_name, result);
  259 + std::this_thread::sleep_for(std::chrono::milliseconds(3));
258 260 continue;
259 261 }
260 262  
... ... @@ -264,8 +266,10 @@ void FFNvDecoder::decode_thread()
264 266 LOG_ERROR("[{}] - Failed to receive frame: {}", m_dec_name, result);
265 267 av_frame_free(&gpuFrame);
266 268 av_packet_unref(pkt);
  269 + std::this_thread::sleep_for(std::chrono::milliseconds(3));
267 270 continue;
268 271 }
  272 +
269 273 av_packet_unref(pkt);
270 274  
271 275 decoded_frame_count++;
... ... @@ -295,8 +299,8 @@ void FFNvDecoder::decode_thread()
295 299 // long end_time = get_cur_time();
296 300 // cout << "解码用时:" << end_time - start_time << endl;
297 301  
298   - if (m_post_decode_thread != 0)
299   - {
  302 + if (m_post_decode_thread != 0){
  303 + m_bExitDisplay = true;
300 304 pthread_join(m_post_decode_thread,0);
301 305 }
302 306  
... ... @@ -341,7 +345,7 @@ void FFNvDecoder::post_decode_thread(){
341 345  
342 346 unsigned long long index = 0;
343 347 int frame_count = 0;
344   - while (m_bRunning)
  348 + while (!m_bExitDisplay)
345 349 {
346 350 std::this_thread::sleep_for(std::chrono::milliseconds(2)); //给m_snapshot_mutex的喘息时间,避免截图一直截不到。避免线程资源占用。
347 351 if(mFrameQueue.size() > 0){
... ... @@ -429,4 +433,8 @@ float FFNvDecoder::fps(){
429 433  
430 434 unsigned long long FFNvDecoder::GetFrameCount() {
431 435 return m_nb_frames;
  436 +}
  437 +
  438 +bool FFNvDecoder::isRealStream() {
  439 + return m_bReal;
432 440 }
433 441 \ No newline at end of file
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.h
... ... @@ -33,6 +33,8 @@ public:
33 33  
34 34 DECODER_TYPE getDecoderType(){ return DECODER_TYPE_FFMPEG; }
35 35  
  36 + bool isRealStream();
  37 +
36 38 public:
37 39 AVPixelFormat getHwPixFmt();
38 40  
... ... @@ -50,9 +52,9 @@ private:
50 52 AVPixelFormat hw_pix_fmt;
51 53  
52 54 pthread_t m_decode_thread;
53   - pthread_t m_post_decode_thread;
54 55  
55 56 bool m_bRunning;
  57 + bool m_bExitDisplay{false};
56 58 bool m_bFinished;
57 59  
58 60 bool m_bPause;
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp
... ... @@ -106,22 +106,11 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN
106 106 {
107 107 set_default_logger(LogLevel(1), "multi_source_process", "logs/main.log", 64 * 1024 * 1024, 30);
108 108  
109   - // checkGpuMem();
110 109 licence_status = -1;
111 110 thrd_status = -1;
112   - //SetUnhandledExceptionFilter(CustomExceptionCrashHandler);
113 111  
114 112 int ret = SUCCESS;
115   - /*DxLogConfig sCfg = { 0 };
116   - sCfg.serviceID = vptParam.serviceID;
117   - sCfg.limitSize = vptParam.limitSize;
118   - strcpy(sCfg.name, vptParam.name);
119   - strcpy(sCfg.path, vptParam.path);
120   - DxInitializeLog(&sCfg);*/
121   -
122   - /*printf("=====================��ȨERROR==================\n");
123   - printf("=====================��ȨERROR==================\n");
124   - printf("=====================��ȨERROR==================\n");*/
  113 +
125 114 #ifdef AUTHORIZATION
126 115 #ifdef _WIN32
127 116 if (SUCCESS == (ret = sy_licence(productSN)))
... ... @@ -130,99 +119,87 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN
130 119 memset(wtime, 0, 15);
131 120 char * time = wtime;
132 121 ret = sy_licence(productSN, &time);
133   - if (SUCCESS == ret)
134 122 #endif
135 123 #else
136 124 ret = license_check(vptParam.auth_license, productSN);// sy_time_check(2022, 2);
137 125 // ret = strcmp(AUTH_LICENSE, vptParam.auth_license);
138   - if (ret == SUCCESS)
139 126 #endif
  127 + if (ret != SUCCESS){
  128 + return AUTHOR_ERROR;
  129 + }
  130 +
  131 +
  132 + cuInit(0);
  133 + int device_count = 0;
  134 + cuDeviceGetCount(&device_count);
  135 +
  136 + if (vptParam.gpuid >= device_count)
140 137 {
141   - cuInit(0);
142   - int device_count = 0;
143   - cuDeviceGetCount(&device_count);
  138 + printf("\nGPU_ID PARAM WRONG, gpuid: %d device_count: %d\n", vptParam.gpuid, device_count);
  139 + return GPUID_PARAM_ERROR;
  140 + }
144 141  
145   - if (vptParam.gpuid >= device_count)
146   - {
147   - printf("\nGPU_ID PARAM WRONG, gpuid: %d device_count: %d\n", vptParam.gpuid, device_count);
148   - return GPUID_PARAM_ERROR;
149   - }
  142 + CUdevice dev = 0;
  143 + size_t memSize = 0;
  144 + dev = vptParam.gpuid;
150 145  
151   - CUdevice dev = 0;
152   - size_t memSize = 0;
153   - dev = vptParam.gpuid;
  146 + CUresult rlt = CUDA_SUCCESS;
  147 + rlt = cuDeviceTotalMem(&memSize, dev);
154 148  
155   - CUresult rlt = CUDA_SUCCESS;
156   - rlt = cuDeviceTotalMem(&memSize, dev);
  149 + gpu_total_memory = (float)memSize / (1024 * 1024);
157 150  
158   - gpu_total_memory = (float)memSize / (1024 * 1024);
  151 + if (gpu_total_memory < 9000) //8G�Դ棬С�ڴ淽��
  152 + section_batch_size = 10;
  153 + else
  154 + section_batch_size = 20;
159 155  
160   - if (gpu_total_memory < 9000) //8G�Դ棬С�ڴ淽��
161   - section_batch_size = 10;
162   - else
163   - section_batch_size = 20;
  156 + if(vptParam.skip_frame > 0){
  157 + // 默认值为5
  158 + skip_frame_ = vptParam.skip_frame;
  159 + }
164 160  
165   - if(vptParam.skip_frame > 0){
166   - // 默认值为5
167   - skip_frame_ = vptParam.skip_frame;
168   - }
  161 + mgpuid = vptParam.gpuid;
  162 + ret = m_vptProcess.init(mgpuid, section_batch_size);
  163 + if (0 != ret)
  164 + return ret;
169 165  
170   - mgpuid = vptParam.gpuid;
171   - ret = m_vptProcess.init(mgpuid, section_batch_size);
172   - if (0 != ret)
173   - return ret;
  166 + viewTaskID = -1;
  167 + TotalTask = 0;
174 168  
175   - viewTaskID = -1;
176   - TaskinPlay = 0;
177   - TotalTask = 0;
  169 + taskFinishCallbackFunc = nullptr;
  170 + if (tFinishCallbackFunc != nullptr)
  171 + taskFinishCallbackFunc = std::bind(tFinishCallbackFunc, this, std::placeholders::_1);
  172 +
  173 + taskObjInfoCallbackFunc = nullptr;
  174 + if (tObjInfoCallbackFunc != nullptr)
  175 + taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1);
178 176  
179   - taskFinishCallbackFunc = nullptr;
180   - if (tFinishCallbackFunc != nullptr)
181   - taskFinishCallbackFunc = std::bind(tFinishCallbackFunc, this, std::placeholders::_1);
182   -
183   - taskObjInfoCallbackFunc = nullptr;
184   - if (tObjInfoCallbackFunc != nullptr)
185   - taskObjInfoCallbackFunc = std::bind(tObjInfoCallbackFunc, this, std::placeholders::_1);
  177 + CommandConfig cmdConfig;
  178 + cmdConfig.hp_analysis_config = vptParam.hp_analysis_config;
  179 + cmdConfig.hcp_analysis_config = vptParam.hcp_analysis_config;
  180 + cmdConfig.vehicle_analysis_config = vptParam.vehicle_analysis_config;
  181 + cmdConfig.hf_recg_config = vptParam.hf_recg_config;
  182 + cmdConfig.hcf_recg_config = vptParam.hcf_recg_config;
  183 + cmdConfig.vcf_recg_config = vptParam.vcf_recg_config;
  184 + cmdConfig.face_detect_config = vptParam.face_det_config;
186 185  
187   - m_hp_analysis_config = vptParam.hp_analysis_config;
188   - m_hcp_analysis_config = vptParam.hcp_analysis_config;
189   - m_vehicle_analysis_config = vptParam.vehicle_analysis_config;
190   - m_hf_recg_config = vptParam.hf_recg_config;
191   - m_hcf_recg_config = vptParam.hcf_recg_config;
192   - m_vcf_recg_config = vptParam.vcf_recg_config;
193   - m_face_det_config = vptParam.face_det_config;
  186 + m_face_det_config = vptParam.face_det_config;
194 187  
195   - m_snaphot_helper.snapshot_helper_init(vptParam.gpuid, gpu_total_memory, vptParam.vrdbpath, vptParam.auth_license, vptParam.wait_framecount, m_hp_analysis_config, \
196   - m_hcp_analysis_config, m_vehicle_analysis_config, m_vehicle_recg_config, m_vehicle_plate_det_recg_config, m_hf_recg_config, m_hcf_recg_config, m_vcf_recg_config, m_face_det_config);
  188 + m_snaphot_helper.snapshot_helper_init(vptParam.gpuid, gpu_total_memory, vptParam.vrdbpath, vptParam.auth_license, vptParam.wait_framecount, cmdConfig);
197 189  
198   - m_bProcessExit = false;
199   - ProcessThread = std::thread(algorthim_process_thread, this);
  190 + m_bProcessExit = false;
  191 + ProcessThread = std::thread(algorthim_process_thread, this);
200 192  
201   - if (ret == SUCCESS) //�ɹ�
202   - {
203   - licence_status = 0;
  193 + if (ret == SUCCESS) //�ɹ�
  194 + {
  195 + licence_status = 0;
204 196 #ifdef AUTHORIZATION
205   - m_bExit = false;
206   - thrd = std::thread(check_thread, this);
  197 + m_bExit = false;
  198 + thrd = std::thread(check_thread, this);
207 199 #endif
208   - thrd_status = 0;
209   - }
210   -
211   - }
212   - else
213   - {
214   - return AUTHOR_ERROR;
215   - }
216   -/*
217   -#ifdef AUTHORIZATION
218   -#ifdef __linux__
219   - if (wtime)
220   - {
221   - delete[] wtime;
222   - wtime = NULL;
  200 + thrd_status = 0;
223 201 }
224   -#endif
225   -#endif */ // debug by zsh
  202 +
226 203 return ret;
227 204 }
228 205  
... ... @@ -234,7 +211,6 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID)
234 211  
235 212 Task& task = m_taskMap[taskID];
236 213  
237   - if (task.taskState == PLAY) TaskinPlay--;
238 214 task.taskState = FINISH;
239 215 task.taskFileSource = nullptr;
240 216 task.taskObjCallbackFunc = nullptr;
... ... @@ -284,7 +260,6 @@ void CMutliSourceVideoProcess::PauseTask(const int taskID)
284 260  
285 261 Task& task = m_taskMap[taskID];
286 262  
287   - if (task.taskState == PLAY) TaskinPlay--;
288 263 task.taskState = PAUSE;
289 264 m_vptProcess.PauseTaskTracker(taskID);
290 265 task.taskTcuvid->PauseDecoder();
... ... @@ -301,7 +276,6 @@ void CMutliSourceVideoProcess::RestartTask(const int taskID)
301 276 Task& task = m_taskMap[taskID];
302 277  
303 278 task.taskState = PLAY;
304   - TaskinPlay++;
305 279 m_vptProcess.RestartTaskTraker(taskID);
306 280 task.taskTcuvid->ResumeDecoder();
307 281 printf("-----------------------restart task: %d-----------------------\n", taskID);
... ... @@ -464,7 +438,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh
464 438 m_taskMap[new_task.taskID] = new_task;
465 439  
466 440 TotalTask++;
467   - TaskinPlay++;
468 441  
469 442 m_vptProcess.AddTaskTracker(new_task.taskID, width, height);
470 443  
... ... @@ -645,19 +618,14 @@ void CMutliSourceVideoProcess::callTaskObjInfoCallbackFunc(const VPT_Result&amp; vpt
645 618  
646 619 }
647 620 }
  621 +
648 622 void CMutliSourceVideoProcess::algorthim_process()
649 623 {
650   - int count = 0;
651   -
652   - DxGPUFrame frame = {};
653   -
654 624 cudaSetDevice(mgpuid);
655 625  
656 626 int total_count = 0;
657 627 long long begintime1 =get_cur_time_ms();
658 628  
659   - int process_times = 0;
660   -
661 629 long long last_time = get_cur_time_ms();
662 630 while (!m_bProcessExit) {
663 631  
... ... @@ -696,6 +664,7 @@ void CMutliSourceVideoProcess::algorthim_process()
696 664 }
697 665  
698 666 if (vec_dxGpuFrame.size() <= 0) {
  667 + std::this_thread::sleep_for(std::chrono::milliseconds(5));
699 668 continue;
700 669 }
701 670  
... ... @@ -876,14 +845,6 @@ void CMutliSourceVideoProcess::algorthim_process()
876 845 task.taskRealTimeCallbackFunc(task.frameImage.data, task.frameImage.rows, task.frameImage.cols);
877 846 }
878 847 }
879   -
880   - {
881   - cudaError_t cudaStatus = cudaGetLastError();
882   - if (cudaStatus != cudaSuccess) {
883   - LOG_ERROR("result last error: {}", cudaGetErrorString(cudaStatus));
884   - }
885   - }
886   -
887 848  
888 849  
889 850 #ifdef LOG_INFO2
... ... @@ -903,26 +864,17 @@ void CMutliSourceVideoProcess::algorthim_process()
903 864 }
904 865 }
905 866  
906   -
907   - for (auto task_algorithm_data: vec_dxGpuFrame) {
908   - cudaFree(task_algorithm_data.frame);
909   - task_algorithm_data.frame = nullptr;
910   - }
911   -
912   -
913   - {
914   - cudaError_t cudaStatus = cudaGetLastError();
915   - if (cudaStatus != cudaSuccess) {
916   - LOG_ERROR("cudaFree last error: {}", cudaGetErrorString(cudaStatus));
917   - }
918   - }
919   -
920 867 m_snaphot_helper.object_attri_analysis();
921 868 cudaError_t cudaStatus = cudaGetLastError();
922 869 if (cudaStatus != cudaSuccess) {
923 870 LOG_ERROR("object_attri_analysis last error: {}", cudaGetErrorString(cudaStatus));
924 871 }
925 872  
  873 + for (auto task_algorithm_data: vec_dxGpuFrame) {
  874 + cudaFree(task_algorithm_data.frame);
  875 + task_algorithm_data.frame = nullptr;
  876 + }
  877 +
926 878 #ifdef LOG_INFO2
927 879 long long second_analysis_time2 = get_cur_time_ms();
928 880 cout << "second_analysis time_using:" << second_analysis_time2 - second_analysis_time << endl;
... ... @@ -940,7 +892,7 @@ void CMutliSourceVideoProcess::algorthim_process()
940 892 m_snaphot_helper.clearSnapshotInfo();
941 893  
942 894 long long costTime1 = get_cur_time_ms() - begintime1;
943   - LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times);
  895 + LOG_INFO("Process Thread is Finished. total frame cost time = {} ms", costTime1);
944 896 }
945 897  
946 898 int CMutliSourceVideoProcess::GetRuningNb() {
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h
... ... @@ -136,9 +136,7 @@ public:
136 136 int skip_frame_ {5}; // 控制跳帧参数
137 137 map<int, Task> m_taskMap;
138 138 int AddTaskSucFlag; //0:��ʼ��״̬ 1����������ɹ� -1����������ʧ��
139   - int TaskinPlay;
140 139 int TotalTask;
141   - set<int> TaskinPlayID;
142 140  
143 141 int viewTaskID;
144 142  
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp
... ... @@ -289,6 +289,8 @@ vector&lt;VPTProcessResult&gt; VPTProcess::process(vector&lt;DataInfo&gt; vec_data) {
289 289 cout << "FrameIndex error !! lastFrameIndex= " << task_tracker.lastFrameIndex << " cur_frameindex = " << det_result_info.ts << endl;
290 290 }
291 291  
  292 + cout << "update_times " << update_times << endl;
  293 +
292 294 for (int j = 0; j < update_times; j++) { // 无检测框跟踪
293 295 VPT_Result unresult;
294 296 unresult.objCount = task_tracker.tracker.update(task_tracker.ratioWidth, task_tracker.ratioHeight, false, task_tracker.lastDetectResult, unresult.obj, task_tracker.lastDeleteObjectID);
... ... @@ -308,96 +310,8 @@ vector&lt;VPTProcessResult&gt; VPTProcess::process(vector&lt;DataInfo&gt; vec_data) {
308 310  
309 311 vec_result.push_back(oneResult);
310 312 }
311   -}
312   -
313   -int VPTProcess::process(sy_img * batch_img, int batchsize, vector<unsigned long long> vec_frameIndex, vector<VPT_Result>& result, vector<vector<int>>& deleteObjectID, vector<vector<VPT_Result>>& unUsedResult)
314   -{
315   - if(nullptr == det_handle){
316   - return FAILED;
317   - }
318   -
319   - long long t1 = get_cur_time_ms();
320   -
321   - vector <vector< vector <float>>> detectResult(batchsize);
322   - int real_index = 0;
323   -
324   - int cycle_time = batchsize / m_max_batch_size;
325   - cycle_time = (batchsize % m_max_batch_size) == 0 ? cycle_time : (cycle_time + 1) ;
326   - vector<sy_img> vec_img;
327   - for (int i = 0; i < cycle_time; i++) {
328   - vec_img.clear();
329   -
330   - int start_index = i * m_max_batch_size;
331   - int end_index = start_index + m_max_batch_size;
332   - if(end_index >= batchsize) {
333   - end_index = batchsize;
334   - }
335   - for (int j = start_index; j < end_index; j++) {
336   - vec_img.push_back(batch_img[j]);
337   - }
338   -
339   - ctools_result *detresult;
340   - int res_status = ctools_process(det_handle, vec_img.data(), vec_img.size(), &detresult);
341   -
342   - for (size_t b = 0; b < vec_img.size(); b++) {
343   - ctools_result &cur_result = detresult[b];
344   - for (int c = 0; c < cur_result.obj_count_ && c < MAX_OBJ_COUNT; c++)
345   - {
346   - float x1 = cur_result.obj_results_[c].data_[2];
347   - float y1 = cur_result.obj_results_[c].data_[3];
348   - float x2 = cur_result.obj_results_[c].data_[4];
349   - float y2 = cur_result.obj_results_[c].data_[5];
350   -
351   - float class_id = cur_result.obj_results_[c].data_[0];
352   - float score = cur_result.obj_results_[c].data_[1];
353   -
354   - if (score >= THRESHOLD)
355   - {
356   - vector <float> obj;
357   -
358   - obj.push_back(x1);
359   - obj.push_back(y1);
360   - obj.push_back(x2);
361   - obj.push_back(y2);
362   - obj.push_back(score);
363   - obj.push_back(class_id);
364   - detectResult[real_index].push_back(obj);
365   - }
366   - }
367   - real_index++;
368   - }
369   - }
370   -
371   - for (int i = 0; i < batchsize; i++) {
372   - TaskTracker& task_tracker = m_taskTrackerMap[i];
373   - if (!task_tracker.tracker.GetState()) {
374   - continue;
375   - }
376 313  
377   - if (task_tracker.lastFrameIndex > 0) {
378   - // 非第一帧
379   - int update_times = vec_frameIndex[i] - task_tracker.lastFrameIndex - 1;
380   - if (update_times < 0) {
381   - cout << "FrameIndex error !! lastFrameIndex= " << task_tracker.lastFrameIndex << " cur_frameindex = " << vec_frameIndex[i] << endl;
382   - }
383   -
384   - for (int j = 0; j < update_times; j++) { // 无检测框跟踪
385   - VPT_Result unresult;
386   - unresult.objCount = task_tracker.tracker.update(task_tracker.ratioWidth, task_tracker.ratioHeight, false, task_tracker.lastDetectResult, unresult.obj, task_tracker.lastDeleteObjectID);
387   - check_VPT_Result(unresult);
388   - unUsedResult[i].push_back(unresult);
389   - }
390   - }
391   - result[i].objCount = task_tracker.tracker.update(task_tracker.ratioWidth, task_tracker.ratioHeight, true, detectResult[i], result[i].obj, deleteObjectID[i]);
392   -
393   - check_VPT_Result(result[i]);
394   -
395   - task_tracker.lastDetectResult = detectResult[i];
396   - task_tracker.lastDeleteObjectID = deleteObjectID[i];
397   -
398   - // 记录帧序号
399   - task_tracker.lastFrameIndex = vec_frameIndex[i];
400   - }
  314 + return vec_result;
401 315 }
402 316  
403 317 void VPTProcess::release() {
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h
... ... @@ -61,18 +61,7 @@ public:
61 61  
62 62 /*************************************************************************
63 63 * PURPOSE: 人车物检测跟踪
64   - * PARAM:
65   - [in] handle - 处理句柄
66   - [in] rgb - 图片数据(3通道BGR数据 cv::Mat格式)
67   - [in] width - 图片宽度
68   - [in] height - 图片高度
69   - [in] result - 搜索结果,在外部申请足够内存
70   - [in] deleteObjectID - 删除的轨迹ID号
71   - [out] traffic - 交通流量结果结构体 内存在外部申请,大小与初始化时流量监测线个数相同,设置为NULL时不返回
72   - * RETURN: -1:图像错误; 其他:检测到的个数
73   - * NOTES:
74 64 *************************************************************************/
75   - int process(sy_img * batch_img, int batchsize, vector<unsigned long long> vec_frameIndex, vector<VPT_Result>& result, vector<vector<int>>& deleteObjectID, vector<vector<VPT_Result>>& unUsedResult);
76 65  
77 66 vector<VPTProcessResult> process(vector<DataInfo> vec_data);
78 67  
... ... @@ -85,8 +74,6 @@ public:
85 74 *************************************************************************/
86 75 void release();
87 76  
88   -
89   -
90 77 void AddTaskTracker(const int taskID, const double rWidth, const double rHeight);
91 78 void FinishTaskTracker(const int taskID);
92 79 void PauseTaskTracker(const int taskID);
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/common.h
... ... @@ -117,4 +117,16 @@ typedef struct VPT_Result
117 117 }VPT_Result;
118 118  
119 119  
  120 +struct CommandConfig {
  121 + sy_command hp_analysis_config;
  122 + sy_command hcp_analysis_config;
  123 + sy_command vehicle_analysis_config;
  124 + sy_command vehicle_recg_config;
  125 + sy_command vehicle_plate_det_recg_config;
  126 + sy_command hf_recg_config;
  127 + sy_command hcf_recg_config;
  128 + sy_command vcf_recg_config;
  129 + sy_command face_detect_config;
  130 +};
  131 +
120 132 #endif
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp
... ... @@ -91,6 +91,7 @@ int HumanCarParsing::process(sy_img * batch_img, int batch_size, hcp_analysis_re
91 91 return SUCCESS;
92 92  
93 93 }
  94 +
94 95 int HumanCarParsing::release()
95 96 {
96 97 if(handle) {
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleColor.h
1   -#include "vehicle_color.h"
2   -
3   -
4 1 #pragma once
  2 +#include "vehicle_color.h"
5 3 #include <iostream>
6 4 #include "utools.h"
7 5 #include <vector>
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehicleRearRecg.cpp
... ... @@ -33,6 +33,7 @@ int VehicleRearRecg::init(char*dbpath, int gpuid, char* auth_license)
33 33 LOG_INFO("vrr_init success! gpu_id: {}", gpuid);
34 34 return SUCCESS;
35 35 }
  36 +
36 37 int VehicleRearRecg::process(sy_img * batch_img, int batchsize, vehicle_rear_result *&vr_result)
37 38 {
38 39 for (int i = 0; i < batchsize; i++)
... ... @@ -47,6 +48,7 @@ int VehicleRearRecg::process(sy_img * batch_img, int batchsize, vehicle_rear_res
47 48  
48 49 return SUCCESS;
49 50 }
  51 +
50 52 int VehicleRearRecg::release()
51 53 {
52 54 if (handle) {
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp
... ... @@ -15,8 +15,6 @@ using namespace std;
15 15 string ObjTypes[9] = { "行人", "自行车", "摩托车", "三轮车", "小型车", "大车", "卡车", "拖拉机", "中巴" };
16 16 string ObjTypesEnglish[9] = { "person", "bike", "motor", "tricycle", "car", "bigbus", "lorry", "tractor", "midibus" };
17 17  
18   -extern int minDistance[];
19   -
20 18 #ifdef _MSC_VER
21 19 char* GbkToUtf8(const char *src_str)
22 20 {
... ... @@ -85,16 +83,15 @@ void SnapshotImageWriteThreadProcess(const void * userPtr){
85 83 }
86 84 }
87 85  
88   -void snapshot_helper::snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, sy_command hp_analysis_config, \
89   - sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command vehicle_recg_config, sy_command vehicle_plate_det_recg_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config, sy_command face_detect_config)
  86 +void snapshot_helper::snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, CommandConfig cmdConfig)
90 87 {
91   - hp_analysis_cf = hp_analysis_config;
92   - hcp_analysis_cf = hcp_analysis_config;
93   - vehicle_analysis_cf = vehicle_analysis_config;
94   - hf_recg_cf = hf_recg_config;
95   - hcf_recg_cf = hcf_recg_config;
96   - vcf_recg_cf = vcf_recg_config;
97   - face_detect_cf = face_detect_config;
  88 + hp_analysis_cf = cmdConfig.hp_analysis_config;
  89 + hcp_analysis_cf = cmdConfig.hcp_analysis_config;
  90 + vehicle_analysis_cf = cmdConfig.vehicle_analysis_config;
  91 + hf_recg_cf = cmdConfig.hf_recg_config;
  92 + hcf_recg_cf = cmdConfig.hcf_recg_config;
  93 + vcf_recg_cf = cmdConfig.vcf_recg_config;
  94 + face_detect_cf = cmdConfig.face_detect_config;
98 95 char* dbpath_utf8 = nullptr;
99 96 #ifdef _MSC_VER
100 97 //dbpath_utf8 = GbkToUtf8(dbpath);
... ... @@ -2067,8 +2064,8 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, sy_
2067 2064  
2068 2065 int left = max(0, (int)(obj.left - boundaryLittle));
2069 2066 int top = max(0, (int)(obj.top - boundaryLittle));
2070   - int right = min({ frameWidth - 1, (int)(obj.right + boundaryLittle) });
2071   - int bottom = min({ frameHeight - 1, (int)(obj.bottom + boundaryLittle) });
  2067 + int right = min(frameWidth - 1, (int)(obj.right + boundaryLittle) );
  2068 + int bottom = min(frameHeight - 1, (int)(obj.bottom + boundaryLittle) );
2072 2069 snapShotInfo[newObj].frameCount = dxGpuFrame.timestamp;
2073 2070 snapShotInfo[newObj].isupdate = true;
2074 2071 snapShotInfo[newObj].lost = 0;
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h
... ... @@ -166,8 +166,9 @@ public:
166 166 std::mutex finishedThreadMutex;
167 167  
168 168 V_ANALYSIS_TYPE v_analysis;
169   - void snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, sy_command hp_analysis_config, \
170   - sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command vehicle_recg_config, sy_command vehicle_plate_det_recg_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config, sy_command face_detect_config);
  169 +
  170 + void snapshot_helper_init(int gpuid, double gpu_total_memory, char* dbpath, char* auth_license, int wait_framecount, CommandConfig cmdConfig);
  171 +
171 172 void snapshot_helper_release();
172 173 void add_task_info(int new_task_id, TASK_INFO new_task_info);
173 174 void delete_task_info(int new_task_id, TASK_INFO new_task_info);
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/sort/Sort.h
... ... @@ -66,12 +66,10 @@ private:
66 66 bool istraffic = 0; //by zl 是否统计交通量
67 67 //vector <mylist> tracker;
68 68 bool WORK = false;
69   - bool m_bYOLOv5 = true;
  69 + bool m_bYOLOv5 {true};
70 70  
71 71 private:
72 72 void associate_detections_to_trackers(vector< vector<int> > &matched, vector<int> &unmatched_dets, vector<int> &unmatched_trks, vector< vector<float> > &dets, vector< vector<float> > &trks, float iou_threshold = 0.3);
73   - //int addTracker(VPT_ObjInfo *result, int resultcount);
74   - int Traffic();
75 73 };
76 74 //辅助函数
77 75 void RectboundCheck(int Width, int Height, VPT_ObjInfo * result); //防止坐标越界 by zl
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp
... ... @@ -686,7 +686,7 @@ void create_task(const char * videoFileName, int total_index) {
686 686 strcpy(tparam.video_filename, videoFileName);
687 687 tparam.on_image_display = false;
688 688 tparam.jpeg_quality = 30; //debug by zsh
689   - tparam.decMode = 1; // 关键帧解码
  689 + tparam.decMode = 0; // 关键帧解码
690 690  
691 691 //tparam.video_filename = argv[total_index%4];
692 692 memcpy(tparam.minBoxsize, m_boxsize, sizeof(sy_rect)* DETECTTYPE);
... ... @@ -741,7 +741,7 @@ int main(int argc, char* argv[])
741 741 vptParam.wait_framecount = 30;
742 742 vptParam.serviceID = 0;
743 743 vptParam.limitSize = (10 << 20);
744   - vptParam.skip_frame = 1;
  744 + vptParam.skip_frame = 12;
745 745 strcat(vptParam.name, "gbrealtime");
746 746 strcat(vptParam.path, "./log/");
747 747 int flag = mvpt_init(&handle, vptParam);
... ... @@ -788,7 +788,7 @@ int main(int argc, char* argv[])
788 788 break;
789 789 }
790 790  
791   - } while(1) ;
  791 + } while(0) ;
792 792  
793 793 // printf("-------------------Begin rt_view_task 1 !----------------------\n");
794 794 // rt_view_task(handle, 0);
... ...