Commit c7af27aa5179d153c671fc653b586cced5b07bb4
1 parent
13fb7a26
修复崩溃问题:tasks[*iter].task_algorithm_data.frame 重复释放了两次造成
Showing
11 changed files
with
439 additions
and
491 deletions
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.cpp
... | ... | @@ -22,7 +22,6 @@ DxDecoderWrap::DxDecoderWrap( const DxConfig * cfg ) |
22 | 22 | { |
23 | 23 | m_bClose = false; |
24 | 24 | m_pDec = nullptr; |
25 | - m_pHwData = nullptr; | |
26 | 25 | |
27 | 26 | m_cfg.post_decoded_cbk = decoded_cbk; |
28 | 27 | m_cfg.decode_finished_cbk = decode_finished_cbk; |
... | ... | @@ -92,17 +91,15 @@ int DxDecoderWrap::DxCloseDecoder() |
92 | 91 | |
93 | 92 | m_queue_frames_mutex.lock(); |
94 | 93 | while (m_queue_frames.size() > 0) { |
95 | - GPUFrame * decodedFrame = m_queue_frames.front(); | |
94 | + DxGPUFrame decodedFrame = m_queue_frames.front(); | |
95 | + if (decodedFrame.frame) { | |
96 | + cudaFree(decodedFrame.frame); | |
97 | + decodedFrame.frame = nullptr; | |
98 | + } | |
96 | 99 | m_queue_frames.pop(); |
97 | - delete decodedFrame; | |
98 | - decodedFrame = nullptr; | |
99 | 100 | } |
100 | 101 | m_queue_frames_mutex.unlock(); |
101 | 102 | |
102 | - if(m_pHwData != nullptr){ | |
103 | - cudaFree(m_pHwData); | |
104 | - } | |
105 | - | |
106 | 103 | return 0; |
107 | 104 | } |
108 | 105 | |
... | ... | @@ -165,48 +162,16 @@ bool DxDecoderWrap::DxFrameIsEmpty() |
165 | 162 | } |
166 | 163 | |
167 | 164 | |
168 | -int DxDecoderWrap::DxLockFrame( DxGPUFrame * frame ) | |
165 | +int DxDecoderWrap::DxLockFrame(DxGPUFrame& frame) | |
169 | 166 | { |
170 | - if ( NULL == frame ) | |
171 | - { | |
172 | - return -1; | |
173 | - } | |
174 | - | |
175 | 167 | std::lock_guard<std::mutex> l(m_queue_frames_mutex); |
176 | 168 | |
177 | 169 | if(m_queue_frames.size() <= 0) { |
178 | 170 | return -1; |
179 | 171 | } |
180 | - GPUFrame * decodedFrame = m_queue_frames.front(); | |
172 | + frame = m_queue_frames.front(); | |
181 | 173 | m_queue_frames.pop(); |
182 | 174 | |
183 | - AVFrame* gpuFrame = decodedFrame->gpuFrame; | |
184 | - | |
185 | - cudaSetDevice(atoi(m_cfg.gpuid.c_str())); | |
186 | - cudaError_t cudaStatus; | |
187 | - size_t rgbSize = 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char); | |
188 | - unsigned char *pHwData = nullptr; | |
189 | - cudaStatus = cudaMalloc((void **)&pHwData, rgbSize); | |
190 | - if (cudaStatus != cudaSuccess) { | |
191 | - LOG_ERROR("[{}]- cudaMalloc failed !!!", m_name.c_str()); | |
192 | - return -1; | |
193 | - } | |
194 | - cuda_common::setColorSpace( ITU_709, 0 ); | |
195 | - cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height); | |
196 | - if (cudaStatus != cudaSuccess) { | |
197 | - LOG_ERROR("[{}]- CUDAToBGR failed !!!", m_name.c_str()); | |
198 | - return -1; | |
199 | - } | |
200 | - | |
201 | - frame->width = gpuFrame->width; | |
202 | - frame->height = gpuFrame->height; | |
203 | - frame->size = gpuFrame->width; | |
204 | - frame->frame = pHwData; | |
205 | - frame->timestamp = decodedFrame->ts; | |
206 | - | |
207 | - delete decodedFrame; | |
208 | - decodedFrame = nullptr; | |
209 | - | |
210 | 175 | return 0; |
211 | 176 | } |
212 | 177 | |
... | ... | @@ -215,7 +180,35 @@ void DxDecoderWrap::post_decode_thread(GPUFrame * decodedFrame) { |
215 | 180 | m_queue_frames_mutex.lock(); |
216 | 181 | if(m_queue_frames.size() < 3) { |
217 | 182 | // 入队 |
218 | - m_queue_frames.push(decodedFrame); | |
183 | + AVFrame* gpuFrame = decodedFrame->gpuFrame; | |
184 | + | |
185 | + cudaSetDevice(atoi(m_cfg.gpuid.c_str())); | |
186 | + cudaError_t cudaStatus; | |
187 | + size_t rgbSize = 3 * gpuFrame->width * gpuFrame->height * sizeof(unsigned char); | |
188 | + unsigned char *pHwData = nullptr; | |
189 | + cudaStatus = cudaMalloc((void **)&pHwData, rgbSize); | |
190 | + if (cudaStatus != cudaSuccess) { | |
191 | + LOG_ERROR("[{}]- cudaMalloc failed !!!", m_name.c_str()); | |
192 | + return ; | |
193 | + } | |
194 | + cuda_common::setColorSpace( ITU_709, 0 ); | |
195 | + cudaStatus = cuda_common::CUDAToBGR((CUdeviceptr)gpuFrame->data[0],(CUdeviceptr)gpuFrame->data[1], gpuFrame->linesize[0], gpuFrame->linesize[1], pHwData, gpuFrame->width, gpuFrame->height); | |
196 | + if (cudaStatus != cudaSuccess) { | |
197 | + LOG_ERROR("[{}]- CUDAToBGR failed !!!", m_name.c_str()); | |
198 | + return ; | |
199 | + } | |
200 | + | |
201 | + DxGPUFrame frame; | |
202 | + frame.width = gpuFrame->width; | |
203 | + frame.height = gpuFrame->height; | |
204 | + frame.size = gpuFrame->width; | |
205 | + frame.frame = pHwData; | |
206 | + frame.timestamp = decodedFrame->ts; | |
207 | + | |
208 | + delete decodedFrame; | |
209 | + decodedFrame = nullptr; | |
210 | + | |
211 | + m_queue_frames.push(frame); | |
219 | 212 | m_queue_frames_mutex.unlock(); |
220 | 213 | break; |
221 | 214 | } else { | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/DxDecoderWrap.h
... | ... | @@ -59,7 +59,7 @@ public: |
59 | 59 | int DxGetResolution( int &width, int &height ); |
60 | 60 | |
61 | 61 | bool DxFrameIsEmpty(); |
62 | - int DxLockFrame( DxGPUFrame * frame ); | |
62 | + int DxLockFrame(DxGPUFrame& frame ); | |
63 | 63 | |
64 | 64 | int PauseDecoder(); |
65 | 65 | int ResumeDecoder(); |
... | ... | @@ -76,11 +76,9 @@ private: |
76 | 76 | string m_name; |
77 | 77 | FFNvDecoder* m_pDec; |
78 | 78 | |
79 | - std::queue<GPUFrame *> m_queue_frames; | |
79 | + std::queue<DxGPUFrame> m_queue_frames; | |
80 | 80 | std::mutex m_queue_frames_mutex; |
81 | 81 | |
82 | - unsigned char *m_pHwData {nullptr}; | |
83 | - | |
84 | 82 | int m_decMode{0}; |
85 | 83 | }; |
86 | 84 | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp
... | ... | @@ -65,10 +65,11 @@ bool FFNvDecoder::init(FFDecConfig& cfg) |
65 | 65 | fp=fopen(cfg.uri.c_str(),"rb"); |
66 | 66 | if(fp!=nullptr) { |
67 | 67 | m_bReal = false; |
68 | + fclose(fp); | |
68 | 69 | } else { |
69 | 70 | m_bReal = true; |
70 | 71 | } |
71 | - fclose(fp); | |
72 | + | |
72 | 73 | |
73 | 74 | post_decoded_cbk = cfg.post_decoded_cbk; |
74 | 75 | decode_finished_cbk = cfg.decode_finished_cbk; |
... | ... | @@ -283,6 +284,10 @@ void FFNvDecoder::decode_thread() |
283 | 284 | av_packet_unref(pkt); |
284 | 285 | } |
285 | 286 | |
287 | + while(m_bRunning && mFrameQueue.size() > 0) { | |
288 | + std::this_thread::sleep_for(std::chrono::milliseconds(20)); | |
289 | + } | |
290 | + | |
286 | 291 | m_bRunning = false; |
287 | 292 | |
288 | 293 | // long end_time = get_cur_time(); |
... | ... | @@ -293,8 +298,6 @@ void FFNvDecoder::decode_thread() |
293 | 298 | pthread_join(m_post_decode_thread,0); |
294 | 299 | } |
295 | 300 | |
296 | - decode_finished_cbk(m_finishedDecArg); | |
297 | - | |
298 | 301 | // 清空队列 |
299 | 302 | while(mFrameQueue.size() > 0){ |
300 | 303 | GPUFrame * frame = mFrameQueue.front(); |
... | ... | @@ -305,6 +308,8 @@ void FFNvDecoder::decode_thread() |
305 | 308 | |
306 | 309 | decode_finished(); |
307 | 310 | |
311 | + decode_finished_cbk(m_finishedDecArg); | |
312 | + | |
308 | 313 | LOG_INFO("[{}] - decode thread exited, decoded frame count: {}", m_dec_name, decoded_frame_count); |
309 | 314 | } |
310 | 315 | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/ImageSaveGPU.cpp
... | ... | @@ -37,7 +37,7 @@ int partMemCopy(unsigned char* d_srcRGB, int src_width, int src_height, unsigned |
37 | 37 | { |
38 | 38 | cudaError_t cudaStatus = cuda_common::PartMemCopy(d_srcRGB, src_width, src_height, d_dstRGB, left, top, right, bottom); |
39 | 39 | if (cudaStatus != cudaSuccess) { |
40 | - LOG_ERROR("cuda_common::77 PartMemCopy failed: {} {} {} {} {} {} {}",cudaGetErrorString(cudaStatus), left, top, right, bottom, src_height, d_dstRGB); | |
40 | + LOG_ERROR("cuda_common::PartMemCopy failed: {} {} {} {} {} {} {}",cudaGetErrorString(cudaStatus), left, top, right, bottom, src_height, d_dstRGB); | |
41 | 41 | return -1; |
42 | 42 | } |
43 | 43 | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/NV12ToRGB.cu
... | ... | @@ -330,13 +330,13 @@ namespace cuda_common |
330 | 330 | CUDAToBGR_drvapi << < grid, block >> >((uint32 *)dataY, (uint32 *)dataUV, pitchY, pitchUV, d_dstRGB, width, height); |
331 | 331 | cudaError_t cudaStatus = cudaGetLastError(); |
332 | 332 | if (cudaStatus != cudaSuccess) { |
333 | - fprintf(stderr, "NV12ToRGB_drvapi launch failed: %s\n", cudaGetErrorString(cudaStatus)); | |
333 | + fprintf(stderr, "CUDAToBGR launch failed: %s\n", cudaGetErrorString(cudaStatus)); | |
334 | 334 | return cudaStatus; |
335 | 335 | } |
336 | 336 | |
337 | 337 | cudaStatus = cudaDeviceSynchronize(); |
338 | 338 | if (cudaStatus != cudaSuccess) { |
339 | - fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching NV12ToRGB_drvapi !\n", cudaStatus); | |
339 | + fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching CUDAToBGR !\n", cudaStatus); | |
340 | 340 | return cudaStatus; |
341 | 341 | } |
342 | 342 | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp
... | ... | @@ -23,7 +23,7 @@ |
23 | 23 | //********************************************************// |
24 | 24 | //1.Ϊʲô��ʱ�ص�index=2��ȴδ�����ﳵ�ķ�������Ϊindex�ں�����Ϊ��2�����Ǵ�ʱ�Ŀ��ղ�������֮ǰ�Ŀ��գ����Կ���δ���£�����ͼ���С����Ϊ112*224 |
25 | 25 | |
26 | -#define AUTHORIZATION | |
26 | +// #define AUTHORIZATION | |
27 | 27 | //#define DQ_AUTHORIZATION |
28 | 28 | |
29 | 29 | |
... | ... | @@ -50,6 +50,8 @@ |
50 | 50 | // #define SKIP_FRMAE 5 //��֡֡�� |
51 | 51 | #define EXTIME 500 |
52 | 52 | |
53 | +#define AUTH_LICENSE "sy_va_sub_sdk_2023" | |
54 | + | |
53 | 55 | static int TaskID = 0; |
54 | 56 | |
55 | 57 | auto show_gpu_syimage_ = [](sy_img& cur_frame) { |
... | ... | @@ -212,7 +214,8 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN |
212 | 214 | if (SUCCESS == ret) |
213 | 215 | #endif |
214 | 216 | #else |
215 | - ret = license_check(vptParam.auth_license, productSN);// sy_time_check(2022, 2); | |
217 | + // ret = license_check(vptParam.auth_license, productSN);// sy_time_check(2022, 2); | |
218 | + ret = strcmp(AUTH_LICENSE, vptParam.auth_license); | |
216 | 219 | if (ret == SUCCESS) |
217 | 220 | #endif |
218 | 221 | { |
... | ... | @@ -264,14 +267,6 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN |
264 | 267 | viewTaskID = -1; |
265 | 268 | TaskinPlay = 0; |
266 | 269 | TotalTask = 0; |
267 | - capacity = 20; | |
268 | - VPTResult.resize(capacity); | |
269 | - //dwThreadID = 0; | |
270 | - ProcessFlag = false; | |
271 | - SourceFlag = false; | |
272 | - | |
273 | - mModeSnapshotVideo = "cpu"; | |
274 | - mModeSnapshotLittle = "cpu"; | |
275 | 270 | |
276 | 271 | taskFinishCallbackFunc = nullptr; |
277 | 272 | if (tFinishCallbackFunc != nullptr) |
... | ... | @@ -291,6 +286,10 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN |
291 | 286 | |
292 | 287 | m_snaphot_helper.snapshot_helper_init(vptParam.gpuid, gpu_total_memory, vptParam.vrdbpath, vptParam.auth_license, vptParam.wait_framecount, m_hp_analysis_config, \ |
293 | 288 | 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); |
289 | + | |
290 | + m_bProcessExit = false; | |
291 | + ProcessThread = std::thread(algorthim_process_thread, this); | |
292 | + | |
294 | 293 | if (ret == SUCCESS) //�ɹ� |
295 | 294 | { |
296 | 295 | licence_status = 0; |
... | ... | @@ -365,13 +364,6 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID) |
365 | 364 | |
366 | 365 | tasks[i].frameImage.release(); |
367 | 366 | |
368 | - | |
369 | - if (tasks[i].task_algorithm_data.frame) | |
370 | - { | |
371 | - cudaFree(tasks[i].task_algorithm_data.frame); | |
372 | - tasks[i].task_algorithm_data.frame = nullptr; | |
373 | - } | |
374 | - | |
375 | 367 | FinishTaskTracker(VPT_Handle, taskID); |
376 | 368 | |
377 | 369 | if (viewTaskID == taskID) viewTaskID = -1; |
... | ... | @@ -445,13 +437,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh |
445 | 437 | |
446 | 438 | std::lock_guard<std::mutex> l(_tx_add_task); |
447 | 439 | using std::placeholders::_1; |
448 | - // printf("begin real add task\n"); | |
449 | - if (TaskinPlay >= capacity) | |
450 | - { | |
451 | - //cout << "********************** resize capacity *************************" << endl; | |
452 | - capacity *= 2; | |
453 | - VPTResult.resize(capacity); | |
454 | - } | |
455 | 440 | |
456 | 441 | Task new_task = {}; |
457 | 442 | new_task.taskID = TotalTask; |
... | ... | @@ -490,7 +475,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh |
490 | 475 | |
491 | 476 | new_task.frameImage = cv::Mat::zeros(height, width, CV_8UC3); |
492 | 477 | new_task.taskState = PLAY; |
493 | - new_task.task_algorithm_data.frame = NULL; | |
494 | 478 | new_task.taskFrameCount = 0; |
495 | 479 | new_task.taskLastFrameCount = 0; |
496 | 480 | |
... | ... | @@ -576,12 +560,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh |
576 | 560 | tasks.push_back(new_task); |
577 | 561 | |
578 | 562 | AddTaskTracker(VPT_Handle, new_task.taskID, width, height); |
579 | - | |
580 | - if (!ProcessFlag) { | |
581 | - m_bProcessExit = false; | |
582 | - ProcessThread = std::thread(algorthim_process_thread, this); | |
583 | - ProcessFlag = true; | |
584 | - } | |
585 | 563 | |
586 | 564 | AddTaskSucFlag = 1; |
587 | 565 | |
... | ... | @@ -591,12 +569,6 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh |
591 | 569 | |
592 | 570 | int CMutliSourceVideoProcess::AddOperator(task_param tparam) |
593 | 571 | { |
594 | - if (!ProcessFlag) | |
595 | - { | |
596 | - AddTask(tparam); | |
597 | - std::this_thread::sleep_for(std::chrono::milliseconds(500)); | |
598 | - } | |
599 | - else | |
600 | 572 | { |
601 | 573 | // printf("add first task in operator queue\n"); |
602 | 574 | std::unique_lock<std::mutex> l(taskMutex); |
... | ... | @@ -765,466 +737,427 @@ void CMutliSourceVideoProcess::algorthim_process() |
765 | 737 | { |
766 | 738 | set<int> k; |
767 | 739 | int count = 0; |
768 | - sy_img * batch_img = new sy_img[20]{}; | |
769 | 740 | |
770 | 741 | DxGPUFrame frame = {}; |
771 | 742 | |
772 | 743 | cudaSetDevice(mgpuid); |
773 | 744 | |
774 | - CUdevice cuDevice; | |
775 | - cuDeviceGet(&cuDevice, mgpuid); | |
776 | - CUcontext context; | |
777 | - cuCtxCreate(&context, 0, cuDevice); | |
778 | - cuCtxPushCurrent(context); | |
779 | - | |
780 | 745 | int total_count = 0; |
781 | 746 | long long begintime1 =get_cur_time_ms(); |
782 | 747 | |
783 | 748 | int process_times = 0; |
784 | 749 | |
785 | 750 | long long last_time = get_cur_time_ms(); |
786 | - | |
751 | + while (!m_bProcessExit) | |
787 | 752 | { |
788 | - while (!m_bProcessExit) | |
753 | + if (licence_status <= -3) | |
789 | 754 | { |
790 | - if (licence_status <= -3) | |
791 | - { | |
792 | - printf("authority failed!\n"); | |
793 | - break; | |
794 | - } | |
755 | + printf("authority failed!\n"); | |
756 | + break; | |
757 | + } | |
795 | 758 | |
796 | - double time_val, time_val_p = 0; | |
797 | - { | |
798 | - std::lock_guard<std::mutex> l(taskMutex); | |
799 | - OperatorTask(); | |
800 | - } | |
801 | - taskCondVar.notify_all(); | |
759 | + double time_val, time_val_p = 0; | |
760 | + { | |
761 | + std::lock_guard<std::mutex> l(taskMutex); | |
762 | + OperatorTask(); | |
763 | + } | |
764 | + | |
765 | + taskCondVar.notify_all(); | |
802 | 766 | |
803 | - int curTaskSize = tasks.size(); | |
767 | + int curTaskSize = tasks.size(); | |
804 | 768 | |
805 | - count = 0; | |
806 | - static int ncount = 0; | |
807 | - map<int, vector<int>> finishTaskDeleteObj; | |
808 | - int curPlayTaskCount = 0; | |
769 | + count = 0; | |
770 | + static int ncount = 0; | |
771 | + map<int, vector<int>> finishTaskDeleteObj; | |
772 | + int curPlayTaskCount = 0; | |
809 | 773 | |
810 | - for (int i = 0; i < curTaskSize; i++) | |
774 | + for (int i = 0; i < curTaskSize; i++) | |
775 | + { | |
776 | + if ((tasks[i].taskState == PLAY || tasks[i].taskState == DECODEERROR)) | |
811 | 777 | { |
812 | - if ((tasks[i].taskState == PLAY || tasks[i].taskState == DECODEERROR)) | |
778 | + if (!tasks[i].taskTcuvid->DxDecoderIsRun()) | |
813 | 779 | { |
814 | - if (!tasks[i].taskTcuvid->DxDecoderIsRun()) | |
815 | - { | |
816 | - cudaError_t cudaStatus = cudaGetLastError(); | |
817 | - if (cudaStatus != cudaSuccess) { | |
818 | - printf("begin finish last error: %s\n", cudaGetErrorString(cudaStatus)); | |
819 | - } | |
780 | + cudaError_t cudaStatus = cudaGetLastError(); | |
781 | + if (cudaStatus != cudaSuccess) { | |
782 | + printf("begin finish last error: %s\n", cudaGetErrorString(cudaStatus)); | |
783 | + } | |
784 | + | |
785 | + cout << "***************** Task " << i << " is Finished *****************" << endl; | |
786 | + tasks[i].taskState = FINISH; | |
787 | + | |
788 | + FinishTask(tasks[i].taskID); | |
789 | + | |
790 | + tasks[i].taskTcuvid->DxCloseDecoder(); | |
791 | + delete tasks[i].taskTcuvid; | |
792 | + tasks[i].taskTcuvid = NULL; | |
820 | 793 | |
821 | - cout << "***************** Task " << i << " is Finished *****************" << endl; | |
822 | - tasks[i].taskState = FINISH; | |
823 | - | |
824 | - FinishTask(tasks[i].taskID); | |
825 | - | |
826 | - tasks[i].taskTcuvid->DxCloseDecoder(); | |
827 | - delete tasks[i].taskTcuvid; | |
828 | - tasks[i].taskTcuvid = NULL; | |
829 | - int taskid = tasks[i].taskID; | |
830 | - | |
831 | - //ѭ���ȴ� ֱ��finished_analysis_ss_info�����и�·Ŀ�궼�Ѿ����ظ��û����ſ��������������� | |
832 | - std::unique_lock<std::mutex> lock(m_snaphot_helper.analysisThreadMutex); | |
833 | - while (std::find_if(m_snaphot_helper.finished_analysis_ss_info.begin(), m_snaphot_helper.finished_analysis_ss_info.end(), [&taskid](const std::pair<OBJ_KEY, video_object_snapshot> & item) ->bool { | |
834 | - if (item.first.videoID == taskid) | |
835 | - { | |
836 | - return true; | |
837 | - } | |
838 | - else | |
839 | - { | |
840 | - return false; | |
841 | - } | |
842 | - | |
843 | - }) != m_snaphot_helper.finished_analysis_ss_info.end()) | |
794 | + int taskid = tasks[i].taskID; | |
795 | + std::unique_lock<std::mutex> lock(m_snaphot_helper.analysisThreadMutex); | |
796 | + while (std::find_if(m_snaphot_helper.finished_analysis_ss_info.begin(), m_snaphot_helper.finished_analysis_ss_info.end(), [&taskid](const std::pair<OBJ_KEY, video_object_snapshot> & item) ->bool { | |
797 | + if (item.first.videoID == taskid) | |
844 | 798 | { |
845 | - lock.unlock(); | |
846 | - std::this_thread::yield(); | |
847 | - std::this_thread::sleep_for(std::chrono::milliseconds(100)); | |
848 | - lock.lock(); | |
799 | + return true; | |
849 | 800 | } |
850 | - | |
851 | - //�ص�֪ͨ�û� ��·����������� | |
852 | - if (taskFinishCallbackFunc != nullptr) | |
801 | + else | |
853 | 802 | { |
854 | - std::lock_guard<std::mutex> l(m_snaphot_helper.callback_tx); | |
855 | - taskFinishCallbackFunc(tasks[i].taskID); | |
803 | + return false; | |
856 | 804 | } |
857 | 805 | |
858 | - TaskinPlay--; | |
806 | + }) != m_snaphot_helper.finished_analysis_ss_info.end()) | |
807 | + { | |
808 | + lock.unlock(); | |
809 | + std::this_thread::yield(); | |
810 | + std::this_thread::sleep_for(std::chrono::milliseconds(100)); | |
811 | + lock.lock(); | |
859 | 812 | } |
860 | - } | |
861 | 813 | |
862 | - if (tasks[i].taskState == FINISH) | |
863 | - count++; | |
864 | - } | |
865 | - | |
866 | - //�������������FINISH״̬ | |
867 | - if (count >= tasks.size()) //have no decode video, break | |
868 | - { | |
869 | - { | |
870 | - std::lock_guard<std::mutex> l(taskMutex); | |
871 | - //�ж���������ȴ������Ƿ����µ��������� | |
872 | - if (HasNewTask()) | |
814 | + //�ص�֪ͨ�û� ��·����������� | |
815 | + if (taskFinishCallbackFunc != nullptr) | |
873 | 816 | { |
874 | - continue; | |
817 | + std::lock_guard<std::mutex> l(m_snaphot_helper.callback_tx); | |
818 | + taskFinishCallbackFunc(tasks[i].taskID); | |
875 | 819 | } |
876 | - else | |
877 | - { | |
878 | - //std::this_thread::sleep_for(std::chrono::milliseconds(40)); | |
879 | - //continue; | |
880 | - //printf("802 set ProcessFlag false\n"); | |
881 | 820 | |
882 | - //Sleep(10); | |
883 | - //continue; | |
884 | - | |
885 | - //printf("0708\n"); | |
886 | - //ProcessFlag = false; | |
887 | - break; | |
888 | - } | |
821 | + TaskinPlay--; | |
889 | 822 | } |
890 | 823 | } |
891 | - | |
892 | - //��ǰû��PLAY������ ѭ���ȴ� | |
893 | - curPlayTaskCount = TaskinPlay; | |
894 | - if (curPlayTaskCount <= 0) { | |
895 | - Sleep(30); | |
896 | - continue; | |
897 | - } | |
898 | 824 | |
899 | - k.clear(); | |
900 | - TaskinPlayID.clear(); | |
901 | - | |
902 | - //��ȡ�������� | |
903 | - getdata_flag: | |
904 | - for (int i = 0; i < curTaskSize; i++) | |
825 | + if (tasks[i].taskState == FINISH) | |
826 | + count++; | |
827 | + } | |
828 | + | |
829 | + //�������������FINISH״̬ | |
830 | + if (count >= tasks.size()) //have no decode video, break | |
831 | + { | |
905 | 832 | { |
906 | - if (k.find(i) == k.end() && tasks[i].taskState == PLAY && tasks[i].taskTcuvid->DxDecoderIsRun()) | |
833 | + std::lock_guard<std::mutex> l(taskMutex); | |
834 | + //�ж���������ȴ������Ƿ����µ��������� | |
835 | + if (HasNewTask()) | |
907 | 836 | { |
908 | - if(tasks[i].taskTcuvid->DxLockFrame(&tasks[i].task_algorithm_data) == 0) { | |
909 | - k.insert(i); | |
910 | - TaskinPlayID.insert(tasks[i].taskID); | |
911 | - } | |
837 | + continue; | |
912 | 838 | } |
913 | - else if (k.find(i) == k.end() && tasks[i].taskState == PLAY && !tasks[i].taskTcuvid->DxDecoderIsRun()) | |
839 | + else | |
914 | 840 | { |
915 | - tasks[i].taskState = DECODEERROR; | |
916 | - curPlayTaskCount--; | |
917 | - FinishTaskTracker(VPT_Handle, tasks[i].taskID); | |
841 | + continue; | |
918 | 842 | } |
919 | 843 | } |
844 | + } | |
920 | 845 | |
921 | - if (curPlayTaskCount <= 0) { | |
922 | - Sleep(30); | |
923 | - continue; | |
924 | - } | |
846 | + //��ǰû��PLAY������ ѭ���ȴ� | |
847 | + curPlayTaskCount = TaskinPlay; | |
848 | + if (curPlayTaskCount <= 0) { | |
849 | + Sleep(30); | |
850 | + continue; | |
851 | + } | |
925 | 852 | |
926 | - //��û�л�ȡ������·���Ľ������� ѭ���ȴ� | |
927 | - if (k.size() < curPlayTaskCount) | |
853 | + k.clear(); | |
854 | + TaskinPlayID.clear(); | |
855 | + | |
856 | + //��ȡ�������� | |
857 | + getdata_flag: | |
858 | + for (int i = 0; i < curTaskSize; i++) | |
859 | + { | |
860 | + if (k.find(i) == k.end() && tasks[i].taskState == PLAY && tasks[i].taskTcuvid->DxDecoderIsRun()) | |
928 | 861 | { |
929 | - std::this_thread::sleep_for(std::chrono::milliseconds(1)); | |
930 | - goto getdata_flag; | |
862 | + if(tasks[i].taskTcuvid->DxLockFrame(tasks[i].task_algorithm_data) == 0) { | |
863 | + k.insert(i); | |
864 | + TaskinPlayID.insert(tasks[i].taskID); | |
865 | + } | |
866 | + } | |
867 | + else if (k.find(i) == k.end() && tasks[i].taskState == PLAY && !tasks[i].taskTcuvid->DxDecoderIsRun()) | |
868 | + { | |
869 | + tasks[i].taskState = DECODEERROR; | |
870 | + curPlayTaskCount--; | |
871 | + FinishTaskTracker(VPT_Handle, tasks[i].taskID); | |
931 | 872 | } |
873 | + } | |
874 | + | |
875 | + if (curPlayTaskCount <= 0) { | |
876 | + Sleep(30); | |
877 | + continue; | |
878 | + } | |
879 | + | |
880 | + //��û�л�ȡ������·���Ľ������� ѭ���ȴ� | |
881 | + if (k.size() < curPlayTaskCount) | |
882 | + { | |
883 | + std::this_thread::sleep_for(std::chrono::milliseconds(1)); | |
884 | + goto getdata_flag; | |
885 | + } | |
932 | 886 | |
933 | 887 | #ifdef LOG_INFO2 |
934 | - long long gather_data_time = get_cur_time_ms(); | |
935 | - std::cout << "gather_data time_using: " << gather_data_time - last_time << std::endl; | |
888 | + long long gather_data_time = get_cur_time_ms(); | |
889 | + std::cout << "gather_data time_using: " << gather_data_time - last_time << std::endl; | |
936 | 890 | #endif |
937 | 891 | |
938 | - cudaDeviceSynchronize(); | |
892 | + cudaDeviceSynchronize(); | |
939 | 893 | |
940 | - //------------------------------ ͳһBATCH���� --------------------------------// | |
941 | - ////////////////////////////////////////////////////////////// | |
942 | - //// | |
943 | - //// compose data -> batch | |
944 | - //// | |
945 | - ///////////////////////////////////////////////////////////// | |
946 | 894 | |
947 | - vector<vector<int>> deleteObjectID; | |
948 | - set<int>::iterator iter = TaskinPlayID.begin(); | |
895 | + vector<vector<int>> deleteObjectID; | |
896 | + set<int>::iterator iter = TaskinPlayID.begin(); | |
949 | 897 | |
950 | - int cur_batch_size = 0; | |
951 | - cur_batch_size = section_batch_size; | |
898 | + int cur_batch_size = 0; | |
899 | + cur_batch_size = section_batch_size; | |
952 | 900 | |
953 | - if (0) | |
901 | + if (0) | |
902 | + { | |
903 | + if (section_batch_size == 20) | |
904 | + cur_batch_size = section_batch_size; | |
905 | + else | |
954 | 906 | { |
955 | - if (section_batch_size == 20) | |
956 | - cur_batch_size = section_batch_size; | |
957 | - else | |
958 | - { | |
959 | - if (curPlayTaskCount <= 2 * section_batch_size) | |
960 | - cur_batch_size = section_batch_size; | |
961 | - else if (curPlayTaskCount >= 2 * MAX_BATCH) | |
962 | - cur_batch_size = MAX_BATCH; | |
963 | - else | |
964 | - cur_batch_size = curPlayTaskCount / 2 + (curPlayTaskCount % 2); | |
965 | - } | |
907 | + if (curPlayTaskCount <= 2 * section_batch_size) | |
908 | + cur_batch_size = section_batch_size; | |
909 | + else if (curPlayTaskCount >= 2 * MAX_BATCH) | |
910 | + cur_batch_size = MAX_BATCH; | |
911 | + else | |
912 | + cur_batch_size = curPlayTaskCount / 2 + (curPlayTaskCount % 2); | |
966 | 913 | } |
967 | - | |
968 | - long long start_time_vpt = get_cur_time_ms(); | |
914 | + } | |
915 | + | |
916 | + long long start_time_vpt = get_cur_time_ms(); | |
917 | + | |
918 | + sy_img batch_img[TaskinPlayID.size()]; | |
919 | + vector<vector<VPT_Result>> unUsedResult; | |
920 | + vector<unsigned long long> vec_frameIndex; | |
921 | + vector<VPT_Result> VPTResult(TaskinPlayID.size()); | |
922 | + unUsedResult.resize(TaskinPlayID.size()); | |
923 | + int cycleTimes = curPlayTaskCount / cur_batch_size + (curPlayTaskCount % cur_batch_size == 0 ? 0 : 1); | |
924 | + for (int c = 0; c < cycleTimes; c++) | |
925 | + { | |
926 | + int batchsize = c == cycleTimes - 1 ? (curPlayTaskCount - cur_batch_size*c) : cur_batch_size; | |
927 | + int startbatch = c*cur_batch_size; | |
969 | 928 | |
970 | - vector<vector<VPT_Result>> unUsedResult; | |
971 | - vector<unsigned long long> vec_frameIndex; | |
972 | - unUsedResult.resize(VPTResult.size()); | |
973 | - int cycleTimes = curPlayTaskCount / cur_batch_size + (curPlayTaskCount % cur_batch_size == 0 ? 0 : 1); | |
974 | - for (int c = 0; c < cycleTimes; c++) | |
929 | + vec_frameIndex.clear(); | |
930 | + for (int i = 0; i < batchsize; i++) | |
975 | 931 | { |
976 | - int batchsize = c == cycleTimes - 1 ? (curPlayTaskCount - cur_batch_size*c) : cur_batch_size; | |
977 | - int startbatch = c*cur_batch_size; | |
932 | + DxGPUFrame task_algorithm_data = tasks[*iter].task_algorithm_data; | |
933 | + int w = task_algorithm_data.width; | |
934 | + int h = task_algorithm_data.height; | |
935 | + int npitch = task_algorithm_data.size; | |
978 | 936 | |
979 | - vec_frameIndex.clear(); | |
980 | - for (int i = 0; i < batchsize; i++) | |
981 | - { | |
982 | - DxGPUFrame task_algorithm_data = tasks[*iter].task_algorithm_data; | |
983 | - int w = task_algorithm_data.width; | |
984 | - int h = task_algorithm_data.height; | |
985 | - int npitch = task_algorithm_data.size; | |
986 | - | |
987 | - batch_img[i].set_data(w, h, 3, (unsigned char *)task_algorithm_data.frame); | |
988 | - vec_frameIndex.push_back(task_algorithm_data.timestamp); | |
989 | - iter++; | |
990 | - } | |
937 | + batch_img[i].set_data(w, h, 3, (unsigned char *)task_algorithm_data.frame); | |
938 | + vec_frameIndex.push_back(task_algorithm_data.timestamp); | |
939 | + iter++; | |
940 | + } | |
991 | 941 | |
992 | - vector<vector<int>> tempDeleteObjectID; | |
993 | - tempDeleteObjectID.resize(batchsize); | |
994 | - int flag = VPT_Process_GPU(GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, VPTResult, tempDeleteObjectID, unUsedResult); | |
995 | - process_times++ ; | |
996 | - | |
997 | - for (auto iter : tempDeleteObjectID) | |
998 | - { | |
999 | - deleteObjectID.push_back(iter); | |
1000 | - } | |
1001 | - vector<vector<int>>().swap(tempDeleteObjectID); | |
942 | + vector<vector<int>> tempDeleteObjectID; | |
943 | + tempDeleteObjectID.resize(batchsize); | |
944 | + int flag = VPT_Process_GPU(GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, VPTResult, tempDeleteObjectID, unUsedResult); | |
945 | + process_times++ ; | |
946 | + | |
947 | + for (auto iter : tempDeleteObjectID) | |
948 | + { | |
949 | + deleteObjectID.push_back(iter); | |
1002 | 950 | } |
951 | + vector<vector<int>>().swap(tempDeleteObjectID); | |
952 | + } | |
953 | + | |
1003 | 954 | #ifdef LOG_INFO2 |
1004 | - std::cout << "VPT_Process_GPU time_using: " << get_cur_time_ms() - start_time_vpt << std::endl; | |
955 | + std::cout << "VPT_Process_GPU time_using: " << get_cur_time_ms() - start_time_vpt << std::endl; | |
1005 | 956 | #endif |
957 | + | |
958 | + long long result_analysis_time = get_cur_time_ms(); | |
959 | + | |
960 | + iter = TaskinPlayID.begin(); | |
961 | + for (int i = 0; i < curPlayTaskCount; i++) | |
962 | + { | |
963 | + Task task = tasks[*iter]; | |
964 | + task.taskFrameCount = task.task_algorithm_data.timestamp; | |
965 | + //若该路任务当前帧未检测到目标,返回ID为-1的目标表明未检测到目标 | |
966 | + if (VPTResult[i].objCount == 0) | |
967 | + { | |
968 | + callTaskObjInfoCallbackFunc(0, nullptr, task.taskFrameCount, *iter); | |
969 | + } | |
1006 | 970 | |
1007 | - long long result_analysis_time = get_cur_time_ms(); | |
971 | + //实时查看模块,若存在实时查看,把当前视频画面cp回内存 | |
972 | + bool view = false; | |
973 | + int frameHeight = task.task_algorithm_data.height; | |
974 | + int frameWidth = task.task_algorithm_data.width; | |
1008 | 975 | |
1009 | - iter = TaskinPlayID.begin(); | |
1010 | - for (int i = 0; i < curPlayTaskCount; i++) | |
976 | + if (*iter == viewTaskID) | |
1011 | 977 | { |
1012 | - Task task = tasks[*iter]; | |
1013 | - task.taskFrameCount = task.task_algorithm_data.timestamp; | |
1014 | - //若该路任务当前帧未检测到目标,返回ID为-1的目标表明未检测到目标 | |
1015 | - if (VPTResult[i].objCount == 0) | |
1016 | - { | |
1017 | - callTaskObjInfoCallbackFunc(0, nullptr, task.taskFrameCount, *iter); | |
1018 | - } | |
1019 | - | |
1020 | - //实时查看模块,若存在实时查看,把当前视频画面cp回内存 | |
1021 | - bool view = false; | |
1022 | - int frameHeight = task.task_algorithm_data.height; | |
1023 | - int frameWidth = task.task_algorithm_data.width; | |
978 | + cudaMemcpy(task.frameImage.data, task.task_algorithm_data.frame, 3 * task.task_algorithm_data.width * task.task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
979 | + view = true; | |
980 | + } | |
1024 | 981 | |
1025 | - if (*iter == viewTaskID) | |
982 | + //跟踪帧也需要返回跟踪的结果 | |
983 | + if (task.taskLastFrameCount > 0) | |
984 | + { | |
985 | + vector<VPT_Result> OneUnUsedResult = unUsedResult[i]; | |
986 | + if (OneUnUsedResult.size() == 0) | |
1026 | 987 | { |
1027 | - cudaMemcpy(task.frameImage.data, task.task_algorithm_data.frame, 3 * task.task_algorithm_data.width * task.task_algorithm_data.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
1028 | - view = true; | |
988 | + callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + 1, *iter); | |
1029 | 989 | } |
1030 | - | |
1031 | - //跟踪帧也需要返回跟踪的结果 | |
1032 | - if (task.taskLastFrameCount > 0) | |
990 | + for (int k = 0; k < OneUnUsedResult.size(); ++k) | |
1033 | 991 | { |
1034 | - vector<VPT_Result> OneUnUsedResult = unUsedResult[i]; | |
1035 | - if (OneUnUsedResult.size() == 0) | |
992 | + if (OneUnUsedResult[k].objCount == 0) | |
1036 | 993 | { |
1037 | - callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + 1, *iter); | |
994 | + callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + k + 1, *iter); | |
1038 | 995 | } |
1039 | - for (int k = 0; k < OneUnUsedResult.size(); ++k) | |
996 | + else | |
1040 | 997 | { |
1041 | - if (OneUnUsedResult[k].objCount == 0) | |
1042 | - { | |
1043 | - callTaskObjInfoCallbackFunc(0, nullptr, task.taskLastFrameCount + k + 1, *iter); | |
1044 | - } | |
1045 | - else | |
1046 | - { | |
1047 | - //cout << "OneUnUsedResult.size = " << OneUnUsedResult.size() << " k=" << k << " OneUnUsedResult[k].objCount = " << OneUnUsedResult[k].objCount << endl; | |
1048 | - callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, task.taskLastFrameCount + k + 1, *iter); | |
1049 | - } | |
998 | + //cout << "OneUnUsedResult.size = " << OneUnUsedResult.size() << " k=" << k << " OneUnUsedResult[k].objCount = " << OneUnUsedResult[k].objCount << endl; | |
999 | + callTaskObjInfoCallbackFunc(OneUnUsedResult[k].objCount, OneUnUsedResult[k].obj, task.taskLastFrameCount + k + 1, *iter); | |
1050 | 1000 | } |
1051 | 1001 | } |
1052 | - task.taskLastFrameCount = task.taskFrameCount; | |
1053 | - | |
1054 | - unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{};// = new unsigned char*[VPTResult[i].objCount]; | |
1055 | - int snapshot_left[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; | |
1056 | - int snapshot_right[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; | |
1057 | - int snapshot_top[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; | |
1058 | - int snapshot_bottom[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; | |
1059 | - int snapshot_dst_width[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; | |
1060 | - int snapshot_dst_height[MAX_OBJ_COUNT]{};// = new int[VPTResult[i].objCount]; | |
1061 | - | |
1062 | - int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 | |
1063 | - vector<int> human_idx; //用于记录快照数组中那些是人脸 | |
1064 | - vector<OBJ_KEY> human_obj_keys; | |
1065 | - | |
1066 | - callTaskObjInfoCallbackFunc(VPTResult[i].objCount, VPTResult[i].obj, task.taskFrameCount, *iter); | |
1067 | - for (int c = 0; c < VPTResult[i].objCount; c++) | |
1068 | - { | |
1069 | - OBJ_KEY newObj = { (*iter), VPTResult[i].obj[c].id }; | |
1002 | + } | |
1003 | + task.taskLastFrameCount = task.taskFrameCount; | |
1070 | 1004 | |
1071 | - //实时查看模块 绘制目标框到画面上 | |
1072 | - if (view) | |
1073 | - { | |
1074 | - int index = m_snaphot_helper.getIndexByKey(newObj); | |
1075 | - if(index < 0) { | |
1076 | - index = VPTResult[i].obj[c].index; | |
1077 | - } | |
1005 | + unsigned char* snapshot_image_data[MAX_OBJ_COUNT]{}; | |
1006 | + int snapshot_left[MAX_OBJ_COUNT]{}; | |
1007 | + int snapshot_right[MAX_OBJ_COUNT]{}; | |
1008 | + int snapshot_top[MAX_OBJ_COUNT]{}; | |
1009 | + int snapshot_bottom[MAX_OBJ_COUNT]{}; | |
1010 | + int snapshot_dst_width[MAX_OBJ_COUNT]{}; | |
1011 | + int snapshot_dst_height[MAX_OBJ_COUNT]{}; | |
1078 | 1012 | |
1079 | - //cout << "---- vew ---- "; | |
1080 | - int p1 = VPTResult[i].obj[c].left - 10 > 0 ? VPTResult[i].obj[c].left - 10 : 0; | |
1081 | - int p2 = VPTResult[i].obj[c].top - 15 > 0 ? VPTResult[i].obj[c].top - 15 : 0; | |
1082 | - | |
1083 | - cv::rectangle(task.frameImage, Rect(VPTResult[i].obj[c].left, VPTResult[i].obj[c].top, | |
1084 | - VPTResult[i].obj[c].right - VPTResult[i].obj[c].left, | |
1085 | - VPTResult[i].obj[c].bottom - VPTResult[i].obj[c].top), Scalar(158, 52, 254), 3, 1, 0); | |
1086 | - #ifdef _MSC_VER | |
1087 | - string resss = "" + to_string(index) + " " + ObjTypes[index]; | |
1088 | - putTextZH(task.frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); | |
1089 | - #else | |
1090 | - string resss = "" + to_string(VPTResult[i].obj[c].id) + " " + ObjTypesEnglish[VPTResult[i].obj[c].index]; | |
1091 | - cv::putText(task.frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); | |
1092 | - #endif | |
1013 | + int copy_obj_count = 0; //用于记录该路有多少个目标需要进行显存图像的更新 | |
1014 | + vector<int> human_idx; //用于记录快照数组中那些是人脸 | |
1015 | + vector<OBJ_KEY> human_obj_keys; | |
1016 | + | |
1017 | + callTaskObjInfoCallbackFunc(VPTResult[i].objCount, VPTResult[i].obj, task.taskFrameCount, *iter); | |
1018 | + | |
1019 | + for (int c = 0; c < VPTResult[i].objCount; c++) | |
1020 | + { | |
1021 | + VPT_ObjInfo obj = VPTResult[i].obj[c]; | |
1022 | + | |
1023 | + OBJ_KEY newObj = { (*iter), obj.id }; | |
1024 | + | |
1025 | + //实时查看模块 绘制目标框到画面上 | |
1026 | + if (view) | |
1027 | + { | |
1028 | + int index = m_snaphot_helper.getIndexByKey(newObj); | |
1029 | + if(index < 0) { | |
1030 | + index = obj.index; | |
1093 | 1031 | } |
1094 | 1032 | |
1095 | - CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, VPTResult[i].obj[c], task); | |
1096 | - if(crop_info.bCrop){ | |
1097 | - snapshot_image_data[copy_obj_count] = crop_info.snapshot_image_data; | |
1098 | - snapshot_left[copy_obj_count] = crop_info.snapshot_left; | |
1099 | - snapshot_top[copy_obj_count] = crop_info.snapshot_top; | |
1100 | - snapshot_right[copy_obj_count] = crop_info.snapshot_right; | |
1101 | - snapshot_bottom[copy_obj_count] = crop_info.snapshot_bottom; | |
1102 | - snapshot_dst_width[copy_obj_count] = crop_info.snapshot_dst_width; | |
1103 | - snapshot_dst_height[copy_obj_count] = crop_info.snapshot_dst_height; | |
1104 | - | |
1105 | - int index = m_snaphot_helper.getIndexByKey(newObj); | |
1106 | - if(0 == index) { | |
1107 | - human_idx.push_back(copy_obj_count); | |
1108 | - human_obj_keys.emplace_back(newObj); | |
1109 | - } | |
1033 | + //cout << "---- vew ---- "; | |
1034 | + int p1 = obj.left - 10 > 0 ? obj.left - 10 : 0; | |
1035 | + int p2 = obj.top - 15 > 0 ? obj.top - 15 : 0; | |
1036 | + | |
1037 | + cv::rectangle(task.frameImage, Rect(obj.left, obj.top, | |
1038 | + obj.right - obj.left, | |
1039 | + obj.bottom - obj.top), Scalar(158, 52, 254), 3, 1, 0); | |
1040 | + #ifdef _MSC_VER | |
1041 | + string resss = "" + to_string(index) + " " + ObjTypes[index]; | |
1042 | + putTextZH(task.frameImage, resss.c_str(), { p1, p2 }, Scalar(20, 255, 20), 14, "Arial"); | |
1043 | + #else | |
1044 | + string resss = "" + to_string(obj.id) + " " + ObjTypesEnglish[obj.index]; | |
1045 | + cv::putText(task.frameImage, resss.c_str(), cv::Point(p1, p2), cv::FONT_HERSHEY_COMPLEX, 2, Scalar(20, 255, 20), 2, 8, 0); | |
1046 | + #endif | |
1047 | + } | |
1110 | 1048 | |
1111 | - copy_obj_count++; | |
1049 | + CropInfo crop_info = m_snaphot_helper.cacheSnapShotInfo(newObj, obj, task); | |
1050 | + if(crop_info.bCrop){ | |
1051 | + snapshot_image_data[copy_obj_count] = crop_info.snapshot_image_data; | |
1052 | + snapshot_left[copy_obj_count] = crop_info.snapshot_left; | |
1053 | + snapshot_top[copy_obj_count] = crop_info.snapshot_top; | |
1054 | + snapshot_right[copy_obj_count] = crop_info.snapshot_right; | |
1055 | + snapshot_bottom[copy_obj_count] = crop_info.snapshot_bottom; | |
1056 | + snapshot_dst_width[copy_obj_count] = crop_info.snapshot_dst_width; | |
1057 | + snapshot_dst_height[copy_obj_count] = crop_info.snapshot_dst_height; | |
1058 | + | |
1059 | + int index = m_snaphot_helper.getIndexByKey(newObj); | |
1060 | + if(0 == index) { | |
1061 | + human_idx.push_back(copy_obj_count); | |
1062 | + human_obj_keys.emplace_back(newObj); | |
1112 | 1063 | } |
1064 | + | |
1065 | + copy_obj_count++; | |
1113 | 1066 | } |
1067 | + } | |
1114 | 1068 | |
1115 | - //若待抠图的快照数不为0 则进行批量抠图 | |
1116 | - if (0 != copy_obj_count) | |
1069 | + //若待抠图的快照数不为0 则进行批量抠图 | |
1070 | + if (0 != copy_obj_count) | |
1071 | + { | |
1072 | + PartMemResizeBatch((unsigned char*)task.task_algorithm_data.frame, frameWidth, frameHeight, | |
1073 | + 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); | |
1074 | + | |
1075 | + //最新刚添加的人脸检测模块,针对存在的行人快照进行人脸检测+人脸快照框的优选 | |
1076 | + if (m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty()) | |
1117 | 1077 | { |
1118 | - cudaSetDevice(mgpuid); | |
1119 | - cuCtxPushCurrent(context); | |
1120 | - PartMemResizeBatch((unsigned char*)task.task_algorithm_data.frame, frameWidth, frameHeight, | |
1121 | - 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); | |
1122 | - cuCtxPopCurrent(&context); | |
1123 | - | |
1124 | - //最新刚添加的人脸检测模块,针对存在的行人快照进行人脸检测+人脸快照框的优选 | |
1125 | - if (m_face_det_config == SY_CONFIG_OPEN && !human_idx.empty()) | |
1078 | + //需要做人脸检测 | |
1079 | + int human_count = human_idx.size(); | |
1080 | + sy_img human_img[human_count]; | |
1081 | + sy_point ori_points[human_count]; | |
1082 | + for (int idx = 0; idx < human_count; idx++) | |
1126 | 1083 | { |
1127 | - //需要做人脸检测 | |
1128 | - int human_count = human_idx.size(); | |
1129 | - sy_img human_img[human_count]; | |
1130 | - sy_point ori_points[human_count]; | |
1131 | - for (int idx = 0; idx < human_count; idx++) | |
1132 | - { | |
1133 | - int ii = human_idx[idx]; | |
1134 | - human_img[idx].set_data(snapshot_dst_width[ii], snapshot_dst_height[ii], 3, snapshot_image_data[ii]); | |
1135 | - ori_points[idx].x_ = (snapshot_right[ii] - snapshot_left[ii]); | |
1136 | - ori_points[idx].y_ = (snapshot_bottom[ii] - snapshot_top[ii]); | |
1137 | - } | |
1138 | - | |
1139 | - m_snaphot_helper.cacheFaceSnapshotInfo(human_img, human_count, ori_points, human_idx, human_obj_keys, snapshot_left, snapshot_top, task); | |
1084 | + int ii = human_idx[idx]; | |
1085 | + human_img[idx].set_data(snapshot_dst_width[ii], snapshot_dst_height[ii], 3, snapshot_image_data[ii]); | |
1086 | + ori_points[idx].x_ = (snapshot_right[ii] - snapshot_left[ii]); | |
1087 | + ori_points[idx].y_ = (snapshot_bottom[ii] - snapshot_top[ii]); | |
1140 | 1088 | } |
1141 | - } | |
1142 | 1089 | |
1143 | - //实时查看 绘制目标轨迹 回调函数返回 | |
1144 | - if (view) | |
1145 | - { | |
1146 | - DrawTracker(VPT_Handle, *iter, &task.frameImage); | |
1147 | - if (task.taskRealTimeCallbackFunc != nullptr) | |
1148 | - task.taskRealTimeCallbackFunc(task.frameImage.data, task.frameImage.rows, task.frameImage.cols); | |
1090 | + m_snaphot_helper.cacheFaceSnapshotInfo(human_img, human_count, ori_points, human_idx, human_obj_keys, snapshot_left, snapshot_top, task); | |
1149 | 1091 | } |
1150 | - // tasks[*iter].taskFrameCount += skip_frame_; | |
1151 | - iter++; | |
1152 | 1092 | } |
1153 | 1093 | |
1094 | + //实时查看 绘制目标轨迹 回调函数返回 | |
1095 | + if (view) | |
1096 | + { | |
1097 | + DrawTracker(VPT_Handle, *iter, &task.frameImage); | |
1098 | + if (task.taskRealTimeCallbackFunc != nullptr) | |
1099 | + task.taskRealTimeCallbackFunc(task.frameImage.data, task.frameImage.rows, task.frameImage.cols); | |
1100 | + } | |
1101 | + // tasks[*iter].taskFrameCount += skip_frame_; | |
1102 | + iter++; | |
1103 | + } | |
1104 | + | |
1154 | 1105 | #ifdef LOG_INFO2 |
1155 | - long long result_analysis_time2 = get_cur_time_ms(); | |
1156 | - cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; | |
1106 | + long long result_analysis_time2 = get_cur_time_ms(); | |
1107 | + cout << "result_analysis time_using:" << result_analysis_time2 - result_analysis_time << endl; | |
1157 | 1108 | #endif |
1158 | 1109 | |
1159 | - AttributionAnalysis = false; | |
1110 | + AttributionAnalysis = false; | |
1160 | 1111 | |
1161 | - long long second_analysis_time = get_cur_time_ms(); | |
1112 | + long long second_analysis_time = get_cur_time_ms(); | |
1162 | 1113 | |
1163 | - auto task_iter = TaskinPlayID.begin(); | |
1164 | - for (int i = 0; i < curPlayTaskCount; i++) | |
1114 | + auto task_iter = TaskinPlayID.begin(); | |
1115 | + for (int i = 0; i < curPlayTaskCount; i++) | |
1116 | + { | |
1117 | + for (int j = 0; j < deleteObjectID[i].size(); j++) | |
1165 | 1118 | { |
1166 | - for (int j = 0; j < deleteObjectID[i].size(); j++) | |
1167 | - { | |
1168 | - OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; | |
1169 | - m_snaphot_helper.SaveResultInFile(deleteObj); | |
1170 | - } | |
1171 | - | |
1172 | - task_iter++; | |
1119 | + OBJ_KEY deleteObj = { *task_iter, deleteObjectID[i][j] }; | |
1120 | + m_snaphot_helper.SaveResultInFile(deleteObj); | |
1173 | 1121 | } |
1174 | 1122 | |
1175 | - for (auto task_id: TaskinPlayID) { | |
1176 | - cudaFree(tasks[task_id].task_algorithm_data.frame); | |
1177 | - } | |
1178 | - | |
1123 | + task_iter++; | |
1124 | + } | |
1179 | 1125 | |
1180 | - for (int i = 0; i < deleteObjectID.size(); i++) | |
1181 | - vector<int>().swap(deleteObjectID[i]); | |
1182 | - vector<vector<int>>().swap(deleteObjectID); | |
1126 | + for (auto task_id: TaskinPlayID) { | |
1127 | + cudaFree(tasks[task_id].task_algorithm_data.frame); | |
1128 | + tasks[task_id].task_algorithm_data.frame = nullptr; | |
1129 | + } | |
1130 | + | |
1183 | 1131 | |
1184 | - m_snaphot_helper.object_attri_analysis(); | |
1132 | + for (int i = 0; i < deleteObjectID.size(); i++) | |
1133 | + vector<int>().swap(deleteObjectID[i]); | |
1134 | + vector<vector<int>>().swap(deleteObjectID); | |
1135 | + | |
1136 | + m_snaphot_helper.object_attri_analysis(); | |
1137 | + cudaError_t cudaStatus = cudaGetLastError(); | |
1138 | + if (cudaStatus != cudaSuccess) { | |
1139 | + LOG_ERROR("object_attri_analysis last error: {}", cudaGetErrorString(cudaStatus)); | |
1140 | + } | |
1185 | 1141 | |
1186 | 1142 | #ifdef LOG_INFO2 |
1187 | - long long second_analysis_time2 = get_cur_time_ms(); | |
1188 | - cout << "second_analysis time_using:" << second_analysis_time2 - second_analysis_time << endl; | |
1143 | + long long second_analysis_time2 = get_cur_time_ms(); | |
1144 | + cout << "second_analysis time_using:" << second_analysis_time2 - second_analysis_time << endl; | |
1189 | 1145 | #endif |
1190 | - | |
1191 | - cudaError_t cudaStatus = cudaGetLastError(); | |
1192 | - if (cudaStatus != cudaSuccess) { | |
1193 | - LOG_ERROR("object_attri_analysis last error: {}", cudaGetErrorString(cudaStatus)); | |
1194 | - } | |
1195 | 1146 | |
1196 | - std::this_thread::sleep_for(std::chrono::milliseconds(1)); | |
1197 | - | |
1198 | - ++total_count; | |
1199 | - ++ncount; | |
1147 | + ++total_count; | |
1148 | + ++ncount; | |
1200 | 1149 | |
1201 | 1150 | #ifdef LOG_INFO2 |
1202 | - last_time = get_cur_time_ms(); | |
1203 | - cout << "process time_using:" << last_time - gather_data_time << endl; | |
1204 | - cout << endl; | |
1151 | + last_time = get_cur_time_ms(); | |
1152 | + cout << "process time_using:" << last_time - gather_data_time << endl; | |
1153 | + cout << endl; | |
1205 | 1154 | #endif |
1206 | - } | |
1207 | 1155 | } |
1208 | - //catch (exception &e) | |
1209 | - { | |
1210 | - //os << 51 << e.what()<< std::endl; | |
1211 | - /* std::cout << e.what() << std::endl; | |
1212 | - exit(-1);*/ | |
1213 | - } | |
1214 | - long long costTime1 = get_cur_time_ms() - begintime1; | |
1215 | - LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times); | |
1216 | 1156 | |
1217 | 1157 | m_snaphot_helper.clearSnapshotInfo(); |
1218 | - ProcessFlag = false; | |
1219 | 1158 | |
1220 | - if (batch_img != NULL) | |
1221 | - { | |
1222 | - delete[] batch_img; | |
1223 | - batch_img = NULL; | |
1224 | - } | |
1225 | - | |
1226 | - cuCtxPopCurrent(nullptr); | |
1227 | - cuCtxDestroy(context); | |
1159 | + long long costTime1 = get_cur_time_ms() - begintime1; | |
1160 | + LOG_INFO("Process Thread is Finished. total frame cost time = {} ms, process times: {}", costTime1, process_times); | |
1228 | 1161 | } |
1229 | 1162 | |
1230 | 1163 | int CMutliSourceVideoProcess::GetRuningNb() { | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h
... | ... | @@ -136,24 +136,17 @@ public: |
136 | 136 | void algorthim_process(); |
137 | 137 | |
138 | 138 | private: |
139 | - //bool ChangeTask; | |
140 | - //HANDLE handle_process; | |
141 | 139 | std::thread ProcessThread; |
142 | 140 | std::mutex _tx_add_task; |
143 | 141 | |
144 | - | |
145 | - //DWORD dwThreadID; | |
146 | 142 | deque<Operator> TaskOperatorQ; |
147 | 143 | int capacity; |
148 | - | |
149 | - //cv::Mat objSnapshot; | |
150 | 144 | |
151 | 145 | double gpu_total_memory; |
152 | 146 | std::thread thrd; |
153 | 147 | void* authority_handle; |
154 | 148 | |
155 | 149 | public: /*锟斤拷锟斤拷锟斤拷锟斤拷应锟斤拷锟斤拷public锟斤拷 锟斤拷锟斤拷锟斤拷锟竭程猴拷锟斤拷锟叫伙拷锟矫碉拷锟斤拷锟铰碉拷锟斤拷锟斤拷 每锟斤拷锟斤拷写一锟斤拷get锟斤拷锟斤拷太锟斤拷锟斤拷锟斤拷*/ |
156 | - //fstream fout[THREAD_COUNT]; //锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 | |
157 | 150 | void * VPT_Handle; |
158 | 151 | int section_batch_size; |
159 | 152 | int licence_status; |
... | ... | @@ -165,19 +158,8 @@ public: /*锟斤拷锟斤拷锟斤拷锟斤拷应锟斤拷锟斤拷public锟斤拷 锟斤拷锟斤拷锟斤拷 |
165 | 158 | int TaskinPlay; |
166 | 159 | int TotalTask; |
167 | 160 | set<int> TaskinPlayID; |
168 | -// float* pDataToVPT; | |
169 | - vector<VPT_Result> VPTResult; | |
170 | - std::atomic<bool> ProcessFlag; | |
171 | - bool SourceFlag; | |
172 | - //float* imgDataHost; | |
173 | - //float* snapshotDataHost; | |
174 | - unsigned char* imgDataDecive; | |
175 | - // void * FrameTemp; | |
176 | - char* mModeSnapshotVideo; | |
177 | - char* mModeSnapshotLittle; | |
178 | - int viewTaskID; | |
179 | 161 | |
180 | - map<int, set<int>> objDelete; | |
162 | + int viewTaskID; | |
181 | 163 | |
182 | 164 | FINISH_CALLBACK taskFinishCallbackFunc; |
183 | 165 | OBJECT_INFO_CALLBACK taskObjInfoCallbackFunc; | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/CropImg.cu
... | ... | @@ -170,6 +170,17 @@ namespace cudacommon { |
170 | 170 | dim3 grid((dst_width + (block.x - 1)) / block.x, (dst_height + (block.y - 1)) / block.y, 1); |
171 | 171 | //kernel_bilinear << < grid, block >> >(d_srcRGB_original, d_dstRGB_original, src_width, src_height, dst_width, dst_height); |
172 | 172 | ResizeImgBilinearBGR_CUDAKernel << < grid, block >> > (d_srcRGB, d_dstRGB, src_width, src_height, dst_width, dst_height); |
173 | + | |
174 | + cudaError_t cudaStatus = cudaGetLastError(); | |
175 | + if (cudaStatus != cudaSuccess) { | |
176 | + printf("ResizeImgBilinearBGR_CUDAKernel launch failed: %s\n", cudaGetErrorString(cudaStatus)); | |
177 | + } | |
178 | + | |
179 | + cudaStatus = cudaDeviceSynchronize(); | |
180 | + if (cudaStatus != cudaSuccess) { | |
181 | + printf("cudaDeviceSynchronize returned error code %d after launching CropImgGpu!\n", cudaStatus); | |
182 | + } | |
183 | + | |
173 | 184 | return; |
174 | 185 | } |
175 | 186 | |
... | ... | @@ -180,6 +191,16 @@ namespace cudacommon { |
180 | 191 | dim3 block(32, 16, 1); |
181 | 192 | dim3 grid((dst_width + (block.x - 1)) / block.x, (dst_height + (block.y - 1)) / block.y, 1); |
182 | 193 | ResizeImgBilinearBGR_uint8 << < grid, block >> > (d_srcRGB, d_dstRGB, src_width, src_height, dst_width, dst_height); |
194 | + | |
195 | + cudaError_t cudaStatus = cudaGetLastError(); | |
196 | + if (cudaStatus != cudaSuccess) { | |
197 | + printf("ResizeImgBilinearBGR_CUDAKernel launch failed: %s\n", cudaGetErrorString(cudaStatus)); | |
198 | + } | |
199 | + | |
200 | + cudaStatus = cudaDeviceSynchronize(); | |
201 | + if (cudaStatus != cudaSuccess) { | |
202 | + printf("cudaDeviceSynchronize returned error code %d after launching CropImgGpu!\n", cudaStatus); | |
203 | + } | |
183 | 204 | return; |
184 | 205 | } |
185 | 206 | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp
... | ... | @@ -325,7 +325,7 @@ void snapshot_helper::save_without_analysis(OBJ_KEY obj_key) |
325 | 325 | iter->second.snapShotLittle.frame = NULL; |
326 | 326 | snapShotInfo[obj_key].snapShotLittle.frame = NULL; |
327 | 327 | } |
328 | - snapShotInfo.erase(iter); | |
328 | + erase_snapshot_info(obj_key); | |
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
... | ... | @@ -557,7 +557,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 |
557 | 557 | cudaFree(iter->second.snapShotLittle.frame); |
558 | 558 | iter->second.snapShotLittle.frame = NULL; |
559 | 559 | } |
560 | - snapShotInfo.erase(iter); | |
560 | + erase_snapshot_info(hp_keys[k]); | |
561 | 561 | } |
562 | 562 | } |
563 | 563 | |
... | ... | @@ -637,13 +637,13 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 |
637 | 637 | int count_bike_size = count_bike.size(); |
638 | 638 | for (int c = 0; c < count_bike_size; c++) |
639 | 639 | { |
640 | - OBJ_KEY iter = count_bike.front(); | |
640 | + OBJ_KEY iter_bike = count_bike.front(); | |
641 | 641 | count_bike.pop(); |
642 | 642 | |
643 | - if (iter.videoID == hcp_keys[k].videoID && iter.objID == hcp_keys[k].objID) | |
643 | + if (iter_bike.videoID == hcp_keys[k].videoID && iter_bike.objID == hcp_keys[k].objID) | |
644 | 644 | continue; |
645 | 645 | |
646 | - count_bike.push(iter); | |
646 | + count_bike.push(iter_bike); | |
647 | 647 | } |
648 | 648 | |
649 | 649 | if (count_bike.size() == count_bike_size) //当前hp_keys[k] 不在count_person数组里 |
... | ... | @@ -657,7 +657,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 |
657 | 657 | iter->second.snapShotLittle.frame = NULL; |
658 | 658 | } |
659 | 659 | |
660 | - snapShotInfo.erase(iter); | |
660 | + erase_snapshot_info(hcp_keys[k]); | |
661 | 661 | |
662 | 662 | } |
663 | 663 | } |
... | ... | @@ -746,7 +746,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id) //是 |
746 | 746 | cudaFree(iter->second.snapShotLittle.frame); |
747 | 747 | iter->second.snapShotLittle.frame = NULL; |
748 | 748 | } |
749 | - snapShotInfo.erase(iter);//modified by dyq | |
749 | + erase_snapshot_info(det_vehicle_keys[vc_idx]);//modified by dyq | |
750 | 750 | } |
751 | 751 | } |
752 | 752 | |
... | ... | @@ -841,7 +841,7 @@ void snapshot_helper::hp_analysis() |
841 | 841 | cudaFree(iter->second.snapShotLittle.frame); |
842 | 842 | iter->second.snapShotLittle.frame = NULL; |
843 | 843 | } |
844 | - snapShotInfo.erase(cur_obj_key); | |
844 | + erase_snapshot_info(cur_obj_key); | |
845 | 845 | } |
846 | 846 | erase_snapshotImage(cur_obj_key); |
847 | 847 | continue; |
... | ... | @@ -866,9 +866,9 @@ void snapshot_helper::hp_analysis() |
866 | 866 | //删除已经进行保存和二次属性分析的目标 |
867 | 867 | int resIndex = 0; |
868 | 868 | |
869 | - for (auto iter_key : erase_obj_key) | |
869 | + for (auto obj_key : erase_obj_key) | |
870 | 870 | { |
871 | - auto iter = snapShotInfo.find(iter_key); | |
871 | + auto iter = snapShotInfo.find(obj_key); | |
872 | 872 | |
873 | 873 | //返回分析结果 |
874 | 874 | hp_result curRes{}; |
... | ... | @@ -879,13 +879,13 @@ void snapshot_helper::hp_analysis() |
879 | 879 | memcpy(curRes.feature, result_f[resIndex].human_fea, sizeof(int8)* HF_FEA_SIZE); |
880 | 880 | |
881 | 881 | ++resIndex; |
882 | - snapshot_res_callback(iter_key, &curRes); | |
882 | + snapshot_res_callback(obj_key, &curRes); | |
883 | 883 | if (iter->second.snapShotLittle.frame) |
884 | 884 | { |
885 | 885 | cudaFree(iter->second.snapShotLittle.frame); |
886 | 886 | iter->second.snapShotLittle.frame = NULL; |
887 | 887 | } |
888 | - snapShotInfo.erase(iter); | |
888 | + erase_snapshot_info(obj_key); | |
889 | 889 | } |
890 | 890 | |
891 | 891 | erase_obj_key.clear(); |
... | ... | @@ -951,7 +951,7 @@ void snapshot_helper::hcp_analysis() |
951 | 951 | cudaFree(iter->second.snapShotLittle.frame); |
952 | 952 | iter->second.snapShotLittle.frame = NULL; |
953 | 953 | } |
954 | - snapShotInfo.erase(cur_obj_key); | |
954 | + erase_snapshot_info(cur_obj_key); | |
955 | 955 | } |
956 | 956 | erase_snapshotImage(cur_obj_key); |
957 | 957 | continue; |
... | ... | @@ -973,9 +973,9 @@ void snapshot_helper::hcp_analysis() |
973 | 973 | } |
974 | 974 | |
975 | 975 | int resIndex = 0; |
976 | - for (auto iter_key : erase_obj_key) | |
976 | + for (auto obj_key : erase_obj_key) | |
977 | 977 | { |
978 | - auto iter = snapShotInfo.find(iter_key); | |
978 | + auto iter = snapShotInfo.find(obj_key); | |
979 | 979 | hcp_result curRes{}; |
980 | 980 | if (hcp_analysis_cf == SY_CONFIG_OPEN) |
981 | 981 | memcpy(&curRes.res_objs, result[resIndex].res_objs, sizeof(classify_obj_res)* HCP_FIR_INDEX_SIZE); |
... | ... | @@ -984,14 +984,14 @@ void snapshot_helper::hcp_analysis() |
984 | 984 | memcpy(curRes.feature, result_f[resIndex].human_fea, sizeof(int8)* HCF_FEA_SIZE); |
985 | 985 | |
986 | 986 | resIndex++; |
987 | - snapshot_res_callback(iter_key, &curRes); | |
987 | + snapshot_res_callback(obj_key, &curRes); | |
988 | 988 | |
989 | 989 | if (iter->second.snapShotLittle.frame) |
990 | 990 | { |
991 | 991 | cudaFree(iter->second.snapShotLittle.frame); |
992 | 992 | iter->second.snapShotLittle.frame = NULL; |
993 | 993 | } |
994 | - snapShotInfo.erase(iter); | |
994 | + erase_snapshot_info(obj_key); | |
995 | 995 | } |
996 | 996 | |
997 | 997 | erase_obj_key.clear(); |
... | ... | @@ -1062,7 +1062,7 @@ bool snapshot_helper::vehicle_color_analysis() |
1062 | 1062 | cudaFree(iter->second.snapShotLittle.frame); |
1063 | 1063 | iter->second.snapShotLittle.frame = NULL; |
1064 | 1064 | } |
1065 | - snapShotInfo.erase(cur_obj_key); | |
1065 | + erase_snapshot_info(cur_obj_key); | |
1066 | 1066 | } |
1067 | 1067 | |
1068 | 1068 | count_vehicle_v.erase(count_vehicle_v.begin() + i); |
... | ... | @@ -1141,7 +1141,7 @@ bool snapshot_helper::vehicle_plate_dr_analysis() |
1141 | 1141 | cudaFree(iter->second.snapShotLittle.frame); |
1142 | 1142 | iter->second.snapShotLittle.frame = NULL; |
1143 | 1143 | } |
1144 | - snapShotInfo.erase(cur_obj_key); | |
1144 | + erase_snapshot_info(cur_obj_key); | |
1145 | 1145 | } |
1146 | 1146 | else printf("cant find\n"); |
1147 | 1147 | |
... | ... | @@ -1378,7 +1378,7 @@ bool snapshot_helper::vehicle_recg_analysis() |
1378 | 1378 | cudaFree(iter->second.snapShotLittle.frame); |
1379 | 1379 | iter->second.snapShotLittle.frame = NULL; |
1380 | 1380 | } |
1381 | - snapShotInfo.erase(cur_obj_key); | |
1381 | + erase_snapshot_info(cur_obj_key); | |
1382 | 1382 | } |
1383 | 1383 | |
1384 | 1384 | count_vehicle_v.erase(count_vehicle_v.begin() + i); |
... | ... | @@ -1639,7 +1639,7 @@ bool snapshot_helper::vehicle_recg_analysis() |
1639 | 1639 | iter->second.snapShotLittle.frame = NULL; |
1640 | 1640 | } |
1641 | 1641 | |
1642 | - snapShotInfo.erase(iter); | |
1642 | + erase_snapshot_info(count_vehicle_v[c]); | |
1643 | 1643 | } |
1644 | 1644 | |
1645 | 1645 | count_vehicle_v.erase(count_vehicle_v.begin(), count_vehicle_v.begin() + cur_batchsize/*OBJ_BATCH_COUNT_VEHICLE / OBJ_SCALE*/); |
... | ... | @@ -2030,7 +2030,6 @@ int snapshot_helper::SaveResultInFile(OBJ_KEY deleteObj) |
2030 | 2030 | { |
2031 | 2031 | save_without_analysis(obj_key); |
2032 | 2032 | } |
2033 | - | |
2034 | 2033 | } |
2035 | 2034 | else |
2036 | 2035 | { |
... | ... | @@ -2123,7 +2122,11 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas |
2123 | 2122 | { |
2124 | 2123 | cur_width = HCP_WIDTH; |
2125 | 2124 | cur_height = HCP_HEIGHT; |
2126 | - LOG_DEBUG("task_id:{} obj_id:{} index = 0、1", newObj.videoID, newObj.objID); | |
2125 | + | |
2126 | + // if(5 == newObj.videoID) | |
2127 | + { | |
2128 | + LOG_DEBUG("task_id:{} obj_id:{} index = {}", newObj.videoID, newObj.objID, snapShotInfo[newObj].index.index ); | |
2129 | + } | |
2127 | 2130 | } |
2128 | 2131 | else if (8 == snapShotInfo[newObj].index.index || (snapShotInfo[newObj].index.index >= 4 && snapShotInfo[newObj].index.index <= 6)) |
2129 | 2132 | { |
... | ... | @@ -2198,8 +2201,7 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas |
2198 | 2201 | |
2199 | 2202 | int boundary_left = boundary_w, boundary_right = boundary_w, boundary_top = boundary_h, boundary_bottom = boundary_h; |
2200 | 2203 | |
2201 | - ExpandMargin((left - snapShotInfo[newObj].box.left), | |
2202 | - (bottom - snapShotInfo[newObj].box.bottom), | |
2204 | + ExpandMargin((left - snapShotInfo[newObj].box.left), (bottom - snapShotInfo[newObj].box.bottom), | |
2203 | 2205 | boundary_w, boundary_h, boundary_left, boundary_right, boundary_top, boundary_bottom); |
2204 | 2206 | |
2205 | 2207 | snapShotInfo[newObj].box.left = left; |
... | ... | @@ -2221,7 +2223,6 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas |
2221 | 2223 | int vBottom = min(frameHeight - 1, obj.bottom + boundary_bottom); |
2222 | 2224 | if (task.folderNameLittle != NULL) |
2223 | 2225 | { |
2224 | - | |
2225 | 2226 | if (0 == snapShotInfo[newObj].index.index) |
2226 | 2227 | { |
2227 | 2228 | if (snapShotInfo[newObj].snapShotLittle.width != HP_WIDTH || snapShotInfo[newObj].snapShotLittle.height != HP_HEIGHT) |
... | ... | @@ -2243,6 +2244,10 @@ CropInfo snapshot_helper::cacheSnapShotInfo(OBJ_KEY newObj, VPT_ObjInfo obj, Tas |
2243 | 2244 | } |
2244 | 2245 | else if (1 == snapShotInfo[newObj].index.index || 2 == snapShotInfo[newObj].index.index) |
2245 | 2246 | { |
2247 | + // if(5 == newObj.videoID) | |
2248 | + { | |
2249 | + LOG_DEBUG("else , task_id:{} obj_id:{} index = {}", newObj.videoID, newObj.objID, snapShotInfo[newObj].index.index); | |
2250 | + } | |
2246 | 2251 | if (snapShotInfo[newObj].snapShotLittle.width != HCP_WIDTH || snapShotInfo[newObj].snapShotLittle.height != HCP_HEIGHT) |
2247 | 2252 | { |
2248 | 2253 | cudaFree(snapShotInfo[newObj].snapShotLittle.frame); //释放显存 |
... | ... | @@ -2461,4 +2466,12 @@ void snapshot_helper::cacheFaceSnapshotInfo(sy_img *human_img, int human_count, |
2461 | 2466 | |
2462 | 2467 | void snapshot_helper::clearSnapshotInfo() { |
2463 | 2468 | snapShotInfo.clear(); |
2469 | +} | |
2470 | + | |
2471 | +void snapshot_helper::erase_snapshot_info(OBJ_KEY& objKey){ | |
2472 | + if (5 == objKey.videoID) { | |
2473 | + LOG_DEBUG("task:{} objId: {}", objKey.videoID, objKey.objID); | |
2474 | + } | |
2475 | + | |
2476 | + snapShotInfo.erase(objKey); | |
2464 | 2477 | } |
2465 | 2478 | \ No newline at end of file | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h
... | ... | @@ -212,6 +212,8 @@ private: |
212 | 212 | //针对车拆开的二次属性分析 |
213 | 213 | void VehicleRecog_Process(sy_img * batch_img, int batchsize, vr_result *&vresult, OBJ_KEY* obj_keys); |
214 | 214 | |
215 | + void erase_snapshot_info(OBJ_KEY& objKey); | |
216 | + | |
215 | 217 | private: |
216 | 218 | HumanCarParsing m_human_car_parsing; |
217 | 219 | HumanParsing m_human_parsing; | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp
... | ... | @@ -783,12 +783,13 @@ int main(int argc, char* argv[]) |
783 | 783 | total_index++ ; |
784 | 784 | |
785 | 785 | } |
786 | - } while(0) ; | |
786 | + | |
787 | + } while(1) ; | |
787 | 788 | |
788 | - printf("-------------------Begin rt_view_task 1 !----------------------\n"); | |
789 | - rt_view_task(handle, 0); | |
789 | + // printf("-------------------Begin rt_view_task 1 !----------------------\n"); | |
790 | + // rt_view_task(handle, 0); | |
790 | 791 | |
791 | - while (getchar() == 'q'); | |
792 | + while (getchar() != 'q'); | |
792 | 793 | |
793 | 794 | |
794 | 795 | /* | ... | ... |