Commit 0b2e2301a838d5b5436f0cc4baccc3998d8e0d45

Authored by Hu Chunming
1 parent cefa38a2

代码优化

vehicle_structure_platform.git0708-3080-trt-face/src/FFNvDecoder/FFNvDecoder.cpp
... ... @@ -53,6 +53,8 @@ FFNvDecoder::FFNvDecoder()
53 53 FFNvDecoder::~FFNvDecoder()
54 54 {
55 55 m_dec_keyframe = false;
  56 +
  57 + LOG_INFO("~FFNvDecoder");
56 58 }
57 59  
58 60 bool FFNvDecoder::init(FFDecConfig& cfg)
... ... @@ -309,12 +311,18 @@ void FFNvDecoder::decode_thread()
309 311 void FFNvDecoder::decode_finished(){
310 312 if (avctx)
311 313 {
  314 + if (avctx->hw_device_ctx) {
  315 + av_buffer_unref(&avctx->hw_device_ctx);
  316 + avctx->hw_device_ctx = nullptr;
  317 + }
312 318 avcodec_free_context(&avctx);
  319 + avctx = nullptr;
313 320 }
314 321  
315 322 if (fmt_ctx)
316 323 {
317 324 avformat_close_input(&fmt_ctx);
  325 + fmt_ctx = nullptr;
318 326 }
319 327  
320 328 m_bFinished = true;
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/MutliSourceVideoProcess.cpp
... ... @@ -412,7 +412,6 @@ void CMutliSourceVideoProcess::FinishTask(const int taskID)
412 412 tasks[i].folderName = nullptr;
413 413 }
414 414  
415   -
416 415 if (tasks[i].folderNameLittle)
417 416 {
418 417 delete tasks[i].folderNameLittle;
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.cpp
... ... @@ -45,195 +45,59 @@
45 45  
46 46 const int FIR_INDEX_SIZE = 14;
47 47 const int SEC_INDEX_SIZE[FIR_INDEX_SIZE] = {4,2,2,2,6,9,4,2,3,3,4,3,2,2 };
48   -int HumanCarParsing_Init(void *&handle, int gpuid, char* auth_license)
  48 +
  49 +HumanCarParsing::HumanCarParsing(){
  50 +
  51 +}
  52 +HumanCarParsing::~HumanCarParsing(){
  53 + LOG_INFO("~HumanCarParsing");
  54 +}
  55 +
  56 +int HumanCarParsing::init(int gpuid, char* auth_license)
49 57 {
50   - hcp_param param;
51   - param.mode = DEVICE_GPU;
52   - param.gpuid = gpuid;
  58 + hcp_param param;
  59 + param.mode = DEVICE_GPU;
  60 + param.gpuid = gpuid;
53 61 param.engine = ENGINE_TENSORRT;
54   - param.max_batch = 20;
55 62 param.serialize_file = "./serialize_file/HCP";
56   - param.auth_license = auth_license;
  63 + param.max_batch = 20;
57 64 if (hcp_init(&handle, param) != 0)
58 65 {
59   - cout << "Init HCP Failed!" << endl;
  66 + LOG_ERROR("Init HCP Failed!");
60 67 return FAILED;
61 68 }
62   -
  69 +
  70 + LOG_INFO("HumanCarParsing init success! gpu_id: {}", gpuid);
63 71 return SUCCESS;
64 72 }
65 73  
66   -#include <fstream>
67   -int HumanCarParsing_Process(void * handle, sy_img * batch_img, int batch_size, hcp_analysis_result *&result)
  74 +int HumanCarParsing::process(sy_img * batch_img, int batch_size, hcp_analysis_result *&result)
68 75 {
69   - // vector<sy_img> vec_batch_img(batch_size);
70   - // for (int i = 0; i < batch_size; i++)
71   - // {
72   - // if (batch_img[i].data_ == NULL) {
73   - // cout << i << " data null" << endl;
74   - // return -1;
75   - // }
76   - // int data_size = batch_img[i].c_ * batch_img[i].h_ * batch_img[i].w_ ;
77   - // cout << "data size:" << data_size << endl;
78   - // unsigned char *snapshotDataHost = new unsigned char[data_size] {};
79   - // cudaMemcpy(snapshotDataHost, batch_img[i].data_, data_size * sizeof(unsigned char), cudaMemcpyDeviceToHost);
80   -
81   - // sy_img tmp_img = batch_img[i];
82   - // tmp_img.data_ = snapshotDataHost;
83   -
84   - // vec_batch_img.push_back(tmp_img);
85   - // }
86   -
87   - sy_img cpu_batch_img[batch_size];
88   - for (int i = 0; i < batch_size; i++)
89   - {
90   - if (batch_img[i].data_ == NULL)
91   - {
92   - cout << i << " data null" << endl;
93   - LOG_ERROR("")
94   - return FAILED;
95   - }
96   - cpu_batch_img[i].data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char));
97   - cudaMemcpy(cpu_batch_img[i].data_, batch_img[i].data_, batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char), cudaMemcpyDeviceToHost);
98   - cpu_batch_img[i].w_ = batch_img[i].w_;
99   - cpu_batch_img[i].h_ = batch_img[i].h_;
100   - cpu_batch_img[i].c_ = batch_img[i].c_;
101   - }
102   -
103   - //cout << "begin hcp ProcessBatch" << endl;
104   - hcp_batch(handle, cpu_batch_img, batch_size, result);
  76 + LOG_INFO("batch_size: {}", batch_size);
  77 + hcp_batch(handle, batch_img, batch_size, result);
105 78  
106 79 for (int b = 0; b < batch_size; b++)
107 80 {
108 81 hcp_analysis_result &cur_result = result[b];
109   -
110 82 for (int i = 0; i < FIR_INDEX_SIZE; i++)
111 83 {
112 84 if (cur_result.res_objs[i].res_index >= SEC_INDEX_SIZE[i])
113 85 {
114 86 cur_result.res_objs[i].res_index = 0;
115   - //printf("HumanCarParsing_Process ERROR!!!!!!!!!!!! %d %d %d\n", i, cur_result.res_objs[i].res_index, SEC_INDEX_SIZE[i]);
116   - /*int data_size = batch_img[i].w_ * batch_img[i].h_ * batch_img[i].c_;
117   - unsigned char *snapshotDataHost = new unsigned char[data_size] {};
118   - cudaMemcpy(snapshotDataHost, batch_img[i].data_, data_size * sizeof(unsigned char), cudaMemcpyDeviceToHost);
119   - cv::Mat newVideoImg(batch_img[i].h_, batch_img[i].w_, CV_8UC3, snapshotDataHost);
120   - cv::imwrite("hcp.jpg", newVideoImg);
121   - delete[] snapshotDataHost;*/
122   - //printf("HumanCarParsing_Process ERROR!!!!!!!!!!!! %d %d %d\n", i, cur_result.res_objs[i].res_index, SEC_INDEX_SIZE[i]);
123 87 }
124 88 }
125   -
126   - free(cpu_batch_img[b].data_) ;
127 89 }
128 90  
129   - //cout << "end hcp ProcessBatch" << endl;
130   - // for (int b = 0; b < batch_size; b++)
131   - // {
132   - // ctools_result &cur_result = result[b];
133   - // int big_class_count = cur_result.obj_count_;
134   - // ctools_obj_result &index_score = cur_result.obj_results_[big_class_count];
135   -
136   -
137   - // //for (int i = 0; i < cur_result.obj_count_ + 1; i++)
138   - // // {
139   - // // ctools_obj_result &index_score_1 = cur_result.obj_results_[i];
140   - // //
141   - // // for (int j = 0; j < index_score_1.data_count_; j++)
142   - // // printf("%.2f ", index_score_1.data_[j]);
143   - // // printf("\n");
144   - // // }
145   -
146   -
147   - // if (index_score.data_count_ != FIR_INDEX_SIZE * 2)
148   - // {
149   - // printf("wrong result.\n");
150   - // break;
151   - // }
152   -
153   - // for (int i = 0; i < FIR_INDEX_SIZE; i++)
154   - // {
155   - // //int resIndex = result[j][i].index;
156   - // int resIndex = index_score.data_[i * 2];
157   - //cout << "resIndex" << endl;
158   - // //������
159   - // switch (i)
160   - // {
161   - // case 0:
162   - // cout << up[resIndex] << " ";
163   - // break;
164   - // case 1:
165   - // cout << up_color[resIndex] << " ";
166   - // break;
167   - // case 2:
168   - // cout << down[resIndex] << " ";
169   - // break;
170   - // case 3:
171   - // cout << down_color[resIndex] << " ";
172   - // break;
173   - // case 4:
174   - // cout << bao[resIndex] << " ";
175   - // break;
176   - // case 5:
177   - // cout << bag_color[resIndex] << " ";
178   - // break;
179   - // case 6:
180   - // cout << head[resIndex] << " ";
181   - // break;
182   - // case 7:
183   - // cout << clothing_text[resIndex] << " ";
184   - // break;
185   - // case 8:
186   - // cout << sex[resIndex] << " ";
187   - // break;
188   - // case 9:
189   - // cout << figure[resIndex] << " ";
190   - // break;
191   - // case 10:
192   - // cout << nationality[resIndex] << " ";
193   - // break;
194   - // case 11:
195   - // cout << age[resIndex] << " ";
196   - // break;
197   - // case 12:
198   - // cout << eye[resIndex] << " ";
199   - // break;
200   - // case 13:
201   - // cout << mouth[resIndex] << " ";
202   - // break;
203   - // case 14:
204   - // cout << weibo[resIndex] << " ";
205   - // break;
206   - // case 15:
207   - // cout << carColor[resIndex] << " ";
208   - // break;
209   - // case 16:
210   - // cout << orient[resIndex] << " ";
211   - // break;
212   - // case 17:
213   - // cout << drivenum[resIndex] << " ";
214   - // break;
215   - // case 18:
216   - // cout << dasan[resIndex] << " ";
217   - // break;
218   - // case 19:
219   - // cout << take[resIndex] << " ";
220   - // break;
221   - // default:
222   - // break;
223   - // }
224   -
225   - // }
226   - // cout << endl;
227   -
228   - // //cudaFree(images[j].data);
229   - // }
230   -
231 91 return SUCCESS;
232 92  
233 93 }
234   -int HumanCarParsing_Release(void *& handle)
  94 +int HumanCarParsing::release()
235 95 {
236   - if(handle)
237   - hcp_release(&handle);
  96 + if(handle) {
  97 + hcp_release(&handle);
  98 + handle = nullptr;
  99 + }
  100 +
  101 + LOG_INFO("HumanCarParsing Release.");
238 102 return SUCCESS;
239 103 }
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/HumanCarParsing.h
... ... @@ -6,7 +6,17 @@
6 6 using namespace std;
7 7  
8 8  
  9 +class HumanCarParsing {
  10 +public:
  11 + HumanCarParsing();
  12 + ~HumanCarParsing();
  13 +
  14 + int init(int gpuid, char* auth_license);
  15 + int process(sy_img * batch_img,int batchsize, hcp_analysis_result *&result);
  16 + int release();
  17 +
  18 +private:
  19 + void* handle {nullptr};
  20 +};
  21 +
9 22  
10   -int HumanCarParsing_Init(void *&handle, int gpuid, char* auth_license);
11   -int HumanCarParsing_Process(void * handle, sy_img * batch_img,int batchsize, hcp_analysis_result *&result);
12   -int HumanCarParsing_Release(void *& handle);
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp
... ... @@ -2,7 +2,6 @@
2 2 #include "opencv2/highgui/highgui.hpp"
3 3 #include "snapshot_helper.h"
4 4 #include "HumanParsing.h"
5   -#include "HumanCarParsing.h"
6 5 #include "VehiclePlate.h"
7 6 #include "VehicleRecognition.h"
8 7 #include "VehicleColor.h"
... ... @@ -119,7 +118,7 @@ void snapshot_helper::snapshot_helper_init(int gpuid, double gpu_total_memory, c
119 118  
120 119 if (hcp_analysis_config == SY_CONFIG_OPEN || hcf_recg_config == SY_CONFIG_OPEN)
121 120 {
122   - HumanCarParsing_Init(hcp_handle, gpuid, auth_license);
  121 + m_human_car_parsing.init(gpuid, auth_license);
123 122 }
124 123  
125 124 if (hf_recg_config == SY_CONFIG_OPEN || hcf_recg_config == SY_CONFIG_OPEN)
... ... @@ -175,7 +174,7 @@ void snapshot_helper::snapshot_helper_release()
175 174 {
176 175 m_bExit = true;
177 176 HumanParsing_Release(hp_handle);
178   - HumanCarParsing_Release(hcp_handle);
  177 + m_human_car_parsing.release();
179 178 VehicleColor_Release(vc_handle);
180 179 VehiclePlateDetectRecog_Release(vp_handle);
181 180 VehicleRecognition_Release(vr_handle);
... ... @@ -463,6 +462,8 @@ void snapshot_helper::object_attri_analysis() //二次属性分析接口
463 462  
464 463 void snapshot_helper::finish_task_ss_analysis(int task_id, sy_command hp_analysis_config, sy_command hcp_analysis_config, sy_command vehicle_analysis_config, sy_command hf_recg_config, sy_command hcf_recg_config, sy_command vcf_recg_config) //是否开启车辆特征识别); //某一路任务结束了,立马对该路任务进行二次属性分析
465 464 {
  465 + LOG_INFO("in: {}", task_id);
  466 +
466 467 vector<OBJ_KEY> hp_keys;
467 468 vector<OBJ_KEY> hcp_keys;
468 469 queue<OBJ_KEY> vehicle_keys;
... ... @@ -613,11 +614,10 @@ void snapshot_helper::finish_task_ss_analysis(int task_id, sy_command hp_analysi
613 614 // printf()
614 615 finish_hcp_img[j].set_data(HCP_WIDTH, HCP_HEIGHT, IMG_CHANNELS, (unsigned char*)snapShotInfo[cur_obj_key].snapShotLittle.frame);
615 616 }
616   - if (hcp_analysis_config == SY_CONFIG_OPEN)
617   - {
  617 +
  618 + if (hcp_analysis_config == SY_CONFIG_OPEN) {
618 619 result = new hcp_analysis_result[hcp_batch_count]{};
619   - //TimeCounting t("HumanCarParsing_Process");
620   - HumanCarParsing_Process(hcp_handle, finish_hcp_img, hcp_batch_count, result);
  620 + m_human_car_parsing.process(finish_hcp_img, hcp_batch_count, result);
621 621 }
622 622  
623 623 if (hcf_recg_cf == SY_CONFIG_OPEN)
... ... @@ -832,6 +832,8 @@ void snapshot_helper::finish_task_ss_analysis(int task_id, sy_command hp_analysi
832 832 }
833 833 }
834 834 }
  835 +
  836 + LOG_INFO("end: {}", task_id);
835 837 }
836 838  
837 839 void snapshot_helper::hp_analysis()
... ... @@ -995,11 +997,9 @@ void snapshot_helper::hcp_analysis()
995 997 ++obj_batch_count;
996 998 }
997 999 //printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~count_bike = %d\n", count_bike.size());
998   - if (hcp_analysis_cf == SY_CONFIG_OPEN)
999   - {
  1000 + if (hcp_analysis_cf == SY_CONFIG_OPEN) {
1000 1001 result = new hcp_analysis_result[obj_batch_count]{};
1001   - //TimeCounting t("HumanCarParsing_Process");
1002   - HumanCarParsing_Process(hcp_handle, batch_hcp, obj_batch_count, result);
  1002 + m_human_car_parsing.process(batch_hcp, obj_batch_count, result);
1003 1003 }
1004 1004  
1005 1005 if (hcf_recg_cf == SY_CONFIG_OPEN)
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.h
... ... @@ -10,6 +10,7 @@
10 10 #include <thread>
11 11 #include <condition_variable>
12 12 #include "ImageSaveCache.h"
  13 +#include "HumanCarParsing.h"
13 14 using namespace std;
14 15  
15 16 #define EDGESIZE 4
... ... @@ -173,7 +174,6 @@ private:
173 174 sy_img * batch_vehicle_vf = nullptr;
174 175  
175 176 void * hp_handle = nullptr;
176   - void * hcp_handle = nullptr;
177 177 void * vc_handle = nullptr;
178 178 void * vp_handle = nullptr;
179 179 void * vr_handle = nullptr;
... ... @@ -256,15 +256,6 @@ public:
256 256 void object_attri_analysis();
257 257 void snapshot_res_callback(OBJ_KEY obj_key,/* OBJ_VALUE obj_value,*/ void* analysisRes = NULL);
258 258  
259   - /*void vf_feature();
260   - void vf_feature(sy_img *batch_vehicle_f, int batch_size, map<int, OBJ_KEY> &mp_head);
261   - void hp_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag);
262   - void hcp_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag);
263   - void vehicle_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag);
264   - void vf_feature(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis);
265   - void hf_features(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis, bool flag);
266   - void vehicle_color_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis);
267   - void vehicle_plate_dr_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis);
268   - void vehicle_recg_analysis(OBJ_KEY obj_key, OBJ_VALUE obj_value, bool AttributionAnalysis);*/
269   -
  259 +private:
  260 + HumanCarParsing m_human_car_parsing;
270 261 };
271 262 \ No newline at end of file
... ...
vehicle_structure_platform.git0708-3080-trt-face/src/test/main.cpp
... ... @@ -645,7 +645,7 @@ int addTaskCount;
645 645 std::chrono::time_point<std::chrono::system_clock> beginTime;
646 646 void videoFinishCallback(void * handle, const int taskID)
647 647 {
648   - cout << "==============================完成任务ID: " << taskID << " ============================" << endl;
  648 + cout << "完成任务ID: " << taskID << "" << endl;
649 649 // auto itor = cur_task_status_.find(taskID);
650 650 // if (itor != cur_task_status_.end())
651 651 // {
... ...