Commit e57d1d04225a175330f962aaed29cdb0f1eb7ecd
1 parent
d9483d64
代码优化
Showing
6 changed files
with
133 additions
and
639 deletions
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp
... | ... | @@ -13,15 +13,8 @@ |
13 | 13 | |
14 | 14 | #include "../FFNvDecoder/logger.hpp" |
15 | 15 | |
16 | -#include "face_detect.h" | |
17 | 16 | #include "CropImg.h" |
18 | -//#include <strsafe.h> | |
19 | -//#include <shlwapi.h> | |
20 | -//#include <DbgHelp.h> | |
21 | -//#pragma comment(lib, "DbgHelp.Lib") | |
22 | -//#pragma comment(lib, "ShLwApi.lib") | |
23 | -//********************************************************// | |
24 | -//1.Ϊʲô��ʱ�ص�index=2��ȴδ�����ﳵ�ķ�������Ϊindex�ں�����Ϊ��2�����Ǵ�ʱ�Ŀ��ղ�������֮ǰ�Ŀ��գ����Կ���δ���£�����ͼ���С����Ϊ112*224 | |
17 | + | |
25 | 18 | |
26 | 19 | // #define AUTHORIZATION |
27 | 20 | //#define DQ_AUTHORIZATION |
... | ... | @@ -46,83 +39,11 @@ |
46 | 39 | #endif |
47 | 40 | #endif |
48 | 41 | |
49 | -//#define LOG_INFO //�Ƿ������ٴ�ӡ | |
50 | -// #define SKIP_FRMAE 5 //��֡֡�� | |
51 | -#define EXTIME 500 | |
52 | 42 | |
53 | 43 | #define AUTH_LICENSE "sy_va_sub_sdk_2023" |
54 | 44 | |
55 | 45 | static int TaskID = 0; |
56 | 46 | |
57 | -auto show_gpu_syimage_ = [](sy_img& cur_frame) { | |
58 | - | |
59 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.w_ * cur_frame.h_]; | |
60 | - cudaMemcpy(cpu_data, cur_frame.data_, 3 * cur_frame.w_ * cur_frame.h_ * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
61 | - cv::Mat img(cur_frame.h_, cur_frame.w_, CV_8UC3, cpu_data); | |
62 | - | |
63 | - cv::imshow("img", img); | |
64 | - cv::waitKey(0); | |
65 | - delete[] cpu_data; | |
66 | -}; | |
67 | - | |
68 | -auto show_gpu_image_ = [](DxGPUFrame& cur_frame) { | |
69 | - | |
70 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; | |
71 | - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
72 | - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); | |
73 | - | |
74 | - cv::imshow("img2", img); | |
75 | - cv::waitKey(0); | |
76 | - delete[] cpu_data; | |
77 | -}; | |
78 | - | |
79 | -auto show_gpu_image_withrect_ = [](DxGPUFrame& cur_frame, sy_rect &rect) { | |
80 | - | |
81 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; | |
82 | - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
83 | - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); | |
84 | - cv::rectangle(img, cv::Rect(rect.left_, rect.top_, rect.width_, rect.height_), cv::Scalar(25, 25, 250), 2, 8, 0); | |
85 | - cv::imshow("ori", img); | |
86 | - cv::waitKey(0); | |
87 | - delete[] cpu_data; | |
88 | -}; | |
89 | - | |
90 | -auto show_gpu_image_withfdinfo_ = [](DxGPUFrame& cur_frame, fd_info &face_info) { | |
91 | - | |
92 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; | |
93 | - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
94 | - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); | |
95 | - | |
96 | - printf("%d %d\n", cur_frame.width , cur_frame.height); | |
97 | - for (int ii = 0; ii < 25; ii++) | |
98 | - { | |
99 | - printf("(%d %d) ", face_info.facial_fea_point[ii].x_, face_info.facial_fea_point[ii].y_); | |
100 | - cv::circle(img, cv::Point(face_info.facial_fea_point[ii].x_, face_info.facial_fea_point[ii].y_), 1, cv::Scalar(0, 255, 0)); | |
101 | - | |
102 | - } | |
103 | - //cv::rectangle(img, cv::Rect(face_info.face_position.left_, face_info.face_position.top_, face_info.face_position.width_, face_info.face_position.height_), cv::Scalar(25, 25, 250), 2, 8, 0); | |
104 | - | |
105 | - cv::Mat big_img; | |
106 | - cv::resize(img, big_img, cv::Size(400, 400)); | |
107 | - | |
108 | - | |
109 | - cv::imshow("ori33", img); | |
110 | - cv::imshow("ori44", big_img); | |
111 | - cv::waitKey(0); | |
112 | - delete[] cpu_data; | |
113 | -}; | |
114 | - | |
115 | -auto show_gpu_image_with2rect_ = [](DxGPUFrame& cur_frame, sy_rect &rect, sy_rect &rect2) { | |
116 | - | |
117 | - unsigned char* cpu_data = new unsigned char[3 * cur_frame.width * cur_frame.height]; | |
118 | - cudaMemcpy(cpu_data, cur_frame.frame, 3 * cur_frame.width * cur_frame.height * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
119 | - cv::Mat img(cur_frame.height, cur_frame.width, CV_8UC3, cpu_data); | |
120 | - cv::rectangle(img, cv::Rect(rect.left_, rect.top_, rect.width_, rect.height_), cv::Scalar(25, 25, 250), 1, 8, 0); | |
121 | - cv::rectangle(img, cv::Rect(rect2.left_, rect2.top_, rect2.width_, rect2.height_), cv::Scalar(25, 250, 25), 1, 8, 0); | |
122 | - cv::imshow("ori2", img); | |
123 | - cv::waitKey(0); | |
124 | - delete[] cpu_data; | |
125 | -}; | |
126 | 47 | |
127 | 48 | static long long get_cur_time_ms(){ |
128 | 49 | chrono::time_point<chrono::system_clock, chrono::milliseconds> tpMicro |
... | ... | @@ -131,7 +52,6 @@ static long long get_cur_time_ms(){ |
131 | 52 | return tpMicro.time_since_epoch().count(); |
132 | 53 | } |
133 | 54 | |
134 | -std::function<void(DxGPUFrame&)> show_gpu_img_func = show_gpu_image_; | |
135 | 55 | |
136 | 56 | void check_thread(void* handle); |
137 | 57 | |
... | ... | @@ -168,8 +88,7 @@ int CMutliSourceVideoProcess::FinishProcessThread() |
168 | 88 | m_bProcessExit = true; |
169 | 89 | ProcessThread.join(); //waiting thread finish |
170 | 90 | |
171 | - VPT_Release(VPT_Handle); | |
172 | - | |
91 | + m_vptProcess.release(); | |
173 | 92 | m_snaphot_helper.snapshot_helper_release(); |
174 | 93 | |
175 | 94 | return 1; |
... | ... | @@ -248,19 +167,8 @@ int CMutliSourceVideoProcess::InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_IN |
248 | 167 | skip_frame_ = vptParam.skip_frame; |
249 | 168 | } |
250 | 169 | |
251 | - VPTProcess_PARAM param{}; | |
252 | - //param.c = 3; | |
253 | - param.mode = DEVICE_GPU; | |
254 | - param.gpuid = vptParam.gpuid; | |
255 | - //param.threshold = 0.6; | |
256 | - param.threshold = 0.5; | |
257 | - param.engine = ENGINE_TENSORRT; | |
258 | - param.max_batch = section_batch_size; | |
259 | - param.serialize_file = "./serialize_file/VPT"; | |
260 | - param.auth_license = vptParam.auth_license; | |
261 | 170 | mgpuid = vptParam.gpuid; |
262 | - VPT_Handle = NULL; | |
263 | - ret = VPT_Init(VPT_Handle, param); | |
171 | + ret = m_vptProcess.init(mgpuid, section_batch_size); | |
264 | 172 | if (0 != ret) |
265 | 173 | return ret; |
266 | 174 | |
... | ... | @@ -364,7 +272,7 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID) |
364 | 272 | |
365 | 273 | tasks[i].frameImage.release(); |
366 | 274 | |
367 | - FinishTaskTracker(VPT_Handle, taskID); | |
275 | + m_vptProcess.FinishTaskTracker(taskID); | |
368 | 276 | |
369 | 277 | if (viewTaskID == taskID) viewTaskID = -1; |
370 | 278 | |
... | ... | @@ -382,7 +290,7 @@ void CMutliSourceVideoProcess::PauseTask(const int taskID) |
382 | 290 | { |
383 | 291 | if (tasks[i].taskState == PLAY) TaskinPlay--; |
384 | 292 | tasks[i].taskState = PAUSE; |
385 | - PauseTaskTracker(VPT_Handle, taskID); | |
293 | + m_vptProcess.PauseTaskTracker(taskID); | |
386 | 294 | tasks[i].taskTcuvid->PauseDecoder(); |
387 | 295 | if (viewTaskID == taskID) viewTaskID = -1; |
388 | 296 | printf("-----------------------pasue task: %d-----------------------\n", taskID); |
... | ... | @@ -399,7 +307,7 @@ void CMutliSourceVideoProcess::RestartTask(const int taskID) |
399 | 307 | { |
400 | 308 | tasks[i].taskState = PLAY; |
401 | 309 | TaskinPlay++; |
402 | - RestartTaskTraker(VPT_Handle, taskID); | |
310 | + m_vptProcess.RestartTaskTraker(taskID); | |
403 | 311 | tasks[i].taskTcuvid->ResumeDecoder(); |
404 | 312 | printf("-----------------------restart task: %d-----------------------\n", taskID); |
405 | 313 | break; |
... | ... | @@ -559,7 +467,7 @@ bool CMutliSourceVideoProcess::AddTask(task_param tparam) //debug by zsh |
559 | 467 | TaskinPlay++; |
560 | 468 | tasks.push_back(new_task); |
561 | 469 | |
562 | - AddTaskTracker(VPT_Handle, new_task.taskID, width, height); | |
470 | + m_vptProcess.AddTaskTracker(new_task.taskID, width, height); | |
563 | 471 | |
564 | 472 | AddTaskSucFlag = 1; |
565 | 473 | |
... | ... | @@ -850,7 +758,7 @@ void CMutliSourceVideoProcess::algorthim_process() |
850 | 758 | { |
851 | 759 | tasks[i].taskState = DECODEERROR; |
852 | 760 | curPlayTaskCount--; |
853 | - FinishTaskTracker(VPT_Handle, tasks[i].taskID); | |
761 | + m_vptProcess.FinishTaskTracker(tasks[i].taskID); | |
854 | 762 | } |
855 | 763 | } |
856 | 764 | |
... | ... | @@ -923,7 +831,7 @@ void CMutliSourceVideoProcess::algorthim_process() |
923 | 831 | |
924 | 832 | vector<vector<int>> tempDeleteObjectID; |
925 | 833 | tempDeleteObjectID.resize(batchsize); |
926 | - int flag = VPT_Process_GPU(GetVPT_Handle(), batch_img, startbatch, batchsize, vec_frameIndex, VPTResult, tempDeleteObjectID, unUsedResult); | |
834 | + int flag = m_vptProcess.process(batch_img, startbatch, batchsize, vec_frameIndex, VPTResult, tempDeleteObjectID, unUsedResult); | |
927 | 835 | process_times++ ; |
928 | 836 | |
929 | 837 | for (auto iter : tempDeleteObjectID) |
... | ... | @@ -1076,7 +984,7 @@ void CMutliSourceVideoProcess::algorthim_process() |
1076 | 984 | //实时查看 绘制目标轨迹 回调函数返回 |
1077 | 985 | if (view) |
1078 | 986 | { |
1079 | - DrawTracker(VPT_Handle, *iter, &task.frameImage); | |
987 | + m_vptProcess.DrawTracker(*iter, &task.frameImage); | |
1080 | 988 | if (task.taskRealTimeCallbackFunc != nullptr) |
1081 | 989 | task.taskRealTimeCallbackFunc(task.frameImage.data, task.frameImage.rows, task.frameImage.cols); |
1082 | 990 | } | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.h
... | ... | @@ -20,7 +20,6 @@ |
20 | 20 | #include "snapshot_helper.h" |
21 | 21 | |
22 | 22 | #include <atomic> |
23 | -//#include "DxLogInterface.h" | |
24 | 23 | |
25 | 24 | #ifdef _MSC_VER |
26 | 25 | #ifdef _DEBUG |
... | ... | @@ -60,9 +59,6 @@ using namespace std; |
60 | 59 | #define MAXLENGTH 416 |
61 | 60 | #define MINLENGTH 224 |
62 | 61 | |
63 | -//#define PROCESSHEIGHT 224 | |
64 | -//#define PROCESSWIDTH 416 | |
65 | -//#define DATASIZE PROCESSWIDTH * PROCESSHEIGHT * 3 | |
66 | 62 | #define THREAD_COUNT 30 |
67 | 63 | #define SNAPSHOTFRAME 15 |
68 | 64 | #define LOSTMAXFRAMECCOUNT 4 |
... | ... | @@ -113,7 +109,7 @@ public: |
113 | 109 | ~CMutliSourceVideoProcess(); |
114 | 110 | |
115 | 111 | int InitAlgorthim(mvpt_param vptParam, VIDEO_OBJECT_INFO_CALLBACK tObjInfoCallbackFunc, VIDEO_FINISH_CALLBACK tFinishCallbackFunc); |
116 | - void* GetVPT_Handle(){ return VPT_Handle; }; | |
112 | + | |
117 | 113 | int get_task_progress(int taskid, double & progress); |
118 | 114 | void OperatorTask(); |
119 | 115 | bool HasNewTask() { |
... | ... | @@ -179,9 +175,11 @@ public: /*��������Ӧ����public�� ������ï |
179 | 175 | sy_command m_face_det_config; //�Ƿ���������� |
180 | 176 | snapshot_helper m_snaphot_helper; |
181 | 177 | |
178 | +private: | |
182 | 179 | bool m_bExit{false}; |
183 | 180 | bool m_bProcessExit{false}; |
181 | + | |
182 | + VPTProcess m_vptProcess; | |
184 | 183 | }; |
185 | 184 | |
186 | -static CMutliSourceVideoProcess mainProcess; | |
187 | 185 | #endif | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/ObjCls.h deleted
1 | -#include "VPTProcess.h"// detector | |
2 | -#include "utools.h" | |
3 | -#include "proto.h" | |
4 | -#include <queue> | |
5 | - | |
6 | -#include "sort/Sort.h" //tracker | |
7 | -#include "MD5/mID.h" | |
8 | -//#define MULTICHANNEL 20 //֧�ֵ����·�� | |
9 | -#define THRESHOLD 0.5 | |
10 | - | |
11 | -//struct objDetector{ | |
12 | -// void* detector; | |
13 | -// //Sort tracker[MULTICHANNEL]; | |
14 | -// VPTProcess_PARAM param; | |
15 | -// int channels;//ֵΪopencv��CV_8UC1 ���� CV_8UC3 | |
16 | -//}; | |
17 | - | |
18 | -struct TaskTracker | |
19 | -{ | |
20 | - int TaskID; | |
21 | - double ratioWidth; | |
22 | - double ratioHeight; | |
23 | - Sort tracker; | |
24 | - unsigned int lastFrameIndex; | |
25 | -}; | |
26 | -vector<TaskTracker> taskTrackers; | |
27 | - | |
28 | - | |
29 | -class CMemoryRecord | |
30 | -{ | |
31 | - public: | |
32 | - unsigned char * ptr; | |
33 | - CMemoryRecord(int w,int h) | |
34 | - { | |
35 | - cudaMalloc((void **) & ptr, w*h*3*sizeof(unsigned char)); | |
36 | - } | |
37 | - virtual ~CMemoryRecord(){ | |
38 | - cudaFree(ptr); | |
39 | - ptr=NULL; | |
40 | - } | |
41 | - | |
42 | -}; | |
43 | -#if 0 | |
44 | -class CMemoryPool | |
45 | -{ | |
46 | - public: | |
47 | - int m_w,m_h; | |
48 | - std::queue<CMemoryRecord*> filled_records; | |
49 | - std::queue<CMemoryRecord*> unfilled_records; | |
50 | - CMemoryPool(int w,int h,int num) | |
51 | - { | |
52 | - m_w = w;m_h=h; | |
53 | - for(int i=0;i<num;i++) | |
54 | - { | |
55 | - CMemoryRecord * ptr= new CMemoryRecord(w,h); | |
56 | - unfilled_records.push_back(ptr); | |
57 | - } | |
58 | - } | |
59 | - | |
60 | - sy_img GetSyImg() | |
61 | - { | |
62 | - sy_img record; | |
63 | - CMemoryRecord * ptr = unfilled_records.front(); | |
64 | - record.set_data(w,h, ptr->ptr); | |
65 | - unfilled_records.pop(); | |
66 | - filled_records.push(ptr); | |
67 | - return record; | |
68 | - } | |
69 | - | |
70 | - | |
71 | - virtual ~CMemoryPool() | |
72 | - { | |
73 | - for(int i=0;i<filled_records.size();i++) | |
74 | - { | |
75 | - CMemoryRecord * ptr=filled_records[i ]; | |
76 | - delete [] ptr; | |
77 | - std::queue<CMemoryRecord*>().swap( filled_records ); | |
78 | - | |
79 | - } | |
80 | - for(int i=0;i<filled_records.size();i++) | |
81 | - { | |
82 | - CMemoryRecord * ptr=filled_records[i ]; | |
83 | - delete [] ptr; | |
84 | - std::queue<CMemoryRecord*>().swap( filled_records ); | |
85 | - } | |
86 | - } | |
87 | -}; | |
88 | -#endif |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.cpp
1 | 1 | #include "VPTProcess.h" |
2 | -#include "MutliSourceVideoProcess.h" | |
3 | - | |
4 | -#ifndef _MSC_VER | |
5 | -#include <sys/time.h> | |
6 | -#endif | |
7 | 2 | |
8 | 3 | #include <stdlib.h> |
9 | 4 | #include <cuda_runtime.h> |
10 | -#include "ObjCls.h" | |
11 | -#include <time.h> | |
12 | 5 | #include "ErrorInfo.h" |
13 | -#include "fstream" | |
14 | 6 | |
7 | +#include "../FFNvDecoder/logger.hpp" | |
15 | 8 | |
9 | +#define THRESHOLD 0.5 | |
16 | 10 | |
17 | 11 | #define USE_YOLOV5 |
18 | 12 | |
... | ... | @@ -32,24 +26,6 @@ |
32 | 26 | |
33 | 27 | |
34 | 28 | |
35 | -typedef struct objDetector { | |
36 | - | |
37 | - void* det_handle; | |
38 | - float threshold; | |
39 | - int engine_type; | |
40 | - // VPT_FPNPluginFactory tensorrt_plugin_factory; | |
41 | - | |
42 | - int licence_status = -1; | |
43 | - int thrd_status = -1; | |
44 | - vector<TaskTracker> taskTrackers; | |
45 | - objDetector() | |
46 | - { | |
47 | - det_handle = NULL; | |
48 | - threshold = 0.6; | |
49 | - } | |
50 | -}objDetector; | |
51 | - | |
52 | - | |
53 | 29 | static long long get_cur_time_ms(){ |
54 | 30 | chrono::time_point<chrono::system_clock, chrono::milliseconds> tpMicro |
55 | 31 | = chrono::time_point_cast<chrono::milliseconds>(chrono::system_clock::now()); |
... | ... | @@ -57,7 +33,15 @@ static long long get_cur_time_ms(){ |
57 | 33 | return tpMicro.time_since_epoch().count(); |
58 | 34 | } |
59 | 35 | |
60 | -void config_fpn_param(ctools_init_params& param, int batch_size) { | |
36 | +VPTProcess::VPTProcess(/* args */) | |
37 | +{ | |
38 | +} | |
39 | + | |
40 | +VPTProcess::~VPTProcess() | |
41 | +{ | |
42 | +} | |
43 | + | |
44 | +void VPTProcess::config_fpn_param(ctools_init_params& param, int batch_size) { | |
61 | 45 | // param.model_type_ = MODEL_FPN; |
62 | 46 | |
63 | 47 | // param.weight_file_ = NULL; |
... | ... | @@ -103,11 +87,11 @@ void config_fpn_param(ctools_init_params& param, int batch_size) { |
103 | 87 | // param.tensorrt_calibrator_array_len_ = ga_trt_fpn_vpt_calibrator_len;// "trt_fpn_vpt_calibrator"; |
104 | 88 | // param.tensorrt_calibrator_array_ = (unsigned char*)ga_trt_fpn_vpt_calibrator;// "trt_fpn_vpt_calibrator"; |
105 | 89 | |
106 | - // param.tensorrt_plugin_factory_ptr_ = &(tools->tensorrt_plugin_factory); | |
90 | + // param.tensorrt_plugin_factory_ptr_ = &(tensorrt_plugin_factory); | |
107 | 91 | // } |
108 | 92 | } |
109 | 93 | |
110 | -void config_yolo_param(ctools_init_params& param, int batch_size) { | |
94 | +void VPTProcess::config_yolo_param(ctools_init_params& param, int batch_size) { | |
111 | 95 | |
112 | 96 | param.model_type_ = MODEL_YOLOV5; // debug by zsh |
113 | 97 | |
... | ... | @@ -154,157 +138,37 @@ void config_yolo_param(ctools_init_params& param, int batch_size) { |
154 | 138 | param.tensorrt_calibrator_array_len_ = ga_trt_yolo_vpt_calibrator_len;// |
155 | 139 | param.tensorrt_calibrator_array_ = (unsigned char*)ga_trt_yolo_vpt_calibrator;// debug by zsh |
156 | 140 | |
157 | - // param.tensorrt_plugin_factory_ptr_ = &(tools->tensorrt_plugin_factory); | |
141 | + // param.tensorrt_plugin_factory_ptr_ = &(tensorrt_plugin_factory); | |
158 | 142 | } |
159 | 143 | } |
160 | 144 | |
161 | -int VPT_Init(void *&handle, VPTProcess_PARAM vparam) | |
145 | +int VPTProcess::init(int gpuid, int max_batch_size) | |
162 | 146 | { |
163 | - objDetector *tools = new objDetector; | |
164 | - | |
165 | 147 | ctools_init_params param; |
166 | - param.thres_ = vparam.threshold; | |
148 | + param.thres_ = 0.5; | |
167 | 149 | param.log_level_ = 0; |
168 | - param.device_type_ = vparam.mode; | |
169 | - param.device_id_ = vparam.gpuid; | |
170 | - param.engine_type_ = vparam.engine; | |
150 | + param.device_type_ = DEVICE_GPU; | |
151 | + param.device_id_ = gpuid; | |
152 | + param.engine_type_ = ENGINE_TENSORRT; | |
153 | + param.trt_serialize_file_ = "./serialize_file/VPT"; | |
171 | 154 | |
172 | - param.trt_serialize_file_ = vparam.serialize_file; | |
155 | + m_max_batch_size = max_batch_size; | |
173 | 156 | |
174 | 157 | #ifdef USE_YOLOV5 |
175 | - config_yolo_param(param, vparam.max_batch); | |
158 | + config_yolo_param(param, m_max_batch_size); | |
176 | 159 | #else |
177 | - config_fpn_param(param, vparam.max_batch); | |
160 | + config_fpn_param(param, m_max_batch_size); | |
178 | 161 | #endif |
179 | 162 | |
180 | - tools->threshold = vparam.threshold; | |
181 | - tools->engine_type = vparam.engine; // debug by zsh | |
182 | - int flag = ctools_init(&(tools->det_handle), ¶m); | |
163 | + int flag = ctools_init(&det_handle, ¶m); | |
183 | 164 | if (SUCCESS != flag) { |
184 | - if (tools) { | |
185 | - delete tools; | |
186 | - tools = NULL; | |
187 | - } | |
188 | - } else { | |
189 | - handle = tools; | |
165 | + LOG_ERROR("VPTProcess init failed!"); | |
190 | 166 | } |
191 | 167 | |
192 | 168 | return flag; |
193 | 169 | } |
194 | 170 | |
195 | -// int VPT_Init(void *&handle, VPTProcess_PARAM vparam) | |
196 | -// { | |
197 | -// objDetector *tools = new objDetector; | |
198 | - | |
199 | -// ctools_init_params param; | |
200 | -// param.thres_ = vparam.threshold; | |
201 | -// param.log_level_ = 0; | |
202 | -// param.device_type_ = vparam.mode; | |
203 | -// param.device_id_ = vparam.gpuid; | |
204 | -// param.engine_type_ = vparam.engine; | |
205 | - | |
206 | -// param.trt_serialize_file_ = vparam.serialize_file; | |
207 | - | |
208 | - | |
209 | -// param.model_type_ = MODEL_FPN; | |
210 | -// // param.model_type_ = MODEL_YOLOV5; // debug by zsh | |
211 | - | |
212 | -// param.weight_file_ = NULL; | |
213 | -// param.net_file_ = NULL; | |
214 | - | |
215 | -// param.data_process_str_ = | |
216 | -// //"CopyData_CPU2GPU_U8;" | |
217 | -// "TypeConvert_U8_F32;" | |
218 | -// "ResizeMaxPad_F32_F32,test_size,720,test_max_size,1280,max_height,736,max_width,1280," | |
219 | -// "submean_b,103.94,submean_g,116.78,submean_r,123.68," | |
220 | -// "variance_rev_b,0.017,variance_rev_g,0.017,variance_rev_r,0.017;" | |
221 | -// "NHWC2NCHW_F32" | |
222 | -// ; | |
223 | -// param.need_im_info_ = 1; // true | |
224 | - | |
225 | -// // param.data_process_str_ = | |
226 | -// // //"CopyData_CPU2GPU_U8;" | |
227 | -// // "TypeConvert_U8_F32;" | |
228 | -// // "ResizeMaxMidPad_F32_F32,test_size,640,test_max_size,640,max_height,640,max_width,640," | |
229 | -// // "submean_b,0,submean_g,0,submean_r,0," | |
230 | -// // "variance_rev_b,0.00392,variance_rev_g,0.00392,variance_rev_r,0.00392;" | |
231 | -// // "BGR2RGB_F32_F32;" | |
232 | -// // "NHWC2NCHW_F32" | |
233 | -// // ; | |
234 | -// // param.need_im_info_ = 0; | |
235 | - | |
236 | - | |
237 | -// if (param.engine_type_ == ENGINE_MCAFFE2) | |
238 | -// { | |
239 | -// /*param.weight_array_ = (unsigned char*)ga_vpt_init_net_caffe2; | |
240 | -// param.weight_array_len_ = ga_vpt_init_net_len_caffe2; | |
241 | -// param.net_array_ = (unsigned char*)ga_vpt_predict_net_caffe2; | |
242 | -// param.net_array_len_ = ga_vpt_predict_net_len_caffe2;*/ | |
243 | -// } | |
244 | -// else if (param.engine_type_ == ENGINE_TENSORRT) | |
245 | -// { | |
246 | -// param.weight_array_ = (uint8_t*)ga_vpt_init_net; | |
247 | -// param.weight_array_len_ = ga_vpt_init_net_len; | |
248 | -// param.net_array_ = (uint8_t*)ga_vpt_predict_net; | |
249 | -// param.net_array_len_ = ga_vpt_predict_net_len; | |
250 | - | |
251 | -// // param.net_array_ = (uint8_t*)ga_vpt_det_yolo_640x640; | |
252 | -// // param.net_array_len_ = ga_vpt_det_yolo_640x640_len; //debug by zsh | |
253 | - | |
254 | -// param.trt_serialize_file_ = vparam.serialize_file; | |
255 | - | |
256 | -// memset(param.tensorrt_param_str_, 0, sizeof(param.tensorrt_param_str_)); | |
257 | - | |
258 | -// int batch_size = vparam.max_batch; | |
259 | -// std::string g_data_mode = "FP32"; | |
260 | -// bool g_is_create_calibrator = false; | |
261 | - | |
262 | -// // int g_is_onnx_model = 1; | |
263 | -// // sprintf(param.tensorrt_param_str_, "max_batchsize %d," | |
264 | -// // "data_mode %s," | |
265 | -// // "is_create_calibrator %d," | |
266 | -// // "is_onnx_model %d," | |
267 | -// // "input_names images," | |
268 | -// // "output_names output", | |
269 | -// // batch_size, g_data_mode.c_str(), g_is_create_calibrator, g_is_onnx_model); | |
270 | - | |
271 | -// sprintf(param.tensorrt_param_str_, "max_batchsize %d," | |
272 | -// "data_mode %s," | |
273 | -// "is_create_calibrator %d," | |
274 | -// "input_names data im_info," | |
275 | -// "output_names cls_prob bbox_pred_final rois_count_each_img", | |
276 | -// batch_size, g_data_mode.c_str(), g_is_create_calibrator); | |
277 | - | |
278 | -// param.tensorrt_calibrator_file_ = NULL;// "trt_fpn_vpt_calibrator"; | |
279 | -// param.tensorrt_calibrator_array_len_ = ga_trt_fpn_vpt_calibrator_len;// "trt_fpn_vpt_calibrator"; | |
280 | -// param.tensorrt_calibrator_array_ = (unsigned char*)ga_trt_fpn_vpt_calibrator;// "trt_fpn_vpt_calibrator"; | |
281 | -// // param.tensorrt_calibrator_array_len_ = ga_trt_yolo_vpt_calibrator_len;// | |
282 | -// // param.tensorrt_calibrator_array_ = (unsigned char*)ga_trt_yolo_vpt_calibrator;// debug by zsh | |
283 | - | |
284 | - | |
285 | -// param.tensorrt_plugin_factory_ptr_ = &(tools->tensorrt_plugin_factory); | |
286 | -// } | |
287 | - | |
288 | -// tools->threshold = vparam.threshold; | |
289 | -// tools->engine_type = vparam.engine; // debug by zsh | |
290 | -// int flag = ctools_init(&(tools->det_handle), ¶m); | |
291 | - | |
292 | -// if (SUCCESS != flag) | |
293 | -// { | |
294 | -// if (tools) | |
295 | -// { | |
296 | -// delete tools; | |
297 | -// tools = NULL; | |
298 | -// } | |
299 | -// } | |
300 | -// else | |
301 | -// { | |
302 | -// handle = tools; | |
303 | -// } | |
304 | -// return flag; | |
305 | -// } | |
306 | - | |
307 | -void check_VPT_Result(VPT_Result & vResult) { | |
171 | +void VPTProcess::check_VPT_Result(VPT_Result & vResult) { | |
308 | 172 | int index = 0; |
309 | 173 | for (int i = 0; i < vResult.objCount; i++) { |
310 | 174 | if ((vResult.obj[i].right - vResult.obj[i].left) > 10 && (vResult.obj[i].bottom - vResult.obj[i].top) > 10) |
... | ... | @@ -331,34 +195,19 @@ void check_VPT_Result(VPT_Result & vResult) { |
331 | 195 | vResult.objCount = index; |
332 | 196 | } |
333 | 197 | |
334 | -int VPT_Process_GPU(void * handle, sy_img * batch_img, int startBatch, int batchsize, vector<unsigned long long> vec_frameIndex, vector<VPT_Result>& result, vector<vector<int>>& deleteObjectID, vector<vector<VPT_Result>>& unUsedResult) | |
198 | +int VPTProcess::process(sy_img * batch_img, int startBatch, int batchsize, vector<unsigned long long> vec_frameIndex, vector<VPT_Result>& result, vector<vector<int>>& deleteObjectID, vector<vector<VPT_Result>>& unUsedResult) | |
335 | 199 | { |
336 | - objDetector *tools = (objDetector*)handle; | |
200 | + if(nullptr == det_handle){ | |
201 | + return FAILED; | |
202 | + } | |
337 | 203 | |
338 | 204 | bool isUseDet = true; |
339 | 205 | int channels = 3; |
340 | 206 | |
341 | - // if(batchsize == 5) { | |
342 | - // for (int i = 0; i < batchsize; i++) { | |
343 | - // // test | |
344 | - // printf("k值: %d \n", i); | |
345 | - // int height = batch_img[i].h_; | |
346 | - // int width = batch_img[i].w_; | |
347 | - // int rgb_size = 3 * width * height; | |
348 | - // unsigned char *cpu_data = new unsigned char[rgb_size]; | |
349 | - // cudaError_t cudaStatus = cudaMemcpy(cpu_data, batch_img[i].data_, rgb_size * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
350 | - // cv::Mat img(height, width, CV_8UC3, cpu_data); | |
351 | - // string filename = "test" + to_string(i) + ".jpg"; | |
352 | - // cv::imwrite(filename.c_str(), img); | |
353 | - // delete[] cpu_data; | |
354 | - // cpu_data = nullptr; | |
355 | - // } | |
356 | - // } | |
357 | - | |
358 | 207 | long long t1 = get_cur_time_ms(); |
359 | 208 | |
360 | 209 | ctools_result *detresult; |
361 | - int res_status = ctools_process(tools->det_handle, batch_img, batchsize, &detresult); | |
210 | + int res_status = ctools_process(det_handle, batch_img, batchsize, &detresult); | |
362 | 211 | |
363 | 212 | #ifdef LOG_INFO2 |
364 | 213 | long long t2 = get_cur_time_ms(); |
... | ... | @@ -400,9 +249,9 @@ int VPT_Process_GPU(void * handle, sy_img * batch_img, int startBatch, int batch |
400 | 249 | int resIndex = startBatch; |
401 | 250 | int detectIndex = 0; |
402 | 251 | |
403 | - for (int i = startBatch; i < tools->taskTrackers.size(); i++) | |
252 | + for (int i = startBatch; i < taskTrackers.size(); i++) | |
404 | 253 | { |
405 | - TaskTracker task_tracker = tools->taskTrackers[i]; | |
254 | + TaskTracker task_tracker = taskTrackers[i]; | |
406 | 255 | if (!task_tracker.tracker.GetState()) { |
407 | 256 | continue; |
408 | 257 | } |
... | ... | @@ -463,225 +312,70 @@ int VPT_Process_GPU(void * handle, sy_img * batch_img, int startBatch, int batch |
463 | 312 | return SUCCESS; |
464 | 313 | } |
465 | 314 | |
466 | - | |
467 | - | |
468 | -void VPT_Release(void * handle) | |
469 | -{ | |
470 | - objDetector *tools = (objDetector*)handle; | |
471 | - | |
472 | - if (tools) | |
473 | - { | |
474 | - if (tools->det_handle) | |
475 | - { | |
476 | - ctools_release(&tools->det_handle); | |
477 | - tools->det_handle = NULL; | |
478 | - } | |
479 | - | |
480 | - vector<TaskTracker>().swap(tools->taskTrackers); | |
481 | - | |
482 | - delete tools; | |
483 | - tools = NULL; | |
315 | +void VPTProcess::release() { | |
316 | + if (det_handle) { | |
317 | + ctools_release(&det_handle); | |
318 | + det_handle = NULL; | |
484 | 319 | } |
320 | + | |
321 | + vector<TaskTracker>().swap(taskTrackers); | |
485 | 322 | } |
486 | 323 | |
487 | -void AddTaskTracker(void * handle, const int taskID, const double rWidth, const double rHeight) | |
324 | +void VPTProcess::AddTaskTracker(const int taskID, const double rWidth, const double rHeight) | |
488 | 325 | { |
489 | - objDetector *tools = (objDetector*)handle; | |
490 | 326 | TaskTracker t; |
491 | 327 | t.TaskID = taskID; |
492 | 328 | t.ratioWidth = rWidth; |
493 | 329 | t.ratioHeight = rHeight; |
494 | 330 | t.lastFrameIndex = 0; |
495 | 331 | t.tracker.setYOLOv5(true); // YOLOv5 要设为true, fpn 要设为false |
496 | - tools->taskTrackers.push_back(t); | |
332 | + taskTrackers.push_back(t); | |
497 | 333 | } |
498 | 334 | |
499 | -void FinishTaskTracker(void * handle, const int taskID) | |
335 | +void VPTProcess::FinishTaskTracker(const int taskID) | |
500 | 336 | { |
501 | - objDetector *tools = (objDetector*)handle; | |
502 | - for (int i = 0; i < tools->taskTrackers.size(); i++) | |
337 | + for (int i = 0; i < taskTrackers.size(); i++) | |
503 | 338 | { |
504 | - if (tools->taskTrackers[i].TaskID == taskID) | |
339 | + if (taskTrackers[i].TaskID == taskID) | |
505 | 340 | { |
506 | - tools->taskTrackers.erase(tools->taskTrackers.begin() + i); | |
341 | + taskTrackers.erase(taskTrackers.begin() + i); | |
507 | 342 | break; |
508 | 343 | } |
509 | 344 | } |
510 | 345 | } |
511 | 346 | |
512 | -void PauseTaskTracker(void * handle, const int taskID) | |
347 | +void VPTProcess::PauseTaskTracker(const int taskID) | |
513 | 348 | { |
514 | - objDetector *tools = (objDetector*)handle; | |
515 | - for (int i = 0; i < tools->taskTrackers.size(); i++) | |
349 | + for (int i = 0; i < taskTrackers.size(); i++) | |
516 | 350 | { |
517 | - if (tools->taskTrackers[i].TaskID == taskID) | |
351 | + if (taskTrackers[i].TaskID == taskID) | |
518 | 352 | { |
519 | - tools->taskTrackers[i].tracker.Pause(); | |
353 | + taskTrackers[i].tracker.Pause(); | |
520 | 354 | break; |
521 | 355 | } |
522 | 356 | } |
523 | 357 | } |
524 | 358 | |
525 | -void RestartTaskTraker(void * handle, const int taskID) | |
359 | +void VPTProcess::RestartTaskTraker(const int taskID) | |
526 | 360 | { |
527 | - objDetector *tools = (objDetector*)handle; | |
528 | - for (int i = 0; i < tools->taskTrackers.size(); i++) | |
361 | + for (int i = 0; i < taskTrackers.size(); i++) | |
529 | 362 | { |
530 | - if (tools->taskTrackers[i].TaskID == taskID) | |
363 | + if (taskTrackers[i].TaskID == taskID) | |
531 | 364 | { |
532 | - tools->taskTrackers[i].tracker.ReSet(); | |
365 | + taskTrackers[i].tracker.ReSet(); | |
533 | 366 | break; |
534 | 367 | } |
535 | 368 | } |
536 | 369 | } |
537 | 370 | |
538 | -void DrawTracker(void * handle, const int taskID, cv::Mat *img) | |
371 | +void VPTProcess::DrawTracker(const int taskID, cv::Mat *img) | |
539 | 372 | { |
540 | - objDetector *tools = (objDetector*)handle; | |
541 | - for (int i = 0; i < tools->taskTrackers.size(); i++) | |
373 | + for (int i = 0; i < taskTrackers.size(); i++) | |
542 | 374 | { |
543 | - if (tools->taskTrackers[i].TaskID == taskID) | |
375 | + if (taskTrackers[i].TaskID == taskID) | |
544 | 376 | { |
545 | - tools->taskTrackers[i].tracker.addTracker(img); | |
377 | + taskTrackers[i].tracker.addTracker(img); | |
546 | 378 | break; |
547 | 379 | } |
548 | 380 | } |
549 | -} | |
550 | - | |
551 | - | |
552 | - | |
553 | -int VPT_Process(void * handle, unsigned char ** bgr, int batchsize, VPT_Result *result) | |
554 | -{ | |
555 | - // isUseDet = false; | |
556 | - // } | |
557 | - | |
558 | - // } | |
559 | - // resIndex++; | |
560 | - // if (resIndex == batchsize) break; | |
561 | - //} | |
562 | - //vector <vector< vector <float>>>().swap(detectResult); | |
563 | - //vector<vector<float>>().swap(ssdResult); | |
564 | - ///*detectResult.clear(); | |
565 | - //ssdResult.clear();*/ | |
566 | - | |
567 | - return SUCCESS; | |
568 | -} | |
569 | - | |
570 | -//#include <windows.h> | |
571 | - | |
572 | - | |
573 | - | |
574 | - | |
575 | -void permute(float * image, int testWidth, int testHeight) | |
576 | -{ | |
577 | - //cv::Mat host_image; | |
578 | - float * host_image; | |
579 | - //host_image.create(testHeight, testWidth, CV_32FC3); | |
580 | - | |
581 | - host_image = (float *)malloc(testHeight*testWidth * 3 * sizeof(float));; | |
582 | - | |
583 | - float *Host_img = new float[3 * testWidth * testHeight]{};//?????ڴ? | |
584 | - | |
585 | - float* image_data_original = image; | |
586 | - //NPP_CHECK_CUDA(cudaMemcpy(Host_img, image_data_original, testWidth*testHeight * 3 * sizeof(float), cudaMemcpyDeviceToHost));//?????Կ???????ͼ???????? | |
587 | - cudaMemcpy(Host_img, image_data_original, testWidth*testHeight * 3 * sizeof(float), cudaMemcpyDeviceToHost);//?????Կ???????ͼ???????? | |
588 | - | |
589 | - for (int j = 0; j < testHeight; j++) | |
590 | - { | |
591 | - float *pts = host_image + j * testWidth * 3; | |
592 | - for (int i = 0; i < testWidth; i++) | |
593 | - { | |
594 | - //pts[3 * i] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 0]); //b | |
595 | - //pts[3 * i + 1] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 1]); //g | |
596 | - //pts[3 * i + 2] = cv::saturate_cast<uchar>(Host_img[3 * (j*host_image.cols + i) + 2]); //r | |
597 | - | |
598 | - pts[3 * i] = (Host_img[j * testWidth + i]); //b | |
599 | - pts[3 * i + 1] = (Host_img[testWidth * testHeight + j * testWidth + i]); //g | |
600 | - pts[3 * i + 2] = (Host_img[2 * testWidth * testHeight + j * testWidth + i]); //r | |
601 | - } | |
602 | - } | |
603 | - | |
604 | - cudaMemcpy(image_data_original, host_image, testWidth*testHeight * 3 * sizeof(float), cudaMemcpyHostToDevice); | |
605 | - free(host_image); | |
606 | - //cv::Mat showImg; | |
607 | - //cv::resize(host_image, showImg, cv::Size(640, 480)); | |
608 | - //cv::imshow("image", showImg); | |
609 | - //cv::waitKey(0); | |
610 | -} | |
611 | - | |
612 | -cv::Mat GpuMat2OpencvMat(unsigned char* image, int width, int height) | |
613 | -{ | |
614 | - int testWidth = width; | |
615 | - int testHeight = height; | |
616 | - cv::Mat host_image; | |
617 | - host_image.create(testHeight, testWidth, CV_8UC3); | |
618 | - unsigned char *Host_img = new unsigned char[3 * testWidth * testHeight]{};//?????ڴ? | |
619 | - unsigned char* image_data_original = image; | |
620 | - | |
621 | - cudaError_t code = cudaMemcpy(Host_img, image_data_original, testWidth*testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost);//?????Կ???????ͼ???????? | |
622 | - if (code != 0) | |
623 | - { | |
624 | - printf("==========================================================error"); | |
625 | - } | |
626 | - std::ofstream outfile("decode.bin", ios::out | ios::binary); | |
627 | - outfile.write((char*)Host_img, int(sizeof(char) * 1080 * 1920 * 3)); | |
628 | - outfile.close(); | |
629 | - | |
630 | - cudaMemcpy(host_image.data, image_data_original, 1920 * testHeight * 3 * sizeof(unsigned char), cudaMemcpyDeviceToHost); | |
631 | - cv::imwrite("input3.jpg", host_image); | |
632 | - return host_image; | |
633 | -} | |
634 | - | |
635 | - | |
636 | -int VPT_ProcessImage(void * handle, unsigned char ** bgr, int batchsize, VPT_Result * result) | |
637 | -{ | |
638 | - //objDetector* tools = (objDetector*)handle; | |
639 | - //if (bgr == NULL) //ͼ?????ݴ??? | |
640 | - // return IMG_DATA_ERROR; | |
641 | - | |
642 | - //vector <Mat> imgs; | |
643 | - ////int datasize = tools->param.w * tools->param.h * tools->param.c; | |
644 | - //for (int i = 0; i < batchsize; i++) | |
645 | - //{ | |
646 | - // Mat img(tools->param.h, tools->param.w, tools->param.c, bgr[i]); | |
647 | - // imgs.push_back(img); | |
648 | - //} | |
649 | - | |
650 | - //vector<vector<float>> ssdResult; | |
651 | - ////clock_t begin = clock(); | |
652 | - //ssdResult = SSD_Detect(tools->detector, batchsize, imgs); // | |
653 | - //vector <vector< vector <float>>> detectResult(batchsize); //ת??Ϊ????????Ҫ?????? | |
654 | - //for (int i = 0; i < ssdResult.size(); ++i) | |
655 | - //{ | |
656 | - // const vector<float>& d = ssdResult[i];// Detection format: [image_id, label, score, xmin, ymin, xmax, ymax) | |
657 | - // const float score = d[2]; | |
658 | - // int imgid = d[0]; | |
659 | - // if (score >= THRESHOLD) //????Ϊleft top right bottom score id | |
660 | - // { | |
661 | - // vector <float> obj; | |
662 | - // obj.push_back(d[3] * imgs[d[0]].cols); | |
663 | - // obj.push_back(d[4] * imgs[d[0]].rows); | |
664 | - // obj.push_back(d[5] * imgs[d[0]].cols); | |
665 | - // obj.push_back(d[6] * imgs[d[0]].rows); | |
666 | - // obj.push_back(d[2]); | |
667 | - // obj.push_back(d[1]); | |
668 | - // detectResult[imgid].push_back(obj); | |
669 | - // } | |
670 | - //} | |
671 | - //for (int i = 0; i < batchsize; i++) | |
672 | - //{ | |
673 | - // for (int j = 0; j < detectResult[i].size(); j++)//left top right bottom score id | |
674 | - // { | |
675 | - // result[i].obj[j].id = 0; | |
676 | - // result[i].obj[j].left = detectResult[i][j][0]; | |
677 | - // result[i].obj[j].top = detectResult[i][j][1]; | |
678 | - // result[i].obj[j].right = detectResult[i][j][2]; | |
679 | - // result[i].obj[j].bottom = detectResult[i][j][3]; | |
680 | - // result[i].obj[j].confidence = detectResult[i][j][4]; | |
681 | - // result[i].obj[j].index = detectResult[i][j][5] - 1; | |
682 | - // } | |
683 | - // | |
684 | - //} | |
685 | - | |
686 | - return SUCCESS; | |
687 | 381 | } |
688 | 382 | \ No newline at end of file | ... | ... |
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/VPTProcess.h
... | ... | @@ -11,95 +11,77 @@ |
11 | 11 | #include <vector> |
12 | 12 | #include "common.h" |
13 | 13 | |
14 | +#include "./sort/Sort.h" //tracker | |
15 | + | |
14 | 16 | using namespace std; |
15 | -#define VTTYPECOUNT 10 //֧�ֵ��������� | |
16 | 17 | |
17 | 18 | |
18 | -typedef struct VPTProcess_PARAM | |
19 | +struct TaskTracker | |
20 | +{ | |
21 | + int TaskID; | |
22 | + double ratioWidth; | |
23 | + double ratioHeight; | |
24 | + Sort tracker; | |
25 | + unsigned int lastFrameIndex; | |
26 | +}; | |
27 | + | |
28 | + | |
29 | +class VPTProcess | |
19 | 30 | { |
20 | - int mode; //����ģʽ(DEVICE_GPU / DEVICE_CPU) | |
21 | - int gpuid; //ָ���Կ�id | |
22 | - float threshold; | |
23 | - int max_batch; | |
24 | - int engine; //ָ����������(ENGINE_MCAFFE2 / ENGINE_TENSORRT) | |
25 | - char* preprocess_param; | |
26 | - char* serialize_file; | |
27 | - char* auth_license; | |
28 | - VPTProcess_PARAM() :mode(DEVICE_GPU), gpuid(0), threshold(0.6), max_batch(20) {}; | |
29 | -}VPTProcess_PARAM; | |
31 | +public: | |
32 | + VPTProcess(/* args */); | |
33 | + ~VPTProcess(); | |
30 | 34 | |
35 | + /************************************************************************* | |
36 | + * PURPOSE: 初始化 | |
37 | + * PARAM: | |
38 | + [in] vparam 参数 | |
39 | + * RETURN: handle | |
40 | + * NOTES: | |
41 | + *************************************************************************/ | |
42 | + int init(int gpuid, int max_batch_size); | |
31 | 43 | |
32 | -/************************************************************************* | |
33 | -* FUNCTION: VPT_Init | |
34 | -* PURPOSE: ��ʼ�� | |
35 | -* PARAM: | |
36 | -[in] vparam ���� | |
37 | -* RETURN: handle | |
38 | -* NOTES: | |
39 | -*************************************************************************/ | |
40 | -int VPT_Init(void *&handle, VPTProcess_PARAM vparam); | |
44 | + /************************************************************************* | |
45 | + * PURPOSE: 人车物检测跟踪 | |
46 | + * PARAM: | |
47 | + [in] handle - 处理句柄 | |
48 | + [in] rgb - 图片数据(3通道BGR数据 cv::Mat格式) | |
49 | + [in] width - 图片宽度 | |
50 | + [in] height - 图片高度 | |
51 | + [in] result - 搜索结果,在外部申请足够内存 | |
52 | + [in] deleteObjectID - 删除的轨迹ID号 | |
53 | + [out] traffic - 交通流量结果结构体 内存在外部申请,大小与初始化时流量监测线个数相同,设置为NULL时不返回 | |
54 | + * RETURN: -1:图像错误; 其他:检测到的个数 | |
55 | + * NOTES: | |
56 | + *************************************************************************/ | |
57 | + //startBatch 多batch为了减少显存,串行处理 - add by lm | |
58 | + int process(sy_img * batch_img, int startBatch, int batchsize, vector<unsigned long long> vec_frameIndex, vector<VPT_Result>& result, vector<vector<int>>& deleteObjectID, vector<vector<VPT_Result>>& unUsedResult); | |
41 | 59 | |
42 | -/************************************************************************* | |
43 | -* FUNCTION: VPT_Process | |
44 | -* PURPOSE: �˳�������� | |
45 | -* PARAM: | |
46 | -[in] handle - ������� | |
47 | -[in] rgb - ͼƬ���ݣ�3ͨ��BGR���� cv::Mat��ʽ�� | |
48 | -[in] width - ͼƬ���� | |
49 | -[in] height - ͼƬ�߶� | |
50 | -[in] result - ������������ⲿ�����㹻�ڴ� | |
51 | -[out] traffic - ��ͨ��������ṹ�� �ڴ����ⲿ���룬��С���ʼ��ʱ��������߸�����ͬ������ΪNULLʱ������ | |
52 | -* RETURN: -1��ͼ����� ���������ĸ��� | |
53 | -* NOTES: | |
54 | -*************************************************************************/ | |
55 | -int VPT_Process(void * handle, unsigned char ** bgr, int batchsize, VPT_Result * result); | |
60 | + /************************************************************************* | |
61 | + * PURPOSE: 资源释放 | |
62 | + * PARAM: | |
63 | + [in] handle - 处理句柄 | |
64 | + * RETURN: NULL | |
65 | + * NOTES: | |
66 | + *************************************************************************/ | |
67 | + void release(); | |
56 | 68 | |
57 | -/************************************************************************* | |
58 | -* FUNCTION: VPT_Process | |
59 | -* PURPOSE: �˳�������� | |
60 | -* PARAM: | |
61 | -[in] handle - ������� | |
62 | -[in] rgb - ͼƬ���ݣ�3ͨ��BGR���� cv::Mat��ʽ�� | |
63 | -[in] width - ͼƬ���� | |
64 | -[in] height - ͼƬ�߶� | |
65 | -[in] result - ������������ⲿ�����㹻�ڴ� | |
66 | -[in] deleteObjectID - ɾ���Ĺ켣ID�� | |
67 | -[out] traffic - ��ͨ��������ṹ�� �ڴ����ⲿ���룬��С���ʼ��ʱ��������߸�����ͬ������ΪNULLʱ������ | |
68 | -* RETURN: -1��ͼ����� ���������ĸ��� | |
69 | -* NOTES: | |
70 | -*************************************************************************/ | |
71 | -//startBatch ��batchΪ�˼����Դ棬���д��� - add by lm | |
72 | -//int VPT_Process_GPU(void * handle, float * bgr, int width, int height, int startBatch, int batchsize, VPT_Result * result, vector<vector<int>>& deleteObjectID); | |
73 | -int VPT_Process_GPU(void * handle, sy_img * batch_img, int startBatch, int batchsize, vector<unsigned long long> vec_frameIndex, vector<VPT_Result>& result, vector<vector<int>>& deleteObjectID, vector<vector<VPT_Result>>& unUsedResult); | |
74 | 69 | |
75 | -/************************************************************************* | |
76 | -* FUNCTION: VPT_ProcessImage | |
77 | -* PURPOSE: �˳�����-ͼƬ | |
78 | -* PARAM: | |
79 | -[in] handle - ������� | |
80 | -[in] rgb - ͼƬ���ݣ�3ͨ��BGR���� cv::Mat��ʽ�� | |
81 | -[in] width - ͼƬ���� | |
82 | -[in] height - ͼƬ�߶� | |
83 | -[in] result - ������������ⲿ�����㹻�ڴ� | |
84 | -* RETURN: -1��ͼ����� ���������ĸ��� | |
85 | -* NOTES: | |
86 | -*************************************************************************/ | |
87 | -int VPT_ProcessImage(void * handle, unsigned char ** bgr, int batchsize, VPT_Result * result); | |
88 | 70 | |
89 | -/************************************************************************* | |
90 | -* FUNCTION: VPT_Release | |
91 | -* PURPOSE: ��Դ�ͷ� | |
92 | -* PARAM: | |
93 | -[in] handle - ������� | |
94 | -* RETURN: NULL | |
95 | -* NOTES: | |
96 | -*************************************************************************/ | |
97 | -void VPT_Release(void * handle); | |
71 | + void AddTaskTracker(const int taskID, const double rWidth, const double rHeight); | |
72 | + void FinishTaskTracker(const int taskID); | |
73 | + void PauseTaskTracker(const int taskID); | |
74 | + void RestartTaskTraker(const int taskID); | |
75 | + void DrawTracker(const int taskID, cv::Mat *img); | |
98 | 76 | |
77 | +private: | |
78 | + void config_fpn_param(ctools_init_params& param, int batch_size); | |
79 | + void config_yolo_param(ctools_init_params& param, int batch_size); | |
80 | + void check_VPT_Result(VPT_Result & vResult); | |
99 | 81 | |
82 | +private: | |
83 | + int m_max_batch_size {20}; | |
100 | 84 | |
101 | -void AddTaskTracker(void * handle, const int taskID, const double rWidth, const double rHeight); | |
102 | -void FinishTaskTracker(void * handle, const int taskID); | |
103 | -void PauseTaskTracker(void * handle, const int taskID); | |
104 | -void RestartTaskTraker(void * handle, const int taskID); | |
105 | -void DrawTracker(void * handle, const int taskID, cv::Mat *img); | |
85 | + void* det_handle {nullptr}; | |
86 | + vector<TaskTracker> taskTrackers; | |
87 | +}; | ... | ... |