eac85cd5
Hu Chunming
调通va
|
1
2
3
4
|
#include "VehicleAnalysis.h"
VehicleAnalysis::VehicleAnalysis() {
|
eac85cd5
Hu Chunming
调通va
|
5
6
7
8
9
10
11
|
cout << va_get_version() << endl;
}
VehicleAnalysis::~VehicleAnalysis() {
release();
}
|
581a68a4
Hu Chunming
修正parse_road无返回值导...
|
12
|
int VehicleAnalysis::init(int devId, std::string sdk_root, int max_batch_size) {
|
eac85cd5
Hu Chunming
调通va
|
13
14
15
16
17
18
19
20
|
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.开启载人分析
|
bb2c60a8
Hu Chunming
修复 vehicle_illega...
|
21
|
param.vehicle_illegal_config= SY_CONFIG_OPEN; //7.开启车违规
|
eac85cd5
Hu Chunming
调通va
|
22
|
param.vehicle_color_config= SY_CONFIG_CLOSE; //3.开启车颜色识别
|
eac85cd5
Hu Chunming
调通va
|
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
|
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;
|
581a68a4
Hu Chunming
修正parse_road无返回值导...
|
55
56
|
string dbPath = sdk_root + "/models/vehicle_analysis/db/vr_h0725x210605_r191230.db";
string models_path = sdk_root + "/models/vehicle_analysis/";
|
eac85cd5
Hu Chunming
调通va
|
57
|
//车型参数
|
581a68a4
Hu Chunming
修正parse_road无返回值导...
|
58
59
|
param.dbPath= (char*)dbPath.data();
param.models_Path= (char*)models_path.data(); //所有模型的地址
|
eac85cd5
Hu Chunming
调通va
|
60
|
|
e3062370
Hu Chunming
优化日志
|
61
|
LOG_INFO("va_init start");
|
15756629
Hu Chunming
添加clothes算法
|
62
|
// 内部有 ctx
|
eac85cd5
Hu Chunming
调通va
|
63
64
65
66
67
|
int ret = va_init(&m_handle, param);
if (ret != 0) {
return -1;
}
|
e3062370
Hu Chunming
优化日志
|
68
|
LOG_INFO("va_init success");
|
eac85cd5
Hu Chunming
调通va
|
69
70
71
|
return 0;
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
72
|
va_result * VehicleAnalysis::detect(vector<sy_img> vec_img) {
|
eac85cd5
Hu Chunming
调通va
|
73
|
|
20396d5c
Hu Chunming
添加车头车尾算法
|
74
|
int batch_size = vec_img.size();
|
eac85cd5
Hu Chunming
调通va
|
75
76
77
78
79
80
81
82
83
84
85
86
|
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
添加车头车尾算法
|
87
|
int ret = va_batch(m_handle, vec_img.data(), batch_size, result);
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
88
89
|
vector<VehicleAnalysisResult> vec_result;
|
eac85cd5
Hu Chunming
调通va
|
90
91
|
for (int b = 0; b < batch_size; b++)
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
92
|
{
|
eac85cd5
Hu Chunming
调通va
|
93
|
for(int c=0;c<result[b].count;c++)
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
94
95
96
97
98
|
{
vehicle_info result_info = result[b].info[c];
VehicleAnalysisResult analysis_result;
|
eac85cd5
Hu Chunming
调通va
|
99
|
std::string str_vehicle_type;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
100
101
102
103
104
105
106
107
108
109
110
|
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
|
111
|
if(param.vehicle_detect_config==SY_CONFIG_OPEN)
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
112
|
{
|
eac85cd5
Hu Chunming
调通va
|
113
114
|
//车身
//std::cout << "vehicle_body_detect_res info:"<< std::endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
115
|
if(result_info.vehicle_body_detect_res.rect.width_>0)
|
eac85cd5
Hu Chunming
调通va
|
116
|
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
117
118
119
120
121
|
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
|
122
123
|
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...
|
124
|
analysis_result.vehicle_rect = result_info.vehicle_body_detect_res.rect;
|
eac85cd5
Hu Chunming
调通va
|
125
126
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
127
128
129
130
131
132
133
134
135
136
137
|
// //车头
// 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
|
138
|
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
139
140
141
142
143
144
145
146
147
148
149
|
// //车窗
// 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
|
150
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
151
|
|
eac85cd5
Hu Chunming
调通va
|
152
|
//4.VR车型识别
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
153
|
if(param.vehicle_recg_config==SY_CONFIG_OPEN && (shot_type==0 || shot_type==1 || shot_type==4 ))
|
eac85cd5
Hu Chunming
调通va
|
154
|
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
155
156
157
158
159
160
|
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
|
161
162
|
float name_score_thre = 0;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
163
164
|
//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
|
165
166
|
if(name_score > name_score_thre)
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
167
|
analysis_result.vehicle_type = vehicle_type_;
|
eac85cd5
Hu Chunming
调通va
|
168
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
169
170
|
} else {
analysis_result.vehicle_type = str_vehicle_type;
|
eac85cd5
Hu Chunming
调通va
|
171
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
172
173
|
std::cout << "vehicle_type_: " << analysis_result.vehicle_type << std::endl;
|
eac85cd5
Hu Chunming
调通va
|
174
|
//5.VP车牌检测识别
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
175
|
if(param.vehicle_plate_det_recg_config==SY_CONFIG_OPEN && (shot_type==0 || shot_type==1))
|
eac85cd5
Hu Chunming
调通va
|
176
|
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
177
|
vplate_results plate_result = result_info.vehicle_plate_det_recg_res;
|
eac85cd5
Hu Chunming
调通va
|
178
|
std::cout << " car plate info:"<< endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
179
|
int special_type=plate_result.special_type;//常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate.
|
eac85cd5
Hu Chunming
调通va
|
180
181
|
std::cout << " special_type:" << special_type<< std::endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
182
|
float detect_score=plate_result.detect_score;
|
eac85cd5
Hu Chunming
调通va
|
183
|
if(detect_score>0.3)
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
184
|
{
|
eac85cd5
Hu Chunming
调通va
|
185
|
//车牌识别结果
|
eac85cd5
Hu Chunming
调通va
|
186
|
std::string plate_recg="";
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
187
|
std::string character_prob;
|
eac85cd5
Hu Chunming
调通va
|
188
189
190
|
//if(num_score>0.99)//车牌识别建议置信度阈值0.99
{
|
eac85cd5
Hu Chunming
调通va
|
191
192
|
for (int m = 0; m < PLATENUM; m++)
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
193
194
|
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
|
195
|
}
|
eac85cd5
Hu Chunming
调通va
|
196
|
}
|
eac85cd5
Hu Chunming
调通va
|
197
|
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
198
199
200
201
202
203
204
|
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
|
205
206
207
|
}
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
208
|
|
eac85cd5
Hu Chunming
调通va
|
209
|
//6.车属性结果:
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
210
|
if(param.vehicle_pendant_det_config==SY_CONFIG_OPEN && (shot_type==0|| shot_type==4))
|
eac85cd5
Hu Chunming
调通va
|
211
212
|
{
std::cout << " vehicle_pendant_det_res info:"<< endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
213
|
int vpd_num = result_info.vehicle_pendant_det_res.count;
|
eac85cd5
Hu Chunming
调通va
|
214
215
216
217
|
//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...
|
218
219
220
221
222
223
224
|
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
|
225
|
}
|
eac85cd5
Hu Chunming
调通va
|
226
227
228
|
}
//11.摩托车三轮车分析
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
229
|
if(param.vehicle_motor_tricycle_analysis_config==SY_CONFIG_OPEN && (shot_type==2 || shot_type==3))
|
eac85cd5
Hu Chunming
调通va
|
230
231
232
|
{
//std::cout << "mta output----"<< std::endl;
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
233
|
if(shot_type==2)//摩托车
|
eac85cd5
Hu Chunming
调通va
|
234
|
{
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
235
236
237
238
239
240
241
242
243
244
245
|
//摩托车载人
//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
|
246
247
248
|
}
}
|
eac85cd5
Hu Chunming
调通va
|
249
|
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
250
251
252
253
254
255
|
//载人输出
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
|
256
|
}
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
257
|
}
|
eac85cd5
Hu Chunming
调通va
|
258
259
260
|
}
//delete result
|
b3012672
Hu Chunming
天啊及hp,road_seg子sd...
|
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
287
288
|
// 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
|
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
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
|
306
|
}
|