#include "VehicleAnalysis.h" VehicleAnalysis::VehicleAnalysis() { va_acl_init(); 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; int ret = va_init(&m_handle, param); if (ret != 0) { return -1; } ACL_CALL(aclrtCreateContext(&ctx, devId), ACL_ERROR_NONE, SY_FAILED); cout << "va_init success " << endl; return 0; } int VehicleAnalysis::detect(vector vec_img) { vector imgs; for (size_t i = 0; i < vec_img.size(); i++) { ImageData dvpp_data = vec_img[i]; sy_img img; img.w_ = dvpp_data.width; img.h_ = dvpp_data.height; img.data_ = dvpp_data.data.get(); imgs.push_back(img); } int batch_size = imgs.size(); va_result *result=new va_result[batch_size]; for(int b=0;b0) { float vehicle_body_detect_res_score = result[b].info[c].vehicle_body_detect_res.score; int x1=result[b].info[c].vehicle_body_detect_res.rect.left_; int y1=result[b].info[c].vehicle_body_detect_res.rect.top_; int x2=result[b].info[c].vehicle_body_detect_res.rect.left_+result[b].info[c].vehicle_body_detect_res.rect.width_; int y2=result[b].info[c].vehicle_body_detect_res.rect.top_+result[b].info[c].vehicle_body_detect_res.rect.height_; std::cout << " vehicle_body_detect_res_score:" <0) { float vehicle_detect_res_score = result[b].info[c].vehicle_detect_res.score; int x1=result[b].info[c].vehicle_detect_res.rect.left_; int y1=result[b].info[c].vehicle_detect_res.rect.top_; int x2=result[b].info[c].vehicle_detect_res.rect.left_+result[b].info[c].vehicle_detect_res.rect.width_; int y2=result[b].info[c].vehicle_detect_res.rect.top_+result[b].info[c].vehicle_detect_res.rect.height_; std::cout << " vehicle_detect_res_score:" <0) { float vehicle_win_detect_res_score = result[b].info[c].vehicle_win_detect_res.score; int x1=result[b].info[c].vehicle_win_detect_res.rect.left_; int y1=result[b].info[c].vehicle_win_detect_res.rect.top_; int x2=result[b].info[c].vehicle_win_detect_res.rect.left_+result[b].info[c].vehicle_win_detect_res.rect.width_; int y2=result[b].info[c].vehicle_win_detect_res.rect.top_+result[b].info[c].vehicle_win_detect_res.rect.height_; std::cout << " vehicle_win_detect_res_score:" <0.5) { std::cout << " car color info:"<< endl; std::cout << " index:"<< index<<" score:"<< score<< std::endl; // std::string str_i = CARCOLOR1[index]; // cv::putText(cvImg, str_i, // cv::Point(result[b].info[c].vehicle_body_detect_res.rect.left_+5, result[b].info[c].vehicle_body_detect_res.rect.top_+50), // cv::FONT_HERSHEY_COMPLEX_SMALL, // 1.3, // cv::Scalar(0, 0, 255), // 2); } } //4.VR车型识别 if(param.vehicle_recg_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1 || vehicle_type==4 )) { //std::cout << "vr output----"<< std::endl; char *vehicle_brand=result[b].info[c].vehicle_recg_res.vehicle_brand;//车辆品牌 char* vehicle_subbrand=result[b].info[c].vehicle_recg_res.vehicle_subbrand; //车辆子品牌 char* vehicle_issue_year=result[b].info[c].vehicle_recg_res.vehicle_issue_year; //车辆年款 char* vehicle_type_=result[b].info[c].vehicle_recg_res.vehicle_type; //车辆类型 char* freight_ton=result[b].info[c].vehicle_recg_res.freight_ton; //货车吨级 float name_score=result[b].info[c].vehicle_recg_res.name_score; //识别置信度 float name_score_thre = 0; //if(vehicle_type==0)name_score_thre=0.7;//车头车型识别建议阈值0.7 //if(vehicle_type==1)name_score_thre=0.8;//车尾车型识别建议阈值0.8 if(name_score > name_score_thre) { cout << " vehicle_recg info: " << endl; std::cout << " name_score: " << name_score << std::endl; std::cout << " vehicle_brand: " << vehicle_brand << std::endl; std::cout << " vehicle_subbrand: " << vehicle_subbrand << std::endl; std::cout << " vehicle_issue_year: " << vehicle_issue_year << std::endl; std::cout << " vehicle_type_: " << vehicle_type_ << std::endl; std::cout << " freight_ton: " << freight_ton << std::endl; //printf("name_score:%f\n", name_score); //printf("vehicle_brand:%s\n", vehicle_brand); //printf("vehicle_subbrand:%s\n", vehicle_subbrand); //printf("vehicle_issue_year:%s\n", vehicle_issue_year); //printf("vehicle_type_:%s\n", vehicle_type_); //printf("freight_ton:%s\n", freight_ton); } } //5.VP车牌检测识别 if(param.vehicle_plate_det_recg_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1)) { std::cout << " car plate info:"<< endl; int special_type=result[b].info[c].vehicle_plate_det_recg_res.special_type;//常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate. std::cout << " special_type:" << special_type<< std::endl; float detect_score=result[b].info[c].vehicle_plate_det_recg_res.detect_score; //std::cout << "detect_score:" << detect_score<< std::endl; if(detect_score>0.3) { int type=result[b].info[c].vehicle_plate_det_recg_res.type; sy_rect rect=result[b].info[c].vehicle_plate_det_recg_res.rect; int x1=rect.left_; int y1=rect.top_; int x2=rect.left_+rect.width_; int y2=rect.top_+rect.height_; std::cout << " vp_type:"<0.99)//车牌识别建议置信度阈值0.99 { //printf("plate: "); for (int m = 0; m < PLATENUM; m++) { //printf("%s", result[b].info[c].vehicle_plate_det_recg_res.recg[m].character); plate_recg=plate_recg + result[b].info[c].vehicle_plate_det_recg_res.recg[m].character; } //printf("\n"); //printf("maxprob: "); //for (int m = 0; m < PLATENUM; m++) //{ // printf("%f ", result[b].info[c].vehicle_plate_det_recg_res.vehicle_plate_infos[0].recg[m].maxprob); //} //printf("\n"); //std::cout << "type:" << type<<" num_score:" <