Commit f1eb769d1fe68bb3e160ff65989281c2725d0add
1 parent
7cf9e4fe
1. 添加GatherDetect
2.补充 task_has_vpt_algor
Showing
8 changed files
with
192 additions
and
7 deletions
src/ai_engine_module/GatherDetect.cpp
0 → 100644
1 | +/* | |
2 | + * @Author: yangzilong | |
3 | + * @Date: 2021-12-16 14:25:13 | |
4 | + * @Last Modified by: yangzilong | |
5 | + * @Email: yangzilong@objecteye.com | |
6 | + * @Description: | |
7 | + */ | |
8 | +#include "GatherDetect.h" | |
9 | +#include "../ai_platform/mvpt_process_assist.h" | |
10 | + | |
11 | +GatherDetect::GatherDetect() | |
12 | +{ | |
13 | + m_task_param_manager = task_param_manager::getInstance(); | |
14 | +} | |
15 | + | |
16 | +std::vector<GatherResult> GatherDetect::process(vector<DeviceMemory*> vec_vptMem, vector<onelevel_det_result> &ol_det_result, algorithm_type_t algor_type) { | |
17 | + std::vector<GatherResult> results; | |
18 | + | |
19 | + map<string, algor_open_config_param> && algor_config_param = m_task_param_manager->get_task_algor_params(); | |
20 | + map<string, map<algo_type, task_param_manager::algo_param_type_t_*>> && algor_param = m_task_param_manager->get_task_other_params(); | |
21 | + | |
22 | + for (size_t idx = 0; idx < vec_vptMem.size(); idx++) | |
23 | + { | |
24 | + DeviceMemory* cur_vptMem = vec_vptMem[idx]; | |
25 | + string task_id = cur_vptMem->getId(); | |
26 | + map<string, int> taskid_obj_count; | |
27 | + map<string, std::vector<box_t>> taskid_to_boxes; | |
28 | + if (algor_config_param.count(task_id) && algor_config_param[task_id].human_algors.count(algor_type)) | |
29 | + { | |
30 | + task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type]; | |
31 | + { | |
32 | + onelevel_det_result &cur_task_ol_detres = ol_det_result[idx]; | |
33 | + | |
34 | + for (int c = 0; c < cur_task_ol_detres.obj_count; c++) | |
35 | + { | |
36 | + auto& obj_c = cur_task_ol_detres.obj[c]; | |
37 | + | |
38 | + bool bHuman = algor_type == algorithm_type_t::HUMAN_GATHER || algor_type == algorithm_type_t::HUMAN_DENSITY || algor_type == algorithm_type_t::HUMAN_REGION_GATHER; | |
39 | + | |
40 | + bool bCount = false; | |
41 | + if(bHuman && obj_c.index == (int)det_class_label_t::HUMAN) { | |
42 | + bCount = true; | |
43 | + } else if (algor_type == algorithm_type_t::VEHICLE_GATHER && obj_c.index >= 4 && obj_c.index <= 8) { | |
44 | + bCount = true; | |
45 | + } | |
46 | + | |
47 | + 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)) | |
48 | + { | |
49 | + taskid_obj_count[task_id]++; | |
50 | + | |
51 | + auto tmp_box = cur_task_ol_detres.obj[c]; | |
52 | + box_t box; | |
53 | + box.top = tmp_box.top; | |
54 | + box.left = tmp_box.left; | |
55 | + box.right = tmp_box.right; | |
56 | + box.bottom = tmp_box.bottom; | |
57 | + box.score = tmp_box.confidence; | |
58 | + taskid_to_boxes[task_id].emplace_back(std::move(box)); | |
59 | + } | |
60 | + } | |
61 | + } | |
62 | + | |
63 | + int count_threshold = ((algor_config_param_human_gather*)cur_task_params->algor_param)->human_count_threshold; | |
64 | + int frame_stride = ((algor_config_param_human_gather*)cur_task_params->algor_param)->frame_stride; | |
65 | + | |
66 | + if (taskid_obj_count[task_id] > count_threshold && cur_vptMem->getFrameNb() % frame_stride == 0) | |
67 | + { | |
68 | + GatherResult data; | |
69 | + data.origin_img = VPCUtil::vpc_devMem2vpcImg(vec_vptMem[idx]); | |
70 | + data.task_id = task_id; | |
71 | + data.boxes = std::move(taskid_to_boxes[task_id]); | |
72 | + data.id = gid_++; | |
73 | + results.emplace_back(std::move(data)); | |
74 | + } | |
75 | + } | |
76 | + } | |
77 | + | |
78 | + return results; | |
79 | +} | |
0 | 80 | \ No newline at end of file | ... | ... |
src/ai_engine_module/GatherDetect.h
0 → 100644
1 | +/* | |
2 | + * @Author: yangzilong | |
3 | + * @Date: 2021-12-10 15:48:49 | |
4 | + * @Last Modified by: yangzilong | |
5 | + * @Last Modified time: Do not edit | |
6 | + * @Email: yangzilong@objecteye.com | |
7 | + * @Description: | |
8 | + */ | |
9 | +#pragma once | |
10 | + | |
11 | +#include <set> | |
12 | +#include <string> | |
13 | +#include <vector> | |
14 | +#include "../ai_platform/task_param_manager.h" | |
15 | +#include "./ai_engine_header.h" | |
16 | +#include "../decoder/interface/DeviceMemory.hpp" | |
17 | + | |
18 | +struct GatherResult | |
19 | +{ | |
20 | + long long id; | |
21 | + vpc_img_info origin_img; | |
22 | + std::vector<box_t> boxes; | |
23 | + std::string task_id; | |
24 | +} ; | |
25 | + | |
26 | +class GatherDetect | |
27 | +{ | |
28 | +public: | |
29 | + GatherDetect(); | |
30 | + | |
31 | + std::vector<GatherResult> process(vector<DeviceMemory*> vec_vptMem, vector<onelevel_det_result> &ol_det_result, algorithm_type_t type); | |
32 | + | |
33 | +private: | |
34 | + task_param_manager *m_task_param_manager{nullptr}; | |
35 | + long long gid_{0}; | |
36 | +}; | |
0 | 37 | \ No newline at end of file | ... | ... |
src/ai_engine_module/RegionLeave.cpp
src/ai_engine_module/ai_engine_module.h
... | ... | @@ -14,4 +14,5 @@ |
14 | 14 | #include "./road_seg_statistics.h" |
15 | 15 | #include "./road_seg_3cls_statistics.h" |
16 | 16 | #include "./road_seg_correlation_algor.h" |
17 | -#include "./RegionLeave.h" | |
18 | 17 | \ No newline at end of file |
18 | +#include "./RegionLeave.h" | |
19 | +#include "./GatherDetect.h" | |
19 | 20 | \ No newline at end of file | ... | ... |
src/ai_platform/MultiSourceProcess.cpp
... | ... | @@ -929,8 +929,13 @@ int CMultiSourceProcess::algorthim_vpt(vector<DeviceMemory*> vec_gpuMem){ |
929 | 929 | |
930 | 930 | /* 一级检测器,内部已完成跟踪操作 */ |
931 | 931 | vpt_process.process_gpu(vpt_interest_imgs.data(), vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // do det & track. |
932 | - // vpt_process.process_gpu(vpt_interest_imgs.data(), vec_vptMem, vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // debug | |
933 | - m_snapshot_reprocessing->screen_effective_snapshot(vptResult); | |
932 | + | |
933 | + gather_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_GATHER); // modified by zsh | |
934 | + gather_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_DENSITY); | |
935 | + gather_process(vec_vptMem, vptResult, algorithm_type_t::VEHICLE_GATHER); | |
936 | + gather_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_REGION_GATHER); | |
937 | + | |
938 | + // m_snapshot_reprocessing->screen_effective_snapshot(vptResult); | |
934 | 939 | |
935 | 940 | #ifndef VEHICLE_MULTI_BOXES |
936 | 941 | /* 快照优选(内部可实现不同的快照优选策略) */ |
... | ... | @@ -2381,6 +2386,45 @@ void CMultiSourceProcess::wander_detect(vector<DeviceMemory*>& vec_gpuMem, vecto |
2381 | 2386 | |
2382 | 2387 | } |
2383 | 2388 | |
2389 | +/* 每帧都需要做的算法模块 */ | |
2390 | +int CMultiSourceProcess::gather_process(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result> &ol_det_result, algorithm_type_t algor_type) { | |
2391 | + /* 人数聚集算法功能 每帧都会获取算法结果 并返回 */ | |
2392 | + std::vector<GatherResult> results; | |
2393 | + results = m_algorthim_gather.process(vec_gpuMem, ol_det_result, algor_type); | |
2394 | + | |
2395 | + int algorithm_type = (int)algor_type; | |
2396 | + for (auto &result : results) { | |
2397 | + | |
2398 | + if (result.boxes.size() <= 0) | |
2399 | + { | |
2400 | + continue; | |
2401 | + } | |
2402 | + | |
2403 | + auto task_id = result.task_id; | |
2404 | + auto task_other_params = m_task_param_manager->get_task_other_param(task_id); | |
2405 | + const auto &algor_other_params = task_other_params->find(algor_type); | |
2406 | + if (algor_other_params == task_other_params->end()) { | |
2407 | + LOG_ERROR("taskId {} not found algor {}", task_id.c_str(), (int)algor_type); | |
2408 | + continue; | |
2409 | + } | |
2410 | + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | |
2411 | + | |
2412 | + std::string cur_timestamp_ms = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>()); | |
2413 | + const std::string origin_file_path = basic_param->result_folder + helpers::os::sep + task_id + "_" + | |
2414 | + std::to_string(result.boxes.size()) + "_" + std::to_string(result.id) + "_" + cur_timestamp_ms + ".jpg"; | |
2415 | + | |
2416 | + string json_str = helpers::gen_json::gen_boxes_json(task_id, algorithm_type, result.boxes, origin_file_path); | |
2417 | + | |
2418 | + ImgSaveInfo info_origin; | |
2419 | + info_origin.img_info = result.origin_img; | |
2420 | + info_origin.file_path = origin_file_path; | |
2421 | + info_origin.json_str = json_str; | |
2422 | + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(info_origin); | |
2423 | + } | |
2424 | + | |
2425 | + return 0; | |
2426 | +} | |
2427 | + | |
2384 | 2428 | void CMultiSourceProcess::face_locus_finished(const OBJ_KEY obj_key) { |
2385 | 2429 | map<OBJ_KEY, OBJ_VALUE> _total_face_snapshot_info = m_snapshot_reprocessing->get_total_face_snapshot_info(); |
2386 | 2430 | ... | ... |
src/ai_platform/MultiSourceProcess.h
... | ... | @@ -20,10 +20,10 @@ |
20 | 20 | #include "../reprocessing_module/mq_manager.hpp" |
21 | 21 | #endif |
22 | 22 | |
23 | +#include "../decoder/interface/DeviceMemory.hpp" | |
23 | 24 | |
24 | 25 | using namespace std; |
25 | 26 | |
26 | -class DeviceMemory; | |
27 | 27 | |
28 | 28 | //分割信息 |
29 | 29 | typedef struct seg_infos { |
... | ... | @@ -125,6 +125,8 @@ private: |
125 | 125 | |
126 | 126 | void wander_detect(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType); |
127 | 127 | |
128 | + int gather_process(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result> &ol_det_result, algorithm_type_t algor_type); | |
129 | + | |
128 | 130 | private: |
129 | 131 | int m_devId; |
130 | 132 | |
... | ... | @@ -184,6 +186,8 @@ private: |
184 | 186 | RegionLeave m_algorthim_region_dismiss; |
185 | 187 | RegionLeave m_algorthim_region_fastmoving; |
186 | 188 | |
189 | + GatherDetect m_algorthim_gather; | |
190 | + | |
187 | 191 | deque<RecoderInfo> m_recoderinfo_queue; |
188 | 192 | mutex m_recoderinfo_queue_mtx; |
189 | 193 | thread* m_recode_thread {nullptr}; | ... | ... |
src/ai_platform/header.h
... | ... | @@ -35,8 +35,10 @@ enum class algorithm_type_t { |
35 | 35 | ROAD_WORK_DET = 212, // 221026byzsh施工占道 |
36 | 36 | |
37 | 37 | HUMAN_LINGER = 214, // 人员徘徊 |
38 | + HUMAN_REGION_GATHER = 215, // 区域人员聚集 | |
38 | 39 | HUMAN_REGION_DISMISS = 216, // 人员逃散 |
39 | 40 | HUMAN_REGION_FAST_MOVING = 217, // 人员快速移动 |
41 | + HUMAN_DENSITY = 218, // 人员密度 | |
40 | 42 | HUMAN_CLIMB = 220, // 人员攀爬 |
41 | 43 | HUMAN_CROSSING_LINE = 221, // 人员越线 |
42 | 44 | HUMAN_LEAVE_REGION = 222, // 区域离开 | ... | ... |
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 |
104 | 104 | } |
105 | 105 | } break; |
106 | 106 | |
107 | - | |
107 | + case algorithm_type_t::VEHICLE_GATHER: | |
108 | + case algorithm_type_t::HUMAN_REGION_GATHER: | |
109 | + case algorithm_type_t::HUMAN_DENSITY: | |
108 | 110 | case algorithm_type_t::HUMAN_GATHER: { |
109 | 111 | m_algor_config_params[task_id].human_algors.insert(algor_type); |
110 | 112 | using algor_config_param_type = algor_config_param_human_gather; |
... | ... | @@ -365,6 +367,10 @@ void task_param_manager::delete_task_param(string task_id) { |
365 | 367 | } |
366 | 368 | break; |
367 | 369 | } |
370 | + | |
371 | + case algorithm_type_t::VEHICLE_GATHER: | |
372 | + case algorithm_type_t::HUMAN_REGION_GATHER: | |
373 | + case algorithm_type_t::HUMAN_DENSITY: | |
368 | 374 | case algorithm_type_t::HUMAN_GATHER: { |
369 | 375 | algor_config_param_human_gather *algor_param = |
370 | 376 | (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) { |
597 | 603 | if (algor_map == nullptr) |
598 | 604 | return false; |
599 | 605 | |
600 | - return (algor_map->find(algorithm_type_t::HUMAN_GATHER) != algor_map->end() || | |
606 | + return (algor_map->find(algorithm_type_t::HUMAN_GATHER) != algor_map->end() || | |
601 | 607 | algor_map->find(algorithm_type_t::HUMAN_SNAPSHOT) != algor_map->end() || |
608 | + algor_map->find(algorithm_type_t::VEHICLE_GATHER) != algor_map->end() || | |
602 | 609 | algor_map->find(algorithm_type_t::HUMAN_CROSSING_LINE) != algor_map->end() || |
610 | + algor_map->find(algorithm_type_t::HUMAN_DENSITY) != algor_map->end() || | |
603 | 611 | algor_map->find(algorithm_type_t::HUMAN_CLIMB) != algor_map->end() || |
604 | 612 | algor_map->find(algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE) != algor_map->end() || |
613 | + algor_map->find(algorithm_type_t::HUMAN_LINGER) != algor_map->end() || | |
614 | + algor_map->find(algorithm_type_t::VEHICLE_ILLEGAL_PARKING) != algor_map->end() || | |
615 | + algor_map->find(algorithm_type_t::HUMAN_REGION_GATHER) != algor_map->end() || | |
616 | + algor_map->find(algorithm_type_t::HUMAN_LEAVE_REGION) != algor_map->end() || | |
617 | + algor_map->find(algorithm_type_t::HUMAN_REGION_DISMISS) != algor_map->end() || | |
618 | + algor_map->find(algorithm_type_t::HUMAN_REGION_FAST_MOVING) != algor_map->end() || | |
605 | 619 | algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT) != algor_map->end() || |
606 | 620 | algor_map->find(algorithm_type_t::SMOKING_DET) != algor_map->end() || |
607 | 621 | algor_map->find(algorithm_type_t::NO_REFLECTIVE_CLOTHING) != algor_map->end() || | ... | ... |