diff --git a/src/ai_engine_module/road_seg_correlation_algor.cpp b/src/ai_engine_module/road_seg_correlation_algor.cpp index 05b2677..a8a2f59 100644 --- a/src/ai_engine_module/road_seg_correlation_algor.cpp +++ b/src/ai_engine_module/road_seg_correlation_algor.cpp @@ -19,7 +19,8 @@ namespace ai_engine_module algorithm_type_t::NONMOTOR_CEOSSPARKLINE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, - algorithm_type_t::VEHICLE_WRONGDIRECTION, + algorithm_type_t::VEHICLE_WRONGDIRECTION, + algorithm_type_t::VEHICLE_NOTGIVEWAY, }; // 判断是否是机动车 @@ -445,6 +446,8 @@ namespace ai_engine_module std::map flattened_idx_to_batch_idx; //! 记录每个box对应的算法以及流id. std::map flattened_idx_to_algor_seq; + // 记录每帧中的行人目标 k:pic index v:data + std::map> frame_person_data; /* 1. Crop & keep some interest class. */ auto taskId_iter = taskIds.begin(); @@ -491,7 +494,7 @@ namespace ai_engine_module continue; stream_idx_and_algor_seq.algors.emplace(algor_type); - if (algor_type == algorithm_type_t::VEHICLE_WRONGDIRECTION ) has_vehicle_algor = true; + if (algor_type == algorithm_type_t::VEHICLE_WRONGDIRECTION || algor_type == algorithm_type_t::VEHICLE_NOTGIVEWAY) has_vehicle_algor = true; } if (stream_idx_and_algor_seq.algors.empty()) @@ -537,6 +540,12 @@ namespace ai_engine_module flattened_interest_data.emplace_back(std::move(data)); flattened_idx_to_algor_seq[flattened_idx] = std::move(stream_idx_and_algor_seq); flattened_idx_to_batch_idx[flattened_idx++] = n; + + // 汇总当前帧的行人目标 + if (static_cast(box.index) == det_class_label_t::HUMAN) { + frame_person_data[n].push_back(data); + } + } } ++taskId_iter; @@ -628,7 +637,7 @@ namespace ai_engine_module if ((algor_type == algorithm_type_t::NONMOTOR_IN_VEHICLELANE || algor_type == algorithm_type_t::NONMOTOR_CEOSSPARKLINE || algor_type == algorithm_type_t::NONMOTOR_WRONGDIRECTION) && !is_valid_nomotor(static_cast(det_result.box.cls))) continue; - if ((algor_type == algorithm_type_t::VEHICLE_WRONGDIRECTION) && !is_valid_car(static_cast(det_result.box.cls))) + if ((algor_type == algorithm_type_t::VEHICLE_WRONGDIRECTION || algor_type == algorithm_type_t::VEHICLE_NOTGIVEWAY) && !is_valid_car(static_cast(det_result.box.cls))) continue; auto& e = id_to_mn_[obj_key]; @@ -707,9 +716,37 @@ namespace ai_engine_module if (!isalarm) continue; } + // 机动车不让行:针对人行道区域有行人,车辆不停车的情形 + if (algor_type == algorithm_type_t::VEHICLE_NOTGIVEWAY) { + bool isalarm = false; + int stop_check_frames = 30; // 30 6s + float stop_min_move = 25; + if (m_total_obj_info[trace_obj_key].center_points.size() > stop_check_frames) { //1. 忽略太短轨迹 + for (auto human_data : frame_person_data[flattened_idx_to_batch_idx[n]]) { + tr_point humanpos; + humanpos.x = (human_data.box.left + human_data.box.right) * 0.5; humanpos.y = human_data.box.bottom; + float temp_diff_x = curpos.x-humanpos.x, temp_diff_y = curpos.y-humanpos.y; + float temp_dist = sqrt(temp_diff_x * temp_diff_x + temp_diff_y * temp_diff_y); + //2.查找当前车辆附近的行人:距离小于车宽认为在附近 + if (temp_dist < flattened_imgs[n].w_) { + for (auto region : crosswalk_regions) { + vector tr_boxes = Mbuild_area(region); + bool human_flag = McheckPointPolygon(tr_boxes, humanpos); //3.判断行人是否在人行道 + if (human_flag) { //4.判断行人在人行道时车辆是否停车 + float res_max_dist = 0; + float total_dist = diff_car_pos(m_total_obj_info[trace_obj_key].center_points, stop_check_frames, res_max_dist); + if (res_max_dist > stop_min_move) { isalarm = true; break; } // 未停车--->未礼让 + } + } + } + if (isalarm) break; + } + } + if (!isalarm) continue; + } + { - // if (++e.n_frame == algor_param->n) if (++e.n_frame == algor_param->n || algor_type == algorithm_type_t::NONMOTOR_CEOSSPARKLINE || algor_type == algorithm_type_t::PERSON_CROSS ) //部分功能当前版本暂不投票 { diff --git a/src/ai_platform/MultiSourceProcess.cpp b/src/ai_platform/MultiSourceProcess.cpp index e13d722..f4f3651 100755 --- a/src/ai_platform/MultiSourceProcess.cpp +++ b/src/ai_platform/MultiSourceProcess.cpp @@ -503,6 +503,9 @@ bool CMultiSourceProcess::task_has_vpt_algor(const std::string &task_id){ algor_map->find(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) != algor_map->end() || algor_map->find(algorithm_type_t::PERSON_CROSS) != algor_map->end() || algor_map->find(algorithm_type_t::VEHICLE_WRONGDIRECTION) != algor_map->end() || + algor_map->find(algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) != algor_map->end() || + algor_map->find(algorithm_type_t::VEHICLE_NOTGIVEWAY) != algor_map->end() || + algor_map->find(algorithm_type_t::VEHICLE_NOTDECELERATION) != algor_map->end() || algor_map->find(algorithm_type_t::TRICYCLE_MANNED) != algor_map->end() || algor_map->find(algorithm_type_t::TRUCK_MANNED) != algor_map->end()); } @@ -1643,7 +1646,8 @@ void CMultiSourceProcess::algorithm_roadseg_correlation_process(vector& algor_map->find(algorithm_type_t::NONMOTOR_CEOSSPARKLINE) != algor_map->end() || algor_map->find(algorithm_type_t::PERSON_CROSS) != algor_map->end() || algor_map->find(algorithm_type_t::NONMOTOR_WRONGDIRECTION) != algor_map->end() || - algor_map->find(algorithm_type_t::VEHICLE_WRONGDIRECTION) != algor_map->end() + algor_map->find(algorithm_type_t::VEHICLE_WRONGDIRECTION) != algor_map->end() || + algor_map->find(algorithm_type_t::VEHICLE_NOTGIVEWAY) != algor_map->end() ) { m_RoadSegTaskMtx.lock(); @@ -1841,7 +1845,7 @@ void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, } vector roadseg_algor = {algorithm_type_t::PERSON_IN_VEHICLELANE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_IN_VEHICLELANE, algorithm_type_t::NONMOTOR_CEOSSPARKLINE, - algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION }; + algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY }; for (size_t idx = 0; idx < roadseg_algor.size(); ++idx) { if (algor_param[task_id].count(roadseg_algor.at(idx))) { const auto &algor_other_params = task_other_params->find(roadseg_algor.at(idx)); diff --git a/src/ai_platform/header.h b/src/ai_platform/header.h index 94cb23a..1ee1d76 100755 --- a/src/ai_platform/header.h +++ b/src/ai_platform/header.h @@ -56,6 +56,9 @@ enum class algorithm_type_t { PERSON_CROSS = 512, // 行人翻越护栏 NONMOTOR_WRONGDIRECTION = 513, // 非机动车逆行 VEHICLE_WRONGDIRECTION = 514, // 机动车逆行 + VEHICLE_SOLIDLINETURNAROUND = 515,// 机动车实线掉头 + VEHICLE_NOTGIVEWAY = 516, // 机动车不让行 + VEHICLE_NOTDECELERATION = 517, // 机动车不减速 }; diff --git a/src/ai_platform/task_param_manager.cpp b/src/ai_platform/task_param_manager.cpp index b7b9d66..e2badde 100755 --- a/src/ai_platform/task_param_manager.cpp +++ b/src/ai_platform/task_param_manager.cpp @@ -85,6 +85,9 @@ bool copy_algor_param_aux(const algorithm_type_t &algor_type, const std::string case algorithm_type_t::VEHICLE_WRONGDIRECTION: m_algor_config_params[task_id].vehicle_algors.insert(algor_type); goto _manned_param_copy; + case algorithm_type_t::VEHICLE_NOTGIVEWAY: + m_algor_config_params[task_id].vehicle_algors.insert(algor_type); + goto _manned_param_copy; case algorithm_type_t::TRUCK_MANNED: { m_algor_config_params[task_id].vehicle_algors.insert(algor_type); _manned_param_copy : { diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index fcfde58..ccb52f0 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -210,7 +210,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty { algor_params->m = 10; algor_params->n = 8; - algor_params->hs_count_threshold = 0; + algor_params->hs_count_threshold = 1; algor_params->obj_confidence_threshold = 0.5f; algor_params->obj_min_height = 6; algor_params->obj_min_width = 32; @@ -354,7 +354,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty algor_init_params->basic_param = basic_params; } break; - case algorithm_type_t::VEHICLE_WRONGDIRECTION: { + case algorithm_type_t::VEHICLE_WRONGDIRECTION: { auto algor_params = new algor_config_param_manned_incident; { algor_params->m = 5; @@ -375,6 +375,27 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty algor_init_params->basic_param = basic_params; } break; + case algorithm_type_t::VEHICLE_NOTGIVEWAY: { + auto algor_params = new algor_config_param_manned_incident; + { + algor_params->m = 10; + algor_params->n = 8; + algor_params->obj_confidence_threshold = 0.5f; + algor_params->obj_min_height = 40; + algor_params->obj_min_width = 40; + } + + auto basic_params = new algor_basic_config_param_t; + { + basic_params->video_folder = "res/video_recode"; + basic_params->result_folder = "res/vehicle_notgiveway"; + basic_params->result_folder_little = "res/vehicle_notgiveway_little"; + } + + algor_init_params->algor_param = algor_params; + algor_init_params->basic_param = basic_params; + } break; + case algorithm_type_t::FACE_SNAPSHOT: { auto basic_params = new algor_basic_config_param_t; @@ -1016,8 +1037,8 @@ void test_gpu(int gpuID){ std::vector algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE, algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS, algorithm_type_t::PERSON_IN_VEHICLELANE, algorithm_type_t::NONMOTOR_IN_VEHICLELANE, - algorithm_type_t::NONMOTOR_CEOSSPARKLINE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION}; - std::vector algor_vec3 = {algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION}; + algorithm_type_t::NONMOTOR_CEOSSPARKLINE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY}; + std::vector algor_vec3 = {algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS}; /* int repeat_num = 1000; @@ -1039,22 +1060,22 @@ void test_gpu(int gpuID){ // createTask(handle, algor_vec, 1); // createTask(handle, algor_vec, 2); // createTask(handle, algor_vec, 3); - createTask(handle, algor_vec3, 4); - createTask(handle, algor_vec3, 5); - createTask(handle, algor_vec3, 6); - createTask(handle, algor_vec3, 7); - createTask(handle, algor_vec3, 8); - createTask(handle, algor_vec3, 9); - createTask(handle, algor_vec3, 10); - createTask(handle, algor_vec3, 11); - createTask(handle, algor_vec3, 12); - createTask(handle, algor_vec3, 13); - createTask(handle, algor_vec3, 14); - createTask(handle, algor_vec3, 15); - createTask(handle, algor_vec3, 16); - createTask(handle, algor_vec3, 17); - createTask(handle, algor_vec3, 18); - createTask(handle, algor_vec3, 19); + createTask(handle, algor_vec2, 4); + createTask(handle, algor_vec2, 5); + createTask(handle, algor_vec2, 6); + createTask(handle, algor_vec2, 7); + createTask(handle, algor_vec2, 8); + createTask(handle, algor_vec2, 9); + createTask(handle, algor_vec2, 10); + createTask(handle, algor_vec2, 11); + createTask(handle, algor_vec2, 12); + createTask(handle, algor_vec2, 13); + createTask(handle, algor_vec2, 14); + createTask(handle, algor_vec2, 15); + createTask(handle, algor_vec2, 16); + createTask(handle, algor_vec2, 17); + createTask(handle, algor_vec2, 18); + createTask(handle, algor_vec2, 19); // createTask(handle, algor_vec2, 20); // createTask(handle, algor_vec2, 21); // createTask(handle, algor_vec2, 22); diff --git a/src/reprocessing_module/snapshot_reprocessing.cpp b/src/reprocessing_module/snapshot_reprocessing.cpp index a8a8712..3a6ed9b 100755 --- a/src/reprocessing_module/snapshot_reprocessing.cpp +++ b/src/reprocessing_module/snapshot_reprocessing.cpp @@ -393,8 +393,9 @@ void snapshot_reprocessing::update_village_bestsnapshot(vector ve algor_param[task_id].count(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) || algor_param[task_id].count(algorithm_type_t::PERSON_IN_VEHICLELANE) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_IN_VEHICLELANE) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_CEOSSPARKLINE) || algor_param[task_id].count(algorithm_type_t::PERSON_CROSS) || - algor_param[task_id].count(algorithm_type_t::NONMOTOR_WRONGDIRECTION) || algor_param[task_id].count(algorithm_type_t::VEHICLE_WRONGDIRECTION) - )) + algor_param[task_id].count(algorithm_type_t::NONMOTOR_WRONGDIRECTION) || algor_param[task_id].count(algorithm_type_t::VEHICLE_WRONGDIRECTION) || + algor_param[task_id].count(algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) || algor_param[task_id].count(algorithm_type_t::VEHICLE_NOTGIVEWAY) || + algor_param[task_id].count(algorithm_type_t::VEHICLE_NOTDECELERATION))) continue; if(!snapshot_legal_minarea(index, cur_real_width, cur_real_height)){ @@ -460,8 +461,9 @@ void snapshot_reprocessing::update_village_bestsnapshot(vector ve algor_param[task_id].count(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) || algor_param[task_id].count(algorithm_type_t::PERSON_IN_VEHICLELANE) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_IN_VEHICLELANE) || algor_param[task_id].count(algorithm_type_t::NONMOTOR_CEOSSPARKLINE) || algor_param[task_id].count(algorithm_type_t::PERSON_CROSS) || - algor_param[task_id].count(algorithm_type_t::NONMOTOR_WRONGDIRECTION) || algor_param[task_id].count(algorithm_type_t::VEHICLE_WRONGDIRECTION) - )) + algor_param[task_id].count(algorithm_type_t::NONMOTOR_WRONGDIRECTION) || algor_param[task_id].count(algorithm_type_t::VEHICLE_WRONGDIRECTION) || + algor_param[task_id].count(algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) || algor_param[task_id].count(algorithm_type_t::VEHICLE_NOTGIVEWAY) || + algor_param[task_id].count(algorithm_type_t::VEHICLE_NOTDECELERATION))) continue; // 过滤边缘位置