VehicleAnalysis.cpp 32.3 KB
1 2 3 4 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 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 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
#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<ImageData> vec_img) {

    vector<sy_img> 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;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];	
        }			
    }
    
    ACL_CALL(aclrtSetCurrentContext(ctx), ACL_ERROR_NONE, SY_FAILED);	
    int ret = va_batch(m_handle, imgs.data(), batch_size, result);
    
    for (int b = 0; b < batch_size; b++)
    {				
        if(param.vehicle_detect_config==SY_CONFIG_CLOSE)//不做车头检测时,应设result[b].count=1,即输入是车头图像,只含1辆车。
            result[b].count=1;
            
        //oFile << file << ","<< result[b].count<< "," <<endl;;	
        std::cout <<"car_count:" <<result[b].count<< std::endl;			
        for(int c=0;c<result[b].count;c++)
        {					
            //temp,中间结果,输出车牌被置黑的车小图
            //if(0)
            //{
            //	cv::Mat tmp(result[b].info[c].car_img_data_cpu[0].h_, result[b].info[c].car_img_data_cpu[0].w_, CV_8UC3, result[b].info[c].car_img_data_cpu[0].data_);
            //	char str_i[100];
            //	sprintf(str_i, "%d_",  c);
            //	cv::imwrite((save_folder_roi+str_i+i).c_str(),tmp);
            //}
            
            
            std::string str_vehicle_type;
            int vehicle_type=result[b].info[c].type;	
            //std::cout << "vehicle_type="<<vehicle_type<< std::endl;					
            if (vehicle_type==0)str_vehicle_type = "head";
            else if (vehicle_type==1)str_vehicle_type = "rear";
            else if (vehicle_type==2)str_vehicle_type = "motor";					
            else if (vehicle_type==3)str_vehicle_type = "tricycle";
            else if (vehicle_type==4)str_vehicle_type = "body";
            else if (vehicle_type==5)str_vehicle_type = "body_nova";
            std::cout << "		vehicle_type:"<<str_vehicle_type<< std::endl;
                
            //1.车头结果:蓝框//2.车窗结果:绿框
            if(param.vehicle_detect_config==SY_CONFIG_OPEN)
            {	
                //车身
                //std::cout << "vehicle_body_detect_res info:"<< std::endl;
                if(result[b].info[c].vehicle_body_detect_res.rect.width_>0)
                {
                    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:" <<vehicle_body_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
                        
                    // Point lt(x1, y1);
                    // Point rb(x2, y2);
                    // rectangle(cvImg, lt, rb, cv::Scalar(0, 255,255), 4);						
                }	
                
                //车头
                //std::cout << "vehicle_detect_res info:"<< std::endl;
                if(result[b].info[c].vehicle_detect_res.rect.width_>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:" <<vehicle_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
                        
                    // Point lt(x1, y1);
                    // Point rb(x2, y2);
                    // rectangle(cvImg, lt, rb, cv::Scalar(255, 0, 0), 4);	
                }
                
                //车窗
                //std::cout << "vwd output----"<< std::endl;
                if(result[b].info[c].vehicle_win_detect_res.rect.width_>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:" <<vehicle_win_detect_res_score<<",win_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;
                        
                    // Point lt(x1, y1);
                    // Point rb(x2, y2);
                    // rectangle(cvImg, lt, rb, cv::Scalar(0, 255, 0), 4);
                }					
            }
    
            
            //3.车颜色
            if(param.vehicle_color_config==SY_CONFIG_OPEN&& (vehicle_type==0 || vehicle_type==1 || vehicle_type==4))
            {
                //std::cout << "vc output----"<< std::endl;
                int index=result[b].info[c].vehicle_color_res.index;
                float score=result[b].info[c].vehicle_color_res.score;
                
                if(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:"<<type<<",vp_det_score:" <<detect_score <<",vp_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl;													
                    
                    // Point lt(x1, y1);
                    // Point rb(x2, y2);
                    // rectangle(cvImg, lt, rb, cv::Scalar(0, 0, 255), 4);
                        
                        
                    
                    //车牌识别结果
                    float num_score=result[b].info[c].vehicle_plate_det_recg_res.num_score;
                    std::string plate_recg="";
                    //if(num_score>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:" <<num_score<<"  " << std::endl;
                        std::cout <<"		    "<<plate_recg<< ",vp_num_score:" << num_score<< std::endl;
                            
                    }
                    
                    
                    char str_cc[100];
                    memset(str_cc, 0, sizeof(str_cc));
                    cv::Point2f p1;
                    p1.x = x1;
                    p1.y = y1-60;
                    //sprintf(str_cc, "det_%.2f_recg_%.2f_%s",detectScore,numScore,plate_recg.c_str()); 
                    sprintf(str_cc, "det_%.2f",detect_score); 
                    // cv::putText(cvImg, str_cc, 
                    //     p1,
                    //     cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //     1.3,
                    //     cv::Scalar(0, 0, 255),
                    //     2);
                        
                    memset(str_cc, 0, sizeof(str_cc));
                    p1.x = x1;
                    p1.y = y1-30;
                    sprintf(str_cc, "recg_%.2f",num_score); 
                    // cv::putText(cvImg, str_cc, 
                    //     p1,
                    //     cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //     1.3,
                    //     cv::Scalar(0, 0, 255),
                    //     2);
                        
                    memset(str_cc, 0, sizeof(str_cc));
                    p1.x = x1;
                    p1.y = y1;
                    sprintf(str_cc, "%s",plate_recg.c_str()); 
                    // cv::putText(cvImg, str_cc, 
                    //     p1,
                    //     cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //     1.3,
                    //     cv::Scalar(0, 0, 255),
                    //     2);

                }
                
            }
            
            //6.车属性结果:
            if(param.vehicle_pendant_det_config==SY_CONFIG_OPEN && (vehicle_type==0|| vehicle_type==4))
            {
                std::cout << "		vehicle_pendant_det_res info:"<< endl;
                int vpd_num = result[b].info[c].vehicle_pendant_det_res.count;
                //std::cout << vpd_num<< std::endl;
                std::cout << "		    vpd_num:"<<vpd_num<< endl;
                for(int p=0; p<vpd_num; p++)
                {
                    int index = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].index;
                    float detect_score = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].confidence;
                    int driver_copilot_info = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].driver_copilot_info;
                    int x1=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.left_;
                    int y1=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.top_;
                    int x2=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.left_+result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.width_;
                    int y2=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.top_+result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.height_;					
    
                    //std::cout <<p<<" ["<<x1<<" "<<y1<<" "<<x2-x1<<" "<<y2-y1<<"] "<<detectScore<<" "<<index<<" "<<driver_copilot_info<< std::endl;
                    std::cout << "		    vpd id:"<<p<<" index:"<<index<<",vpd_det_score:" <<detect_score <<",vpd_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<<" driver_copilot_info:"<<driver_copilot_info<< std::endl;
                        
                    
                    // Point lt(x1, y1);
                    // Point rb(x2, y2);
                    // rectangle(cvImg, lt, rb, cv::Scalar(255, 255, 0), 4);
                    
                    //车属性人脸特征
                    //f(index ==1)//人脸
                    //{
                    //	std::cout << "		    vpd face feature:[";
                    //	/*for(int f=0;f<VPD_FACE_FEATURESIZE;f++)
                    //	{
                    //		float fea = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[f];
                    //		//std::cout << "feature "<<f<<":"<<fea<<std::endl; 
                    //		std::cout <<fea<< " ";
                    //	}*/
                    //	std::cout << "]"<< std::endl;
                    //	//std::cout << "face feature:"<<result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[0]<<" "<<result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[1]<<" "<<result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[2]<<std::endl; 
                    //}						
                }
            }
            
            //7.VID车违规结果-----------
            if(param.vehicle_illegal_config==SY_CONFIG_OPEN  && vehicle_type==0)
            {		
                std::cout << "		vehicle_illegal_det_res info:"<< endl;
                vid_result cur_result = result[b].info[c].vehicle_illegal_det_res;
                //副驾驶copilot
                {
                    //有人没人判断,阈值0.6
                    std::string str_person="UNCERTAINTY";
                    if(cur_result.copilot.person.status==SOMEBODY)
                        str_person ="PERSON";
                    else if(cur_result.copilot.person.status==NOBODY)
                        str_person ="NOPERSON";				
                    //cv::putText(batch_mat[b], str_person, 
                    //	  cv::Point(5, 25),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);
                    
                    //打电话,阈值0.9
                    std::string str_call="UNCERTAINTY";
                    if(cur_result.copilot.call.status==lEGAL)
                        str_call ="lEGAL";//str_call ="NOCALL";
                    else if(cur_result.copilot.call.status==ILLEGAL)
                        str_call ="ILLEGAL";//str_call ="CALL";
                    //cv::putText(batch_mat[b], str_call, 
                    //	  cv::Point(5, 50),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);
                            
                    //使用电话、阈值0.89
                    std::string str_phone="UNCERTAINTY";
                    if(cur_result.copilot.phone.status==lEGAL)
                        str_phone ="lEGAL";//str_phone ="NOPHONE";
                    else if(cur_result.copilot.phone.status==ILLEGAL)
                        str_phone ="ILLEGAL";//str_phone ="USEPHONE";
                    //cv::putText(batch_mat[b], str_phone, 
                    //	  cv::Point(5, 75),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);
                    
                    //系安全带,阈值0.5
                    std::string str_belt="UNCERTAINTY";
                    if(cur_result.copilot.belt.status==lEGAL)
                        str_belt ="lEGAL";//str_belt ="SAFETYBELT";
                    else if(cur_result.copilot.belt.status==ILLEGAL)
                        str_belt ="ILLEGAL";

                    //cv::putText(batch_mat[b], str_belt, 
                    //	  cv::Point(5, 75),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);
                            
                    //抽烟,阈值0.9
                    std::string str_smoke="UNCERTAINTY";
                    if(cur_result.copilot.smoke.status==ILLEGAL)
                        str_smoke ="ILLEGAL";//str_smoke ="SMOKE";
                    else if(cur_result.copilot.smoke.status==lEGAL)
                        str_smoke ="lEGAL";//str_smoke ="NOSMOKE";
                    //cv::putText(batch_mat[b], str_smoke, 
                    //	  cv::Point(5, 100),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);

                    //std::cout << "copilot: "<<str_person<< " "<<str_call<< " "<<str_phone<< " "<<str_belt<< " "<<str_smoke<< std::endl;						
                    //std::cout << "copilot confidence: "<<cur_result.copilot.person.confidence<< " "<<cur_result.copilot.call.confidence<< " "<<cur_result.copilot.phone.confidence<< " "<<cur_result.copilot.belt.confidence<< " "<<cur_result.copilot.smoke.confidence<< std::endl;
                    std::cout << "		    copilot:  "<<"person:"<<str_person<< " call:"<<str_call<< " phone:"<<str_phone<< " belt:"<<str_belt<< " smoke:"<<str_smoke<< std::endl;						
                    std::cout << "		    copilot confidence:  "<<"person:"<<cur_result.copilot.person.confidence<< " call:"<<cur_result.copilot.call.confidence<< " phone:"<<cur_result.copilot.phone.confidence<< " belt:"<<cur_result.copilot.belt.confidence<< " smoke:"<<cur_result.copilot.smoke.confidence<< std::endl;
                    
                }
                
                //驾驶driver
                {
                    //有人没人判断,阈值0.6
                    std::string str_person="UNCERTAINTY";
                    if(cur_result.driver.person.status==SOMEBODY)
                        str_person ="PERSON";
                    else if(cur_result.driver.person.status==NOBODY)
                        str_person ="NOPERSON";				
                    //cv::putText(batch_mat[b], str_person, 
                    //	  cv::Point(5, 150),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);
                    
                    //打电话,阈值0.9
                    std::string str_call="UNCERTAINTY";
                    if(cur_result.driver.call.status==lEGAL)
                        str_call ="lEGAL";//str_call ="NOCALL";
                    else if(cur_result.driver.call.status==ILLEGAL)
                        str_call ="ILLEGAL";//str_call ="CALL";
                    //cv::putText(batch_mat[b], str_call, 
                    //	  cv::Point(5, 175),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);
                            
                    //使用电话,阈值0.89
                    std::string str_phone="UNCERTAINTY";
                    if(cur_result.driver.phone.status==lEGAL)
                        str_phone ="lEGAL";//str_phone ="NOPHONE";
                    else if(cur_result.driver.phone.status==ILLEGAL)
                        str_phone ="ILLEGAL";//str_phone ="USEPHONE";
                    //cv::putText(batch_mat[b], str_phone, 
                    //	  cv::Point(5, 200),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);
                    
                    //系安全带,阈值0.5
                    std::string str_belt="UNCERTAINTY";
                    if(cur_result.driver.belt.status==lEGAL)
                        str_belt ="lEGAL";//str_belt ="SAFETYBELT";
                    else if(cur_result.driver.belt.status==ILLEGAL)
                        str_belt ="ILLEGAL";//str_belt ="NOSAFETYBELT";

                    //cv::putText(batch_mat[b], str_belt, 
                    //	  cv::Point(5, 200),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);
                            
                    //抽烟,阈值0.9
                    std::string str_smoke="UNCERTAINTY";
                    if(cur_result.driver.smoke.status==ILLEGAL)
                        str_smoke ="ILLEGAL";//str_smoke ="SMOKE";
                    else if(cur_result.driver.smoke.status==lEGAL)
                        str_smoke ="lEGAL";//str_smoke ="NOSMOKE";
                    //cv::putText(batch_mat[b], str_smoke, 
                    //	  cv::Point(5, 225),
                    //	  cv::FONT_HERSHEY_COMPLEX_SMALL,
                    //	  1.3,
                    //	  cv::Scalar(255, 0, 0),
                    //	  2);
                    
                    //std::cout << "driver: "<<str_person<< " "<<str_call<< " "<<str_phone<< " "<<str_belt<< " "<<str_smoke<< std::endl;
                    //std::cout << "driver confidence: "<<cur_result.driver.person.confidence<< " "<<cur_result.driver.call.confidence<< " "<<cur_result.driver.phone.confidence<< " "<<cur_result.driver.belt.confidence<< " "<<cur_result.driver.smoke.confidence<< std::endl;
                        std::cout << "		    driver:  person:"<<str_person<< " call:"<<str_call<< " phone:"<<str_phone<< " belt:"<<str_belt<< " smoke:"<<str_smoke<< std::endl;
                    std::cout << "		    driver confidence:  person:"<<cur_result.driver.person.confidence<< " call:"<<cur_result.driver.call.confidence<< " phone:"<<cur_result.driver.phone.confidence<< " belt:"<<cur_result.driver.belt.confidence<< " smoke:"<<cur_result.driver.smoke.confidence<< std::endl;
                    
                }				
            }
            
            //8.车特征
            if(param.vehicle_feature_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1))
            {
                std::cout << "		vehicle_fea_res info: "<<std::endl;
                std::cout << "		    [";	
                for(int f=0;f<VA_FEATURESIZE;f++)
                {
                    float fea=result[b].info[c].vehicle_fea_res.feature[f];
                    //std::cout << "feature "<<f<<":"<<fea<<std::endl; 
                    std::cout <<fea<<" ";
                }
                std::cout <<"]"<<std::endl;
                //std::cout << "feature 0 :"<<result[b].info[c].vehicle_fea_res.feature[0]<<std::endl; 
                //std::cout << "feature 1 :"<<result[b].info[c].vehicle_fea_res.feature[1]<<std::endl; 
                //std::cout << "feature 2 :"<<result[b].info[c].vehicle_fea_res.feature[2]<<std::endl; 
                //std::cout << "feature 3 :"<<result[b].info[c].vehicle_fea_res.feature[3]<<std::endl; 
                //std::cout << "feature 4 :"<<result[b].info[c].vehicle_fea_res.feature[4]<<std::endl; 
                //std::cout << "feature 5 :"<<result[b].info[c].vehicle_fea_res.feature[5]<<std::endl; 
                
                //test
                //for(int f=0;f<10;f++)
                //{
                //	float fea=result[b].info[c].vehicle_fea_res.feature[f];
                //	std::cout << "feature "<<f<<":"<<fea<<std::endl; 
                //}
            }

            //11.摩托车三轮车分析
            if(param.vehicle_motor_tricycle_analysis_config==SY_CONFIG_OPEN && (vehicle_type==2 || vehicle_type==3))
            {
                //std::cout << "mta output----"<< std::endl;
                
                if(vehicle_type==2)//摩托车
                {
                //摩托车载人
                //int status=result[b].info[c].mta_res.motor_manned.status;	
                //float score=result[b].info[c].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;
                
                //摩托车驾驶人是否戴安全帽
                int status=result[b].info[c].mta_res.motor_driver_helmeted.status;
                float score=result[b].info[c].mta_res.motor_driver_helmeted.confidence;
                if(status == MOTOR_DRIVER_HELMETED)
                    std::cout << "		    motor info: MOTOR_DRIVER_HELMETED, prob: " << score << std::endl;
                else if(status == MOTOR_DRIVER_NOT_HELMETED)
                    std::cout << "		    motor info: MOTOR_DRIVER_NOT_HELMETED, prob: " << score << std::endl;	
                
                }
            }
                            //载人输出
            //if(param.vehicle_manned_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1 || vehicle_type==3))
            if(param.vehicle_manned_config==SY_CONFIG_OPEN && vehicle_type!=5)
            {
                std::cout << "----------------------manned output----"<< std::endl;
                int hs_count = result[b].info[c].manned_res.hs_count;
                std::cout <<"manned_hs_count:"<< hs_count << std::endl;
                for(int lo=0;lo<hs_count;lo++)
                {
                    int x1=result[b].info[c].manned_res.hs_rect[lo].rect.left_;
                    int y1=result[b].info[c].manned_res.hs_rect[lo].rect.top_;
                    int x2=result[b].info[c].manned_res.hs_rect[lo].rect.left_+result[b].info[c].manned_res.hs_rect[lo].rect.width_;
                    int y2=result[b].info[c].manned_res.hs_rect[lo].rect.top_+result[b].info[c].manned_res.hs_rect[lo].rect.height_;					

                    std::cout <<"manned_hs_rect:"<< x1 <<" "<< y1<<" " <<x2<<"  " << y2<< std::endl;
                    
                    // Point lt(x1, y1);
                    // Point rb(x2, y2);
                    // rectangle(cvImg, lt, rb, cv::Scalar(0, 255, 255), 4);
                }						
            }				
        }

        //测试相似度比对函数,batch_size设为2
        //double similarity=va_compute_similarity(result[0].info[0].vehicle_fea_res.feature, result[1].info[0].vehicle_fea_res.feature, FEATURESIZE);
        //std::cout << "similarity: "<<similarity<<std::endl; 
        
        // cv::imwrite((saveimagepath+file).c_str(),cvImg);
                                                    
    }
    
    //delete result
    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 0;  
}

void VehicleAnalysis::release(){
    if(ctx){
        aclrtDestroyContext(ctx);
    }

    if (m_handle) {
        va_release(&m_handle);
    }
    
}