Commit 99b9185314da079deb28d82afe51042079782197

Authored by Hu Chunming
1 parent f79fec75

代码优化

vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/VehiclePlate.cpp
@@ -29,7 +29,6 @@ int VehiclePlateDetectRecog_Init(void *&handle, int gpuid, char* auth_license) @@ -29,7 +29,6 @@ int VehiclePlateDetectRecog_Init(void *&handle, int gpuid, char* auth_license)
29 return SUCCESS; 29 return SUCCESS;
30 } 30 }
31 31
32 -#include <fstream>  
33 int VehiclePlateDetectRecog_Process(void * handle, sy_img * batch_img, int batchsize, vplate_result *&result) 32 int VehiclePlateDetectRecog_Process(void * handle, sy_img * batch_img, int batchsize, vplate_result *&result)
34 { 33 {
35 /*��ʼ������ṹ��*/ 34 /*��ʼ������ṹ��*/
@@ -42,26 +41,21 @@ int VehiclePlateDetectRecog_Process(void * handle, sy_img * batch_img, int batc @@ -42,26 +41,21 @@ int VehiclePlateDetectRecog_Process(void * handle, sy_img * batch_img, int batc
42 } 41 }
43 } 42 }
44 43
45 - std::vector<unsigned char *> gpu_data; 44 + sy_img cpu_batch_img[batchsize];
46 for (int i = 0; i < batchsize; i++) 45 for (int i = 0; i < batchsize; i++)
47 { 46 {
48 if (batch_img[i].data_ == NULL) 47 if (batch_img[i].data_ == NULL)
49 { 48 {
50 cout << i << " data null" << endl; 49 cout << i << " data null" << endl;
51 } 50 }
52 - unsigned char * data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char));  
53 - cudaMemcpy(data_, batch_img[i].data_, batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char), cudaMemcpyDeviceToHost);  
54 - gpu_data.push_back(batch_img[i].data_);  
55 - batch_img[i].data_ = data_;  
56 -  
57 - /*cv::Mat car(batch_img[i].h_, batch_img[i].w_, CV_8UC3, data_);  
58 - cv::imshow("car", car);  
59 - cv::waitKey(0);*/ 51 + cpu_batch_img[i].data_ = (unsigned char *)malloc(batch_img[i].w_ *batch_img[i].h_ * batch_img[i].c_ * sizeof(unsigned char));
  52 + 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);
  53 + cpu_batch_img[i].w_ = batch_img[i].w_;
  54 + cpu_batch_img[i].h_ = batch_img[i].h_;
  55 + cpu_batch_img[i].c_ = batch_img[i].c_;
60 } 56 }
61 57
62 - //cout << "error begin vpdr_batch" << endl;  
63 - int index_count = vpdr_batch(handle, batch_img, batchsize, all_result);  
64 - //cout << "end vpdr_batch" << endl; 58 + int index_count = vpdr_batch(handle, cpu_batch_img, batchsize, all_result);
65 59
66 for (int b = 0; b < batchsize; b++) 60 for (int b = 0; b < batchsize; b++)
67 { 61 {
@@ -80,38 +74,15 @@ int VehiclePlateDetectRecog_Process(void * handle, sy_img * batch_img, int batc @@ -80,38 +74,15 @@ int VehiclePlateDetectRecog_Process(void * handle, sy_img * batch_img, int batc
80 best_index = j; 74 best_index = j;
81 } 75 }
82 } 76 }
83 - /*{  
84 - result[b].detect_score = all_result[b][best_index].detect_score;  
85 - result[b].num_score = all_result[b][best_index].num_score;  
86 - result[b].rect.left_ = all_result[b][best_index].rect.left_;  
87 - result[b].rect.height_ = all_result[b][best_index].rect.height_;  
88 - result[b].rect.top_ = all_result[b][best_index].rect.top_;  
89 - result[b].rect.width_ = all_result[b][best_index].rect.width_;  
90 - result[b].type = all_result[b][best_index].type;  
91 -  
92 - }  
93 -*/  
94 - /*printf("b=%d\n", b);  
95 - for (int m = 0; m < PLATENUM; m++)  
96 - {  
97 - printf("%s", all_result[b].vehicle_plate_infos[best_index].recg[m].character);  
98 - }  
99 - printf("\n");*/  
100 77
101 memcpy(&result[b], &all_result[b].vehicle_plate_infos[best_index], sizeof(vplate_result)); 78 memcpy(&result[b], &all_result[b].vehicle_plate_infos[best_index], sizeof(vplate_result));
102 } 79 }
103 80
104 -  
105 - //for (int i = 0; i<batchsize; i++)  
106 - //{  
107 - // if (all_result[i] != NULL)  
108 - // delete[] all_result[i];  
109 - //}  
110 - for (int i = 0; i < batchsize; i++)  
111 - {  
112 - free(batch_img[i].data_);  
113 - batch_img[i].data_ = gpu_data[i]; 81 + for (int i = 0; i < batchsize; i++) {
  82 + free(cpu_batch_img[i].data_);
  83 + cpu_batch_img[i].data_ = nullptr;
114 } 84 }
  85 +
115 if (all_result != NULL) 86 if (all_result != NULL)
116 delete [] all_result; 87 delete [] all_result;
117 88
vehicle_structure_platform.git0708-3080-trt-face/src/VPT/snapshot_analysis/snapshot_helper.cpp
@@ -709,8 +709,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id, sy_command hp_analysi @@ -709,8 +709,7 @@ void snapshot_helper::finish_task_ss_analysis(int task_id, sy_command hp_analysi
709 709
710 if (vehicle_batch_count == 0) continue; 710 if (vehicle_batch_count == 0) continue;
711 711
712 - sy_img* finish_vehicle_img = new sy_img[vehicle_batch_count]{};  
713 - 712 + sy_img finish_vehicle_img[vehicle_batch_count];
714 for (int j = 0; j < vehicle_batch_count; j++) 713 for (int j = 0; j < vehicle_batch_count; j++)
715 { 714 {
716 OBJ_KEY cur_obj_key = vehicle_keys[j]; 715 OBJ_KEY cur_obj_key = vehicle_keys[j];
@@ -834,12 +833,6 @@ void snapshot_helper::finish_task_ss_analysis(int task_id, sy_command hp_analysi @@ -834,12 +833,6 @@ void snapshot_helper::finish_task_ss_analysis(int task_id, sy_command hp_analysi
834 vrresult = NULL; 833 vrresult = NULL;
835 } 834 }
836 835
837 - if (finish_vehicle_img != NULL)  
838 - {  
839 - delete[] finish_vehicle_img;  
840 - finish_vehicle_img = NULL;  
841 - }  
842 -  
843 vehicle_keys.erase(vehicle_keys.begin(), vehicle_keys.begin() + vehicle_batch_count); 836 vehicle_keys.erase(vehicle_keys.begin(), vehicle_keys.begin() + vehicle_batch_count);
844 } 837 }
845 838