eac85cd5
Hu Chunming
调通va
|
1
2
3
4
|
#include "VehicleAnalysis.h"
VehicleAnalysis::VehicleAnalysis() {
|
eac85cd5
Hu Chunming
调通va
|
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
cout << va_get_version() << endl;
}
VehicleAnalysis::~VehicleAnalysis() {
release();
}
int VehicleAnalysis::init(int devId, int max_batch_size) {
param.vehicle_detect_config= SY_CONFIG_OPEN; //1.开启车检测 SY_CONFIG_CLOSE SY_CONFIG_OPEN
param.vehicle_recg_config= SY_CONFIG_OPEN; //4.开启车型识别
param.vehicle_recg_supplement_config= SY_CONFIG_OPEN; //4.开启车型识别补充识别
param.vehicle_plate_det_recg_config= SY_CONFIG_OPEN; //5.开启车牌检测识别
param.vehicle_pendant_det_config= SY_CONFIG_OPEN; //6.开启车属性检测识别
param.vehicle_motor_tricycle_analysis_config= SY_CONFIG_OPEN; //8.摩托车分析
param.vehicle_manned_config= SY_CONFIG_OPEN; //8.开启载人分析
param.vehicle_color_config= SY_CONFIG_CLOSE; //3.开启车颜色识别
param.vehicle_illegal_config= SY_CONFIG_CLOSE; //7.开启车违规
param.vehicle_feature_config= SY_CONFIG_CLOSE; //8.开启车辆特征提取
param.gpuid=devId;
//车检测参数
//param.vehicle_det_param.process_min_l = 720;// 720;
//param.vehicle_det_param.process_max_l = 1280;//1280;
//param.vehicle_det_param.thresld=0.3;
//param.min_obj_size=200; //最小目标
param.vehicle_det_thresld=0.4;
//车牌检测参数
//param.vehicle_plate_det_param.process_min_l=320;
//param.vehicle_plate_det_param.process_max_l=320;
//param.vehicle_plate_det_param.thresld=0.4;
param.vehicle_plate_det_thresld=0.5;
//车属性检测参数
//param.vehicle_attribute_det_param.process_min_l=360;
//param.vehicle_attribute_det_param.process_max_l=640;
//param.vehicle_attribute_det_param.thresld=0.3;
param.vehicle_attribute_det_thresld=0.5;
//车logo检测参数
//param.vehicle_logo_det_param.process_min_l=512;
//param.vehicle_logo_det_param.process_max_l=512;
//param.vehicle_logo_det_param.thresld=0.1;
param.vehicle_logo_det_thresld=0.1;
//车颜色阈值
param.vc_thresld = 0.5;
//车型参数
param.dbPath="./models/vehicle_analysis/db/vr_h0725x210605_r191230.db";
param.models_Path="./models/vehicle_analysis/"; //所有模型的地址
cout << "va_init start " << endl;
|
15756629
Hu Chunming
添加clothes算法
|
60
|
// 内部有 ctx
|
eac85cd5
Hu Chunming
调通va
|
61
62
63
64
65
|
int ret = va_init(&m_handle, param);
if (ret != 0) {
return -1;
}
|
eac85cd5
Hu Chunming
调通va
|
66
67
68
69
|
cout << "va_init success " << endl;
return 0;
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
70
|
va_result * VehicleAnalysis::detect(vector<sy_img> vec_img) {
|
eac85cd5
Hu Chunming
调通va
|
71
|
|
20396d5c
Hu Chunming
添加车头车尾算法
|
72
|
int batch_size = vec_img.size();
|
eac85cd5
Hu Chunming
调通va
|
73
74
75
76
77
78
79
80
81
82
83
84
|
va_result *result=new va_result[batch_size];
for(int b=0;b<batch_size;b++)
{
result[b].count=0;
result[b].info=new vehicle_info[100];
for(int c=0; c<100; c++)
{
result[b].info[c].vehicle_pendant_det_res.vpd_res=new v_pendant_d_info[300];
}
}
|
20396d5c
Hu Chunming
添加车头车尾算法
|
85
|
int ret = va_batch(m_handle, vec_img.data(), batch_size, result);
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
86
87
|
vector<VehicleAnalysisResult> vec_result;
|
eac85cd5
Hu Chunming
调通va
|
88
89
|
for (int b = 0; b < batch_size; b++)
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
90
|
{
|
eac85cd5
Hu Chunming
调通va
|
91
|
for(int c=0;c<result[b].count;c++)
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
92
93
94
95
96
|
{
vehicle_info result_info = result[b].info[c];
VehicleAnalysisResult analysis_result;
|
eac85cd5
Hu Chunming
调通va
|
97
|
std::string str_vehicle_type;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
98
99
100
101
102
103
104
105
106
107
108
|
int shot_type=result_info.type;
if (shot_type==0)str_vehicle_type = "head";
else if (shot_type==1)str_vehicle_type = "rear";
else if (shot_type==2)str_vehicle_type = "motor";
else if (shot_type==3)str_vehicle_type = "tricycle";
else if (shot_type==4)str_vehicle_type = "body";
else if (shot_type==5)str_vehicle_type = "body_nova";
analysis_result.shot_type = shot_type;
//1.车头结果:蓝框//2.车窗结果:绿框
|
eac85cd5
Hu Chunming
调通va
|
109
|
if(param.vehicle_detect_config==SY_CONFIG_OPEN)
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
110
|
{
|
eac85cd5
Hu Chunming
调通va
|
111
112
|
//车身
//std::cout << "vehicle_body_detect_res info:"<< std::endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
113
|
if(result_info.vehicle_body_detect_res.rect.width_>0)
|
eac85cd5
Hu Chunming
调通va
|
114
|
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
115
116
117
118
119
|
float vehicle_body_detect_res_score = result_info.vehicle_body_detect_res.score;
int x1=result_info.vehicle_body_detect_res.rect.left_;
int y1=result_info.vehicle_body_detect_res.rect.top_;
int x2=result_info.vehicle_body_detect_res.rect.left_+result_info.vehicle_body_detect_res.rect.width_;
int y2=result_info.vehicle_body_detect_res.rect.top_+result_info.vehicle_body_detect_res.rect.height_;
|
eac85cd5
Hu Chunming
调通va
|
120
121
|
std::cout << " vehicle_body_detect_res_score:" <<vehicle_body_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
122
|
analysis_result.vehicle_rect = result_info.vehicle_body_detect_res.rect;
|
eac85cd5
Hu Chunming
调通va
|
123
124
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
125
126
127
128
129
130
131
132
133
134
135
|
// //车头
// if(result_info.vehicle_detect_res.rect.width_>0)
// {
// float vehicle_detect_res_score = result_info.vehicle_detect_res.score;
// int x1=result_info.vehicle_detect_res.rect.left_;
// int y1=result_info.vehicle_detect_res.rect.top_;
// int x2=result_info.vehicle_detect_res.rect.left_+result_info.vehicle_detect_res.rect.width_;
// int y2=result_info.vehicle_detect_res.rect.top_+result_info.vehicle_detect_res.rect.height_;
// std::cout << " vehicle_detect_res_score:" <<vehicle_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
// }
|
eac85cd5
Hu Chunming
调通va
|
136
|
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
137
138
139
140
141
142
143
144
145
146
147
|
// //车窗
// if(result_info.vehicle_win_detect_res.rect.width_>0)
// {
// float vehicle_win_detect_res_score = result_info.vehicle_win_detect_res.score;
// int x1=result_info.vehicle_win_detect_res.rect.left_;
// int y1=result_info.vehicle_win_detect_res.rect.top_;
// int x2=result_info.vehicle_win_detect_res.rect.left_+result_info.vehicle_win_detect_res.rect.width_;
// int y2=result_info.vehicle_win_detect_res.rect.top_+result_info.vehicle_win_detect_res.rect.height_;
// std::cout << " vehicle_win_detect_res_score:" <<vehicle_win_detect_res_score<<",win_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
// }
|
eac85cd5
Hu Chunming
调通va
|
148
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
149
|
|
eac85cd5
Hu Chunming
调通va
|
150
|
//4.VR车型识别
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
151
|
if(param.vehicle_recg_config==SY_CONFIG_OPEN && (shot_type==0 || shot_type==1 || shot_type==4 ))
|
eac85cd5
Hu Chunming
调通va
|
152
|
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
153
154
155
156
157
158
|
char *vehicle_brand=result_info.vehicle_recg_res.vehicle_brand;//车辆品牌
char* vehicle_subbrand=result_info.vehicle_recg_res.vehicle_subbrand; //车辆子品牌
char* vehicle_issue_year=result_info.vehicle_recg_res.vehicle_issue_year; //车辆年款
char* vehicle_type_=result_info.vehicle_recg_res.vehicle_type; //车辆类型
char* freight_ton=result_info.vehicle_recg_res.freight_ton; //货车吨级
float name_score=result_info.vehicle_recg_res.name_score; //识别置信度
|
eac85cd5
Hu Chunming
调通va
|
159
160
|
float name_score_thre = 0;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
161
162
|
//if(shot_type==0)name_score_thre=0.7;//车头车型识别建议阈值0.7
//if(shot_type==1)name_score_thre=0.8;//车尾车型识别建议阈值0.8
|
eac85cd5
Hu Chunming
调通va
|
163
164
|
if(name_score > name_score_thre)
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
165
|
analysis_result.vehicle_type = vehicle_type_;
|
eac85cd5
Hu Chunming
调通va
|
166
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
167
168
|
} else {
analysis_result.vehicle_type = str_vehicle_type;
|
eac85cd5
Hu Chunming
调通va
|
169
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
170
171
|
std::cout << "vehicle_type_: " << analysis_result.vehicle_type << std::endl;
|
eac85cd5
Hu Chunming
调通va
|
172
|
//5.VP车牌检测识别
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
173
|
if(param.vehicle_plate_det_recg_config==SY_CONFIG_OPEN && (shot_type==0 || shot_type==1))
|
eac85cd5
Hu Chunming
调通va
|
174
|
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
175
|
vplate_results plate_result = result_info.vehicle_plate_det_recg_res;
|
eac85cd5
Hu Chunming
调通va
|
176
|
std::cout << " car plate info:"<< endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
177
|
int special_type=plate_result.special_type;//常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate.
|
eac85cd5
Hu Chunming
调通va
|
178
179
|
std::cout << " special_type:" << special_type<< std::endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
180
|
float detect_score=plate_result.detect_score;
|
eac85cd5
Hu Chunming
调通va
|
181
|
if(detect_score>0.3)
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
182
|
{
|
eac85cd5
Hu Chunming
调通va
|
183
|
//车牌识别结果
|
eac85cd5
Hu Chunming
调通va
|
184
|
std::string plate_recg="";
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
185
|
std::string character_prob;
|
eac85cd5
Hu Chunming
调通va
|
186
187
188
|
//if(num_score>0.99)//车牌识别建议置信度阈值0.99
{
|
eac85cd5
Hu Chunming
调通va
|
189
190
|
for (int m = 0; m < PLATENUM; m++)
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
191
192
|
plate_recg=plate_recg + plate_result.recg[m].character;
character_prob += std::string(plate_result.recg[m].character) + "-" + std::to_string(plate_result.recg[m].maxprob) + ",";
|
eac85cd5
Hu Chunming
调通va
|
193
|
}
|
eac85cd5
Hu Chunming
调通va
|
194
|
}
|
eac85cd5
Hu Chunming
调通va
|
195
|
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
196
197
198
199
200
201
202
|
analysis_result.plate_det_score = plate_result.detect_score;
analysis_result.plate_rect = plate_result.rect;//车牌检测坐标
analysis_result.plate_type = plate_result.type; //车牌类型:0-单排蓝色 1-单排黄色 2-单排白色 3-单排黑色 4-双排黄色 5-双排白色 6-新能源黄绿色 7-新能源白绿色
analysis_result.plate_num = plate_recg;
analysis_result.character_prob = character_prob;
analysis_result.plate_num_score = plate_result.num_score;//识别置信度
// analysis_result.special_type; //常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate.
|
eac85cd5
Hu Chunming
调通va
|
203
204
205
|
}
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
206
|
|
eac85cd5
Hu Chunming
调通va
|
207
|
//6.车属性结果:
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
208
|
if(param.vehicle_pendant_det_config==SY_CONFIG_OPEN && (shot_type==0|| shot_type==4))
|
eac85cd5
Hu Chunming
调通va
|
209
210
|
{
std::cout << " vehicle_pendant_det_res info:"<< endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
211
|
int vpd_num = result_info.vehicle_pendant_det_res.count;
|
eac85cd5
Hu Chunming
调通va
|
212
213
214
215
|
//std::cout << vpd_num<< std::endl;
std::cout << " vpd_num:"<<vpd_num<< endl;
for(int p=0; p<vpd_num; p++)
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
216
217
218
219
220
221
222
|
int index = result_info.vehicle_pendant_det_res.vpd_res[p].index;
if(index == 0){
DriverInfo info;
info.driver_rect = result_info.vehicle_pendant_det_res.vpd_res[p].rect;
info.driver_prob = result_info.vehicle_pendant_det_res.vpd_res[p].confidence;
analysis_result.vec_drivers.push_back(info);
}
|
eac85cd5
Hu Chunming
调通va
|
223
|
}
|
eac85cd5
Hu Chunming
调通va
|
224
225
226
|
}
//11.摩托车三轮车分析
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
227
|
if(param.vehicle_motor_tricycle_analysis_config==SY_CONFIG_OPEN && (shot_type==2 || shot_type==3))
|
eac85cd5
Hu Chunming
调通va
|
228
229
230
|
{
//std::cout << "mta output----"<< std::endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
231
|
if(shot_type==2)//摩托车
|
eac85cd5
Hu Chunming
调通va
|
232
|
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
233
234
235
236
237
238
239
240
241
242
243
|
//摩托车载人
//int status=result_info.mta_res.motor_manned.status;
//float score=result_info.mta_res.motor_manned.confidence;
//if(status == MOTOR_MANNED)
// std::cout << "motor info: MOTOR_MANNED, prob: " << score << std::endl;
//else if(status == MOTOR_NOT_MANNED)
// std::cout << "motor info: MOTOR_NOT_MANNED, prob: " << score << std::endl;
//摩托车驾驶人是否戴安全帽
analysis_result.motor_helmeted = result_info.mta_res.motor_driver_helmeted.status;
float score=result_info.mta_res.motor_driver_helmeted.confidence;
|
eac85cd5
Hu Chunming
调通va
|
244
245
246
|
}
}
|
eac85cd5
Hu Chunming
调通va
|
247
|
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
248
249
250
251
252
253
|
//载人输出
if(param.vehicle_manned_config==SY_CONFIG_OPEN && shot_type!=5)
{
if(result_info.manned_res.hs_count >= 3){
analysis_result.motor_manned = 1;
}
|
eac85cd5
Hu Chunming
调通va
|
254
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
255
|
}
|
eac85cd5
Hu Chunming
调通va
|
256
257
258
|
}
//delete result
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
// for(int b=0;b<batch_size;b++)
// {
// for(int c=0; c<100; c++)
// {
// if(result[b].info[c].vehicle_pendant_det_res.vpd_res!=NULL)
// delete[] result[b].info[c].vehicle_pendant_det_res.vpd_res;
// }
// if(result[b].info!=NULL){
// delete[] result[b].info;
// }
// }
// if(result!=NULL){
// delete[] result;
// }
return result;
}
void VehicleAnalysis::release(){
if (m_handle) {
va_release(&m_handle);
}
}
void VehicleAnalysis::release_result(va_result* result, int batch_size){
|
eac85cd5
Hu Chunming
调通va
|
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
for(int b=0;b<batch_size;b++)
{
for(int c=0; c<100; c++)
{
if(result[b].info[c].vehicle_pendant_det_res.vpd_res!=NULL)
delete[] result[b].info[c].vehicle_pendant_det_res.vpd_res;
}
if(result[b].info!=NULL){
delete[] result[b].info;
}
}
if(result!=NULL){
delete[] result;
}
|
eac85cd5
Hu Chunming
调通va
|
304
|
}
|