From 10667f7cf930d79a1dc63424322e9c5ac0da470c Mon Sep 17 00:00:00 2001 From: cmhu <2657262686@qq.com> Date: Thu, 23 Jan 2025 11:11:48 +0800 Subject: [PATCH] 违法载人判断的优化 --- src/PicAnalysis.cpp | 73 +++++++++++++++++++++++++++++++++++++++++-------------------------------- src/ai_engine_module/VehicleAnalysis.cpp | 4 ++-- src/ai_engine_module/VehicleHeadTail.h | 2 +- src/common/sy_errorinfo.h | 2 +- src/village_inc.h | 6 +++--- 5 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/PicAnalysis.cpp b/src/PicAnalysis.cpp index 2f6b79b..15d3480 100644 --- a/src/PicAnalysis.cpp +++ b/src/PicAnalysis.cpp @@ -36,14 +36,14 @@ int PicAnalysis::init(VillageParam param) { return -1; } - // head_tail_param ht_param; - // ht_param.devId = dev_id; - // ht_param.max_batch = 16; - // ht_param.sdk_path = param.sdk_path; - // ret = m_head_tail_algorithm.init(ht_param); - // if(0 != ret){ - // return -1; - // } + head_tail_param ht_param; + ht_param.devId = dev_id; + ht_param.max_batch = 16; + ht_param.sdk_root = param.sdk_path; + ret = m_head_tail_algorithm.init(ht_param); + if(0 != ret){ + return -1; + } ret = m_clothes_algorithm.init(dev_id, param.sdk_path); if(0 != ret){ @@ -157,6 +157,7 @@ vector PicAnalysis::va_result2AnalysisResult(va_result* result, info.type = result_info.type ; info.vpt_type = result_info.vpt_type ; + auto pendant_result = result_info.vehicle_pendant_det_res; for (size_t j = 0; j < pendant_result.count; j++) { @@ -243,7 +244,7 @@ vector PicAnalysis::analysis_img(vector vec_img){ } // 行人 - if (6 == shot_type) + if (0 == result_info.vpt_type) { ImageData* human_data = m_crop_util.crop(src, vehicle_rect.left_, vehicle_rect.top_, vehicle_rect.left_ + vehicle_rect.width_, vehicle_rect.top_ + vehicle_rect.height_); @@ -262,20 +263,39 @@ vector PicAnalysis::analysis_img(vector vec_img){ delete human_data; human_data = nullptr; - } else if(1 == shot_type) { - // 车尾,判断是否 货车尾部货厢载人 - if(result_info.vpt_type == 6 || result_info.vpt_type == 7){ - if(result_info.manned_res.hs_count > 0){ - result_info.truck_manned = 1; - } - } + } else if(result_info.vpt_type == 1 || result_info.vpt_type == 2 || result_info.vpt_type == 3){ + if(result_info.manned_res.hs_count >= 3){ + // 摩托车、三轮车载人 + result_info.motor_manned = 1; + } } else { - if(result_info.vpt_type == 1 || result_info.vpt_type == 2 || result_info.vpt_type == 3){ - if(result_info.manned_res.hs_count >= 3){ - // 摩托车、三轮车载人 - result_info.motor_manned = 1; - } + ImageData* vehicle_data = m_crop_util.crop(src, vehicle_rect.left_, vehicle_rect.top_, vehicle_rect.left_ + vehicle_rect.width_, vehicle_rect.top_ + vehicle_rect.height_); + + sy_img img; + img.w_ = vehicle_data->alignWidth; + img.h_ = vehicle_data->alignHeight; + img.data_ = vehicle_data->data_naked; + + vector vec_vehicle_img; + vec_vehicle_img.push_back(img); + + vector head_tail_result; + ret = m_head_tail_algorithm.detect(vec_vehicle_img, head_tail_result); + if (0 != ret) { + LOG_ERROR("m_head_tail_algorithm failed!"); + head_tail_result.clear(); + } else { + auto one_ht_result = head_tail_result[0]; + + if(result_info.vpt_type == 6 || result_info.vpt_type == 7){ + if (one_ht_result.cls == 0 && result_info.manned_res.hs_count > 0) + { // 车尾,判断是否 货车尾部货厢载人 + result_info.truck_manned = 1; + } + } } + + } // 司乘 @@ -318,10 +338,6 @@ vector PicAnalysis::analysis_img(vector vec_img){ // 摩托车 if(shot_type==2)//摩托车 { - //摩托车驾驶人是否戴安全帽 - // analysis_result.motor_helmeted = result_info.mta_res.motor_driver_helmeted.status; - // float score=result_info.mta_res.motor_driver_helmeted.confidence; - ImageData* motor_data = m_crop_util.crop(src, vehicle_rect.left_, vehicle_rect.top_, vehicle_rect.left_ + vehicle_rect.width_, vehicle_rect.top_ + vehicle_rect.height_); sy_img img; @@ -378,13 +394,6 @@ vector PicAnalysis::analysis_img(vector vec_img){ } } - // vector head_tail_result; - // ret = m_head_tail_algorithm.detect(vec_img, head_tail_result); - // if (0 != ret) { - // LOG_ERROR("m_head_tail_algorithm failed!"); - // head_tail_result.clear(); - // } - LOG_INFO("analysis finished!"); return vec_result; diff --git a/src/ai_engine_module/VehicleAnalysis.cpp b/src/ai_engine_module/VehicleAnalysis.cpp index 93f714e..668d08d 100644 --- a/src/ai_engine_module/VehicleAnalysis.cpp +++ b/src/ai_engine_module/VehicleAnalysis.cpp @@ -19,8 +19,8 @@ int VehicleAnalysis::init(int devId, std::string sdk_root, int max_batch_size) { param.vehicle_motor_tricycle_analysis_config= SY_CONFIG_OPEN; //8.摩托车分析 param.vehicle_manned_config= SY_CONFIG_OPEN; //8.开启载人分析 param.vehicle_illegal_config= SY_CONFIG_OPEN; //7.开启车违规 - param.vehicle_color_config= SY_CONFIG_CLOSE; //3.开启车颜色识别 - param.vehicle_feature_config= SY_CONFIG_CLOSE; //8.开启车辆特征提取 + param.vehicle_color_config= SY_CONFIG_OPEN; //3.开启车颜色识别 + param.vehicle_feature_config= SY_CONFIG_OPEN; //8.开启车辆特征提取 param.gpuid=devId; diff --git a/src/ai_engine_module/VehicleHeadTail.h b/src/ai_engine_module/VehicleHeadTail.h index 9dceccb..afceac1 100644 --- a/src/ai_engine_module/VehicleHeadTail.h +++ b/src/ai_engine_module/VehicleHeadTail.h @@ -19,7 +19,7 @@ typedef struct head_tail_param } head_tail_param; struct HeadTailResult { - int cls; + int cls; // {'车尾': 0, '车侧': 1, '车头': 2} float confidence; }; diff --git a/src/common/sy_errorinfo.h b/src/common/sy_errorinfo.h index f5600f4..ae51870 100644 --- a/src/common/sy_errorinfo.h +++ b/src/common/sy_errorinfo.h @@ -4,8 +4,8 @@ //--------------------------------通用------------------------------------// -#define SY_SUCCESS 0 //成功 #define SY_FAILED -1 //失败 +#define SY_SUCCESS 0 //成功 //1.通用错误 预留编号:(-199) - (-100) #define SY_PARAMS_NULL_ERROR -100 //参数为空 diff --git a/src/village_inc.h b/src/village_inc.h index 59ef771..ec6fbdd 100644 --- a/src/village_inc.h +++ b/src/village_inc.h @@ -28,10 +28,10 @@ struct VillageParam { typedef struct pendant_info { sy_rect rect; - int index; //���� 0-driver 1-face 2-belt 3-sunshield 4-tag 5-decoration 6-napkinbox 7-zhuanjt 8-callPhone 9-sunRoof 10-holder 11-smoke - float confidence; + int index{-1}; //���� 0-driver 1-face 2-belt 3-sunshield 4-tag 5-decoration 6-napkinbox 7-zhuanjt 8-callPhone 9-sunRoof 10-holder 11-smoke + float confidence{0.0}; int driver_copilot_info; - int iColor; // "棕", "橙", "灰", "白", "粉", "紫", "红", "绿", "蓝", "银", "青", "黄", "黑", ,"多色", "其他" + int iColor{14}; // "棕", "橙", "灰", "白", "粉", "紫", "红", "绿", "蓝", "银", "青", "黄", "黑", ,"多色", "其他" } pendant_info; typedef struct VehicleInfo { -- libgit2 0.21.4