Commit 35fac12dfb1a0106331be0990473ed6fd767adff
1 parent
a27a9f5b
添加人员徘徊和车辆违停
Showing
5 changed files
with
153 additions
and
11 deletions
src/ai_platform/MultiSourceProcess.cpp
... | ... | @@ -930,8 +930,11 @@ int CMultiSourceProcess::algorthim_vpt(vector<DeviceMemory*> vec_gpuMem){ |
930 | 930 | cross_line_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_CROSSING_LINE); |
931 | 931 | cross_line_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_CLIMB); |
932 | 932 | cross_line_process(vec_vptMem, vptResult, algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE); |
933 | + | |
934 | + wander_detect(vec_vptMem, vptResult, algorithm_type_t::HUMAN_LINGER); | |
935 | + wander_detect(vec_vptMem, vptResult, algorithm_type_t::VEHICLE_ILLEGAL_PARKING); | |
933 | 936 | // 轨迹记录 |
934 | - trace_record(vpt_interest_task_id, vptResult); | |
937 | + trace_record(vec_vptMem, vptResult); | |
935 | 938 | // 农村违法分析的快照缓存 |
936 | 939 | m_snapshot_reprocessing->update_village_bestsnapshot(vec_vptMem, vptResult, deleteObjectID); |
937 | 940 | // 三轮车载人 |
... | ... | @@ -1319,19 +1322,27 @@ void CMultiSourceProcess::algorthim_trespass(vector<string>& vpt_interest_task_i |
1319 | 1322 | } |
1320 | 1323 | |
1321 | 1324 | // 轨迹记录 |
1322 | -void CMultiSourceProcess::trace_record(vector<string>& vpt_interest_task_id, vector<onelevel_det_result>& vptResult) { | |
1323 | - int bidx = 0; | |
1324 | - for (auto iter = vpt_interest_task_id.begin(); iter != vpt_interest_task_id.end(); ++ iter, ++ bidx) { | |
1325 | - auto task_id = *iter; | |
1325 | +void CMultiSourceProcess::trace_record(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result>& vptResult) { | |
1326 | + | |
1327 | + for (size_t bidx = 0; bidx < vec_gpuMem.size(); bidx++){ | |
1328 | + DeviceMemory* gpuMem = vec_gpuMem[bidx]; | |
1329 | + string task_id = gpuMem->getId(); | |
1330 | + | |
1326 | 1331 | for (int c = 0; c < vptResult[bidx].obj_count; c++) { |
1327 | 1332 | //计算检测框坐标中心点 |
1328 | 1333 | sy_point center_point; |
1329 | 1334 | center_point.x_ = vptResult[bidx].obj[c].left + (vptResult[bidx].obj[c].right - vptResult[bidx].obj[c].left) * 0.5; |
1330 | 1335 | // center_point.y_ = vptResult[bidx].obj[c].top + (vptResult[bidx].obj[c].bottom - vptResult[bidx].obj[c].top) * 0.85; |
1331 | - center_point.y_ = vptResult[bidx].obj[c].bottom; | |
1336 | + center_point.y_ = vptResult[bidx].obj[c].bottom; // 越线检测以脚越线为标准 | |
1332 | 1337 | |
1333 | 1338 | OBJ_KEY new_obj = { task_id, vptResult[bidx].obj[c].id }; |
1334 | 1339 | m_TotalObjMtx.lock(); |
1340 | + auto it = m_total_obj_info.find(new_obj); | |
1341 | + if (it == m_total_obj_info.end()) | |
1342 | + { | |
1343 | + m_total_obj_info[new_obj].last_frame_nb = gpuMem->getFrameNb(); | |
1344 | + m_total_obj_info[new_obj].last_ts = gpuMem->getTimesstamp(); | |
1345 | + } | |
1335 | 1346 | m_total_obj_info[new_obj].index = vptResult[bidx].obj[c].index; |
1336 | 1347 | m_total_obj_info[new_obj].center_points.push_back(center_point); |
1337 | 1348 | m_TotalObjMtx.unlock(); |
... | ... | @@ -2244,6 +2255,98 @@ void CMultiSourceProcess::cross_line_process(vector<DeviceMemory*> vec_gpuMem, v |
2244 | 2255 | } |
2245 | 2256 | } |
2246 | 2257 | |
2258 | +void CMultiSourceProcess::wander_detect(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType) | |
2259 | +{ | |
2260 | + map<string, map<algo_type, task_param_manager::algo_param_type_t_*>> && algor_param = m_task_param_manager->get_task_other_params(); | |
2261 | + | |
2262 | + for (size_t i = 0; i < vec_gpuMem.size(); i++) | |
2263 | + { | |
2264 | + DeviceMemory* gpuMem = vec_gpuMem[i]; | |
2265 | + string task_id = gpuMem->getId(); | |
2266 | + long frame_nb = gpuMem->getFrameNb(); | |
2267 | + | |
2268 | + task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][eType]; | |
2269 | + if (!cur_task_params) | |
2270 | + { | |
2271 | + continue; | |
2272 | + } | |
2273 | + | |
2274 | + algor_config_param_behavior* algor_param = (algor_config_param_behavior*)cur_task_params->algor_param; | |
2275 | + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)cur_task_params->basic_param; | |
2276 | + | |
2277 | + long algor_skip_gap = algor_param->duration; | |
2278 | + | |
2279 | + std::string cur_src_ts = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>()); | |
2280 | + std::string origin_file_path = basic_param->result_folder + helpers::os::sep + task_id + "_origin_" + cur_src_ts + ".jpg"; | |
2281 | + | |
2282 | + std::vector<box_t> boxes; | |
2283 | + for (int c = 0; c < vptResult[i].obj_count; c++) { | |
2284 | + auto& obj_c = vptResult[i].obj[c]; | |
2285 | + | |
2286 | + bool bCount = false; | |
2287 | + if(eType == algorithm_type_t::HUMAN_LINGER && obj_c.index == (int)det_class_label_t::HUMAN) { | |
2288 | + bCount = true; | |
2289 | + } else if (eType == algorithm_type_t::VEHICLE_ILLEGAL_PARKING && obj_c.index >= 4 && obj_c.index <= 8) { | |
2290 | + bCount = true; | |
2291 | + } | |
2292 | + | |
2293 | + if (!bCount || !snapshot_legal_inarea(basic_param->algor_valid_rect, obj_c.left, obj_c.top, obj_c.right, obj_c.bottom)) | |
2294 | + { | |
2295 | + continue; | |
2296 | + } | |
2297 | + | |
2298 | + if (obj_c.confidence < algor_param->conf_threshold) | |
2299 | + { | |
2300 | + continue; | |
2301 | + } | |
2302 | + | |
2303 | + int obj_width = obj_c.right - obj_c.left; | |
2304 | + int obj_height = obj_c.right - obj_c.left; | |
2305 | + if (obj_width < algor_param->minmum_width || obj_height < algor_param->minmum_height) | |
2306 | + { | |
2307 | + continue; | |
2308 | + } | |
2309 | + | |
2310 | + OBJ_KEY o_key = { task_id, obj_c.id }; | |
2311 | + m_TotalObjMtx.lock(); | |
2312 | + auto it = m_total_obj_info.find(o_key); | |
2313 | + if (it != m_total_obj_info.end()) | |
2314 | + { | |
2315 | + long skip_gap = frame_nb - m_total_obj_info[o_key].last_frame_nb; | |
2316 | + if (skip_gap > algor_skip_gap) | |
2317 | + { | |
2318 | + box_t box; | |
2319 | + box.left = obj_c.left; | |
2320 | + box.right = obj_c.right; | |
2321 | + box.top = obj_c.top; | |
2322 | + box.bottom = obj_c.bottom; | |
2323 | + box.score = obj_c.confidence; | |
2324 | + boxes.push_back(box); | |
2325 | + | |
2326 | + m_total_obj_info[o_key].last_frame_nb = frame_nb; // 更新帧号以判断下一次逗留 | |
2327 | + } | |
2328 | + } | |
2329 | + | |
2330 | + m_TotalObjMtx.unlock(); | |
2331 | + } | |
2332 | + | |
2333 | + if (boxes.size() <= 0) | |
2334 | + { | |
2335 | + continue; | |
2336 | + } | |
2337 | + | |
2338 | + int algorithm_type = (int)eType; | |
2339 | + string json_str = helpers::gen_json::gen_boxes_json(task_id, algorithm_type, boxes, origin_file_path); | |
2340 | + | |
2341 | + ImgSaveInfo info_origin; | |
2342 | + info_origin.img_info = VPCUtil::vpc_devMem2vpcImg(gpuMem); | |
2343 | + info_origin.file_path = origin_file_path; | |
2344 | + info_origin.json_str = json_str; | |
2345 | + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(info_origin); | |
2346 | + } | |
2347 | + | |
2348 | +} | |
2349 | + | |
2247 | 2350 | void CMultiSourceProcess::face_locus_finished(const OBJ_KEY obj_key) { |
2248 | 2351 | map<OBJ_KEY, OBJ_VALUE> _total_face_snapshot_info = m_snapshot_reprocessing->get_total_face_snapshot_info(); |
2249 | 2352 | ... | ... |
src/ai_platform/MultiSourceProcess.h
... | ... | @@ -75,13 +75,12 @@ private: |
75 | 75 | // 逆行 |
76 | 76 | void algorthim_retrograde(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, vector<onelevel_det_result>& vptResult); |
77 | 77 | // 闯入 |
78 | - void algorthim_trespass(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | |
79 | - vector<onelevel_det_result>& vptResult ,vector<vector<int>>& deleteObjectID); | |
78 | + void algorthim_trespass(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, vector<onelevel_det_result>& vptResult ,vector<vector<int>>& deleteObjectID); | |
80 | 79 | |
81 | 80 | // 道路分割 |
82 | 81 | int algorthim_road_seg(vector<DeviceMemory*> vec_gpuMem); |
83 | 82 | // 轨迹记录 |
84 | - void trace_record(vector<string>& vpt_interest_task_id, vector<onelevel_det_result>& vptResult); | |
83 | + void trace_record(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result>& vptResult); | |
85 | 84 | // 三轮车载人 |
86 | 85 | void algorithm_tricycle_manned(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, vector<onelevel_det_result>& vptResult); |
87 | 86 | // 货车载人 |
... | ... | @@ -98,7 +97,6 @@ private: |
98 | 97 | void algorithm_traffic_light_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, vector<onelevel_det_result>& vptResult); |
99 | 98 | // 道路分割相关算法--占用机动车道等 |
100 | 99 | void algorithm_roadseg_correlation_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, vector<onelevel_det_result>& vptResult); |
101 | - | |
102 | 100 | |
103 | 101 | private: |
104 | 102 | // 工具处理函数 |
... | ... | @@ -124,6 +122,9 @@ private: |
124 | 122 | int snapshot_task(std::string& uri_or_name, const std::string& file_name, bool bInTask); |
125 | 123 | |
126 | 124 | void cross_line_process(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType); |
125 | + | |
126 | + void wander_detect(vector<DeviceMemory*>& vec_gpuMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType); | |
127 | + | |
127 | 128 | private: |
128 | 129 | int m_devId; |
129 | 130 | ... | ... |
src/ai_platform/det_obj_header.h
src/ai_platform/header.h
... | ... | @@ -34,6 +34,7 @@ enum class algorithm_type_t { |
34 | 34 | PEDESTRIAN_TRESPASS = 211, |
35 | 35 | ROAD_WORK_DET = 212, // 221026byzsh施工占道 |
36 | 36 | |
37 | + HUMAN_LINGER = 214, // 人员徘徊 | |
37 | 38 | HUMAN_CLIMB = 220, // 人员攀爬 |
38 | 39 | HUMAN_CROSSING_LINE = 221, // 人员越线 |
39 | 40 | |
... | ... | @@ -41,6 +42,7 @@ enum class algorithm_type_t { |
41 | 42 | VEHICLE_RETROGRADE = 310, |
42 | 43 | VEHICLE_TRESPASS = 311, |
43 | 44 | VEHICLE_GATHER = 312, // 车辆聚集 |
45 | + VEHICLE_ILLEGAL_PARKING = 313, // 车辆违停 | |
44 | 46 | VEHICLE_ILLEGAL_CROSSING_LINE = 314, // 车辆压线 |
45 | 47 | |
46 | 48 | NONMOTOR_VEHICLE_SNAPSHOT = 401, |
... | ... | @@ -393,7 +395,6 @@ typedef algor_config_param_pedestrian_safety_detector_basic algor_config_param_n |
393 | 395 | #endif // #ifndef ___PEDESTRIAN_SAFETY_DETECTOR_ALGOR_CONFIG_PARAM__ |
394 | 396 | |
395 | 397 | |
396 | - | |
397 | 398 | // 越线类 |
398 | 399 | typedef struct algor_config_param_illegal_crossing_line { |
399 | 400 | float conf_threshold{0.0}; // 目标检测阈值,小于该阈值不识别 |
... | ... | @@ -403,6 +404,17 @@ typedef struct algor_config_param_illegal_crossing_line { |
403 | 404 | } algor_config_param_illegal_crossing_line; // 车辆压线/人员越线/人员攀爬 共用 |
404 | 405 | |
405 | 406 | |
407 | +typedef struct algor_config_param_behavior { | |
408 | + float conf_threshold; // 目标检测阈值,小于该阈值不识别 | |
409 | + unsigned minmum_height, minmum_width; // 最小目标大小,小于该值不识别 | |
410 | + int duration; // 持续时长 | |
411 | + int moving_distance_threshold; // 像素变动距离阈值 | |
412 | + algor_config_param_behavior() | |
413 | + : duration(0), conf_threshold(0.0f), minmum_height(0), minmum_width(0), moving_distance_threshold(0) { | |
414 | + } | |
415 | +} algor_config_param_behavior; | |
416 | + | |
417 | + | |
406 | 418 | // 行人安全检测参数 |
407 | 419 | #ifndef ___RETROGRADE_ALGOR_CONFIG_PARAM__ |
408 | 420 | #define ___RETROGRADE_ALGOR_CONFIG_PARAM__ | ... | ... |
src/ai_platform/task_param_manager.cpp
... | ... | @@ -124,6 +124,16 @@ bool copy_algor_param_aux(const algorithm_type_t &algor_type, const std::string |
124 | 124 | *((algor_config_param_type *)algor_param); // deep copy. |
125 | 125 | } break; |
126 | 126 | |
127 | + case algorithm_type_t::HUMAN_LINGER: | |
128 | + case algorithm_type_t::VEHICLE_ILLEGAL_PARKING: | |
129 | + { | |
130 | + m_algor_config_params[task_id].human_algors.insert(algor_type); | |
131 | + using algor_config_param_type = algor_config_param_behavior; | |
132 | + copied_algor_param->algor_param = new algor_config_param_type; | |
133 | + *((algor_config_param_type *)(copied_algor_param->algor_param)) = | |
134 | + *((algor_config_param_type *)algor_param); // deep copy. | |
135 | + } break; | |
136 | + | |
127 | 137 | |
128 | 138 | //221026byzsh--------------------------------------------------------- |
129 | 139 | case algorithm_type_t::ROAD_WORK_DET: { |
... | ... | @@ -381,6 +391,20 @@ void task_param_manager::delete_task_param(string task_id) { |
381 | 391 | } |
382 | 392 | break; |
383 | 393 | } |
394 | + | |
395 | + case algorithm_type_t::HUMAN_LINGER: | |
396 | + case algorithm_type_t::VEHICLE_ILLEGAL_PARKING: | |
397 | + { | |
398 | + algor_config_param_behavior *algor_param = | |
399 | + (algor_config_param_behavior *)((algor_init_config_param_t *)m_task_params[task_id][iter.first]) | |
400 | + ->algor_param; | |
401 | + if (algor_param) { | |
402 | + delete (algor_config_param_behavior *)((algor_init_config_param_t *)m_task_params[task_id][iter.first]) | |
403 | + ->algor_param; | |
404 | + ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->algor_param = nullptr; | |
405 | + } | |
406 | + break; | |
407 | + } | |
384 | 408 | |
385 | 409 | //221026byzsh--------------------------------------------------------- |
386 | 410 | case algorithm_type_t::ROAD_WORK_DET: { | ... | ... |