diff --git a/src/ai_engine_module/GatherDetect.cpp b/src/ai_engine_module/GatherDetect.cpp new file mode 100644 index 0000000..4162197 --- /dev/null +++ b/src/ai_engine_module/GatherDetect.cpp @@ -0,0 +1,79 @@ +/* + * @Author: yangzilong + * @Date: 2021-12-16 14:25:13 + * @Last Modified by: yangzilong + * @Email: yangzilong@objecteye.com + * @Description: + */ +#include "GatherDetect.h" +#include "../ai_platform/mvpt_process_assist.h" + +GatherDetect::GatherDetect() +{ + m_task_param_manager = task_param_manager::getInstance(); +} + +std::vector GatherDetect::process(vector vec_vptMem, vector &ol_det_result, algorithm_type_t algor_type) { + std::vector results; + + map && algor_config_param = m_task_param_manager->get_task_algor_params(); + map> && algor_param = m_task_param_manager->get_task_other_params(); + + for (size_t idx = 0; idx < vec_vptMem.size(); idx++) + { + DeviceMemory* cur_vptMem = vec_vptMem[idx]; + string task_id = cur_vptMem->getId(); + map taskid_obj_count; + map> taskid_to_boxes; + if (algor_config_param.count(task_id) && algor_config_param[task_id].human_algors.count(algor_type)) + { + task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type]; + { + onelevel_det_result &cur_task_ol_detres = ol_det_result[idx]; + + for (int c = 0; c < cur_task_ol_detres.obj_count; c++) + { + auto& obj_c = cur_task_ol_detres.obj[c]; + + bool bHuman = algor_type == algorithm_type_t::HUMAN_GATHER || algor_type == algorithm_type_t::HUMAN_DENSITY || algor_type == algorithm_type_t::HUMAN_REGION_GATHER; + + bool bCount = false; + if(bHuman && obj_c.index == (int)det_class_label_t::HUMAN) { + bCount = true; + } else if (algor_type == algorithm_type_t::VEHICLE_GATHER && obj_c.index >= 4 && obj_c.index <= 8) { + bCount = true; + } + + if (bCount && snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect, obj_c.left, obj_c.top, obj_c.right, obj_c.bottom)) + { + taskid_obj_count[task_id]++; + + auto tmp_box = cur_task_ol_detres.obj[c]; + box_t box; + box.top = tmp_box.top; + box.left = tmp_box.left; + box.right = tmp_box.right; + box.bottom = tmp_box.bottom; + box.score = tmp_box.confidence; + taskid_to_boxes[task_id].emplace_back(std::move(box)); + } + } + } + + int count_threshold = ((algor_config_param_human_gather*)cur_task_params->algor_param)->human_count_threshold; + int frame_stride = ((algor_config_param_human_gather*)cur_task_params->algor_param)->frame_stride; + + if (taskid_obj_count[task_id] > count_threshold && cur_vptMem->getFrameNb() % frame_stride == 0) + { + GatherResult data; + data.origin_img = VPCUtil::vpc_devMem2vpcImg(vec_vptMem[idx]); + data.task_id = task_id; + data.boxes = std::move(taskid_to_boxes[task_id]); + data.id = gid_++; + results.emplace_back(std::move(data)); + } + } + } + + return results; +} \ No newline at end of file diff --git a/src/ai_engine_module/GatherDetect.h b/src/ai_engine_module/GatherDetect.h new file mode 100644 index 0000000..37eba8f --- /dev/null +++ b/src/ai_engine_module/GatherDetect.h @@ -0,0 +1,36 @@ +/* + * @Author: yangzilong + * @Date: 2021-12-10 15:48:49 + * @Last Modified by: yangzilong + * @Last Modified time: Do not edit + * @Email: yangzilong@objecteye.com + * @Description: + */ +#pragma once + +#include +#include +#include +#include "../ai_platform/task_param_manager.h" +#include "./ai_engine_header.h" +#include "../decoder/interface/DeviceMemory.hpp" + +struct GatherResult +{ + long long id; + vpc_img_info origin_img; + std::vector boxes; + std::string task_id; +} ; + +class GatherDetect +{ +public: + GatherDetect(); + + std::vector process(vector vec_vptMem, vector &ol_det_result, algorithm_type_t type); + +private: + task_param_manager *m_task_param_manager{nullptr}; + long long gid_{0}; +}; \ No newline at end of file diff --git a/src/ai_engine_module/RegionLeave.cpp b/src/ai_engine_module/RegionLeave.cpp index c17d901..ff3aee9 100644 --- a/src/ai_engine_module/RegionLeave.cpp +++ b/src/ai_engine_module/RegionLeave.cpp @@ -34,7 +34,12 @@ RegionLeave::RegionLeave(){ RegionLeave::~RegionLeave() { - + if (m_save_util) + { + delete m_save_util; + m_save_util = nullptr; + } + } void RegionLeave::init(int devId, algorithm_type_t eType){ diff --git a/src/ai_engine_module/ai_engine_module.h b/src/ai_engine_module/ai_engine_module.h index 9490d70..cd9ef59 100644 --- a/src/ai_engine_module/ai_engine_module.h +++ b/src/ai_engine_module/ai_engine_module.h @@ -14,4 +14,5 @@ #include "./road_seg_statistics.h" #include "./road_seg_3cls_statistics.h" #include "./road_seg_correlation_algor.h" -#include "./RegionLeave.h" \ No newline at end of file +#include "./RegionLeave.h" +#include "./GatherDetect.h" \ No newline at end of file diff --git a/src/ai_platform/MultiSourceProcess.cpp b/src/ai_platform/MultiSourceProcess.cpp index eb36072..df3805e 100755 --- a/src/ai_platform/MultiSourceProcess.cpp +++ b/src/ai_platform/MultiSourceProcess.cpp @@ -929,8 +929,13 @@ int CMultiSourceProcess::algorthim_vpt(vector vec_gpuMem){ /* 一级检测器,内部已完成跟踪操作 */ vpt_process.process_gpu(vpt_interest_imgs.data(), vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // do det & track. - // vpt_process.process_gpu(vpt_interest_imgs.data(), vec_vptMem, vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // debug - m_snapshot_reprocessing->screen_effective_snapshot(vptResult); + + gather_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_GATHER); // modified by zsh + gather_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_DENSITY); + gather_process(vec_vptMem, vptResult, algorithm_type_t::VEHICLE_GATHER); + gather_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_REGION_GATHER); + + // m_snapshot_reprocessing->screen_effective_snapshot(vptResult); #ifndef VEHICLE_MULTI_BOXES /* 快照优选(内部可实现不同的快照优选策略) */ @@ -2381,6 +2386,45 @@ void CMultiSourceProcess::wander_detect(vector& vec_gpuMem, vecto } +/* 每帧都需要做的算法模块 */ +int CMultiSourceProcess::gather_process(vector& vec_gpuMem, vector &ol_det_result, algorithm_type_t algor_type) { + /* 人数聚集算法功能 每帧都会获取算法结果 并返回 */ + std::vector results; + results = m_algorthim_gather.process(vec_gpuMem, ol_det_result, algor_type); + + int algorithm_type = (int)algor_type; + for (auto &result : results) { + + if (result.boxes.size() <= 0) + { + continue; + } + + auto task_id = result.task_id; + auto task_other_params = m_task_param_manager->get_task_other_param(task_id); + const auto &algor_other_params = task_other_params->find(algor_type); + if (algor_other_params == task_other_params->end()) { + LOG_ERROR("taskId {} not found algor {}", task_id.c_str(), (int)algor_type); + continue; + } + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; + + std::string cur_timestamp_ms = std::to_string(helpers::timer::get_timestamp()); + const std::string origin_file_path = basic_param->result_folder + helpers::os::sep + task_id + "_" + + std::to_string(result.boxes.size()) + "_" + std::to_string(result.id) + "_" + cur_timestamp_ms + ".jpg"; + + string json_str = helpers::gen_json::gen_boxes_json(task_id, algorithm_type, result.boxes, origin_file_path); + + ImgSaveInfo info_origin; + info_origin.img_info = result.origin_img; + info_origin.file_path = origin_file_path; + info_origin.json_str = json_str; + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(info_origin); + } + + return 0; +} + void CMultiSourceProcess::face_locus_finished(const OBJ_KEY obj_key) { map _total_face_snapshot_info = m_snapshot_reprocessing->get_total_face_snapshot_info(); diff --git a/src/ai_platform/MultiSourceProcess.h b/src/ai_platform/MultiSourceProcess.h index 779a568..2eedcf7 100755 --- a/src/ai_platform/MultiSourceProcess.h +++ b/src/ai_platform/MultiSourceProcess.h @@ -20,10 +20,10 @@ #include "../reprocessing_module/mq_manager.hpp" #endif +#include "../decoder/interface/DeviceMemory.hpp" using namespace std; -class DeviceMemory; //分割信息 typedef struct seg_infos { @@ -125,6 +125,8 @@ private: void wander_detect(vector& vec_gpuMem, vector& vptResult, algorithm_type_t eType); + int gather_process(vector& vec_gpuMem, vector &ol_det_result, algorithm_type_t algor_type); + private: int m_devId; @@ -184,6 +186,8 @@ private: RegionLeave m_algorthim_region_dismiss; RegionLeave m_algorthim_region_fastmoving; + GatherDetect m_algorthim_gather; + deque m_recoderinfo_queue; mutex m_recoderinfo_queue_mtx; thread* m_recode_thread {nullptr}; diff --git a/src/ai_platform/header.h b/src/ai_platform/header.h index 7868d8a..8af8ff7 100755 --- a/src/ai_platform/header.h +++ b/src/ai_platform/header.h @@ -35,8 +35,10 @@ enum class algorithm_type_t { ROAD_WORK_DET = 212, // 221026byzsh施工占道 HUMAN_LINGER = 214, // 人员徘徊 + HUMAN_REGION_GATHER = 215, // 区域人员聚集 HUMAN_REGION_DISMISS = 216, // 人员逃散 HUMAN_REGION_FAST_MOVING = 217, // 人员快速移动 + HUMAN_DENSITY = 218, // 人员密度 HUMAN_CLIMB = 220, // 人员攀爬 HUMAN_CROSSING_LINE = 221, // 人员越线 HUMAN_LEAVE_REGION = 222, // 区域离开 diff --git a/src/ai_platform/task_param_manager.cpp b/src/ai_platform/task_param_manager.cpp index a9c4173..d0461cd 100755 --- a/src/ai_platform/task_param_manager.cpp +++ b/src/ai_platform/task_param_manager.cpp @@ -104,7 +104,9 @@ bool copy_algor_param_aux(const algorithm_type_t &algor_type, const std::string } } break; - + case algorithm_type_t::VEHICLE_GATHER: + case algorithm_type_t::HUMAN_REGION_GATHER: + case algorithm_type_t::HUMAN_DENSITY: case algorithm_type_t::HUMAN_GATHER: { m_algor_config_params[task_id].human_algors.insert(algor_type); using algor_config_param_type = algor_config_param_human_gather; @@ -365,6 +367,10 @@ void task_param_manager::delete_task_param(string task_id) { } break; } + + case algorithm_type_t::VEHICLE_GATHER: + case algorithm_type_t::HUMAN_REGION_GATHER: + case algorithm_type_t::HUMAN_DENSITY: case algorithm_type_t::HUMAN_GATHER: { algor_config_param_human_gather *algor_param = (algor_config_param_human_gather *)((algor_init_config_param_t *)m_task_params[task_id][iter.first]) @@ -597,11 +603,19 @@ bool task_param_manager::task_has_vpt_algor(const std::string &task_id) { if (algor_map == nullptr) return false; - return (algor_map->find(algorithm_type_t::HUMAN_GATHER) != algor_map->end() || + return (algor_map->find(algorithm_type_t::HUMAN_GATHER) != algor_map->end() || algor_map->find(algorithm_type_t::HUMAN_SNAPSHOT) != algor_map->end() || + algor_map->find(algorithm_type_t::VEHICLE_GATHER) != algor_map->end() || algor_map->find(algorithm_type_t::HUMAN_CROSSING_LINE) != algor_map->end() || + algor_map->find(algorithm_type_t::HUMAN_DENSITY) != algor_map->end() || algor_map->find(algorithm_type_t::HUMAN_CLIMB) != algor_map->end() || algor_map->find(algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE) != algor_map->end() || + algor_map->find(algorithm_type_t::HUMAN_LINGER) != algor_map->end() || + algor_map->find(algorithm_type_t::VEHICLE_ILLEGAL_PARKING) != algor_map->end() || + algor_map->find(algorithm_type_t::HUMAN_REGION_GATHER) != algor_map->end() || + algor_map->find(algorithm_type_t::HUMAN_LEAVE_REGION) != algor_map->end() || + algor_map->find(algorithm_type_t::HUMAN_REGION_DISMISS) != algor_map->end() || + algor_map->find(algorithm_type_t::HUMAN_REGION_FAST_MOVING) != algor_map->end() || algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT) != algor_map->end() || algor_map->find(algorithm_type_t::SMOKING_DET) != algor_map->end() || algor_map->find(algorithm_type_t::NO_REFLECTIVE_CLOTHING) != algor_map->end() ||