diff --git a/src/ai_platform/MultiSourceProcess.cpp b/src/ai_platform/MultiSourceProcess.cpp index 43a58fc..86e534e 100755 --- a/src/ai_platform/MultiSourceProcess.cpp +++ b/src/ai_platform/MultiSourceProcess.cpp @@ -13,6 +13,7 @@ #include "../helpers/os_helper.hpp" #include "../helpers/gen_json.hpp" #include "../helpers/str_helper.hpp" +#include "../helpers/common_tool.h" #include "../reprocessing_module/save_snapshot_reprocessing.h" #include "macro_definition.h" @@ -765,9 +766,7 @@ int CMultiSourceProcess::algorthim_process_thread(){ } } } - - } m_RgbDataList.pop_front(); @@ -890,26 +889,29 @@ int CMultiSourceProcess::algorthim_vpt(vector vec_gpuMem){ } /* 待检测的图片不为空 开始检测 */ - if (!vpt_interest_imgs.empty()) { - vector> deleteObjectID; - deleteObjectID.resize(vpt_interest_task_id.size()); - vector> unUsedResult; - vector vptResult(0); + if (vpt_interest_imgs.empty()) { + return 1; + } + + vector> deleteObjectID; + deleteObjectID.resize(vpt_interest_task_id.size()); + vector> unUsedResult; + vector vptResult(0); - /* 一级检测器,内部已完成跟踪操作 */ - 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); + /* 一级检测器,内部已完成跟踪操作 */ + 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); #ifndef VEHICLE_MULTI_BOXES - /* 快照优选(内部可实现不同的快照优选策略) */ - m_snapshot_reprocessing->update_bestsnapshot(vec_vptMem, vptResult, deleteObjectID); - /* for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径)*/ - vehicle_snapshot(vpt_interest_task_id, deleteObjectID); + /* 快照优选(内部可实现不同的快照优选策略) */ + m_snapshot_reprocessing->update_bestsnapshot(vec_vptMem, vptResult, deleteObjectID); + /* for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径)*/ + vehicle_snapshot(vpt_interest_task_id, deleteObjectID); #else - algorithm_vehicle_relult(vec_vptMem, vptResult, deleteObjectID); + algorithm_vehicle_relult(vec_vptMem, vptResult, deleteObjectID); - send_locus_finished_msg(vpt_interest_task_id, deleteObjectID); + send_locus_finished_msg(vpt_interest_task_id, deleteObjectID); #endif // #ifdef WITH_SECOND_PROCESS @@ -925,6 +927,9 @@ int CMultiSourceProcess::algorthim_vpt(vector vec_gpuMem){ // #endif #ifdef USE_VILLAGE + cross_line_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_CROSSING_LINE); + cross_line_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_CLIMB); + cross_line_process(vec_vptMem, vptResult, algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE); // 轨迹记录 trace_record(vpt_interest_task_id, vptResult); // 农村违法分析的快照缓存 @@ -948,14 +953,13 @@ int CMultiSourceProcess::algorthim_vpt(vector vec_gpuMem){ village_snapshot(vpt_interest_task_id, vec_vptMem, deleteObjectID); #endif - vptResult.clear(); - unUsedResult.clear(); - // deleteObjectID.clear(); - for (int i = 0; i < deleteObjectID.size(); i++) { - vector().swap(deleteObjectID[i]); // free. - } - vector>().swap(deleteObjectID); // free. + vptResult.clear(); + unUsedResult.clear(); + // deleteObjectID.clear(); + for (int i = 0; i < deleteObjectID.size(); i++) { + vector().swap(deleteObjectID[i]); // free. } + vector>().swap(deleteObjectID); // free. vec_vptMem.clear(); vpt_interest_task_id.clear(); @@ -1331,7 +1335,6 @@ void CMultiSourceProcess::trace_record(vector& vpt_interest_task_id, vec m_total_obj_info[new_obj].index = vptResult[bidx].obj[c].index; m_total_obj_info[new_obj].center_points.push_back(center_point); m_TotalObjMtx.unlock(); - } } } @@ -2141,6 +2144,106 @@ void CMultiSourceProcess::algorthim_face_detect(vector vec_gpuMem } } +void CMultiSourceProcess::cross_line_process(vector vec_gpuMem, vector& vptResult, algorithm_type_t eType) +{ + map> && algor_param = m_task_param_manager->get_task_other_params(); + + for (int bidx = 0; bidx < vec_gpuMem.size(); ++ bidx) { + + DeviceMemory* gpuMem = vec_gpuMem[bidx]; + string task_id = gpuMem->getId(); + + task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][eType]; + if (!cur_task_params) + { + continue; + } + + bool b_src_saved = false; + + algor_config_param_illegal_crossing_line* algor_param = (algor_config_param_illegal_crossing_line*)cur_task_params->algor_param; + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)cur_task_params->basic_param; + jxline std_line(algor_param->p1.x_, algor_param->p1.y_, algor_param->p2.x_, algor_param->p2.y_); + + std::string cur_src_ts = std::to_string(helpers::timer::get_timestamp()); + std::string origin_file_path = basic_param->result_folder + helpers::os::sep + task_id + "_origin_" + cur_src_ts + ".jpg"; + + std::vector boxes; + for (int c = 0; c < vptResult[bidx].obj_count; c++) { + auto& obj_c = vptResult[bidx].obj[c]; + + bool bHuman = eType == algorithm_type_t::HUMAN_CROSSING_LINE || eType == algorithm_type_t::HUMAN_CLIMB; + + bool bCount = false; + if(bHuman && obj_c.index == (int)det_class_label_t::HUMAN) { + bCount = true; + } else if (eType == algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE && obj_c.index >= 4 && obj_c.index <= 8) { + bCount = true; + } + + if (!bCount || !snapshot_legal_inarea(basic_param->algor_valid_rect, obj_c.left, obj_c.top, obj_c.right, obj_c.bottom)) + { + continue; + } + + if (obj_c.confidence < algor_param->conf_threshold) + { + continue; + } + + int obj_width = obj_c.right - obj_c.left; + int obj_height = obj_c.right - obj_c.left; + if (obj_width < algor_param->minmum_width || obj_height < algor_param->minmum_height) + { + continue; + } + + //计算检测框坐标中心点 + sy_point center_point; + center_point.x_ = obj_c.left + (obj_c.right - obj_c.left) * 0.5; + center_point.y_ = obj_c.bottom; + + m_TotalObjMtx.lock(); + + OBJ_KEY obj_key = { task_id, obj_c.id }; + auto it = m_total_obj_info.find(obj_key); + if (it != m_total_obj_info.end()) + { + vector center_points = m_total_obj_info[obj_key].center_points; + sy_point last_pt = center_points[center_points.size() - 1]; + // 计算越线 + jxline cur_line(last_pt.x_, last_pt.y_, center_point.x_, center_point.y_); + bool bflag = common::is_intersect(cur_line, std_line); + if (bflag) + { + box_t box; + box.left = obj_c.left; + box.right = obj_c.right; + box.top = obj_c.top; + box.bottom = obj_c.bottom; + box.score = obj_c.confidence; + boxes.push_back(box); + } + } + m_TotalObjMtx.unlock(); + } + + if (boxes.size() <= 0) + { + continue; + } + + int algorithm_type = (int)eType; + string json_str = helpers::gen_json::gen_boxes_json(task_id, algorithm_type, boxes, origin_file_path); + + ImgSaveInfo info_origin; + info_origin.img_info = VPCUtil::vpc_devMem2vpcImg(gpuMem); + info_origin.file_path = origin_file_path; + info_origin.json_str = json_str; + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(info_origin); + } +} + 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 3b4c94e..cdf9c3a 100755 --- a/src/ai_platform/MultiSourceProcess.h +++ b/src/ai_platform/MultiSourceProcess.h @@ -122,6 +122,8 @@ private: void face_locus_finished(const OBJ_KEY obj_key); int snapshot_task(std::string& uri_or_name, const std::string& file_name, bool bInTask); + + void cross_line_process(vector vec_devMem, vector& vptResult, algorithm_type_t eType); private: int m_devId; diff --git a/src/ai_platform/header.h b/src/ai_platform/header.h index 4c36b6b..ce53874 100755 --- a/src/ai_platform/header.h +++ b/src/ai_platform/header.h @@ -34,10 +34,14 @@ enum class algorithm_type_t { PEDESTRIAN_TRESPASS = 211, ROAD_WORK_DET = 212, // 221026byzsh施工占道 + HUMAN_CLIMB = 220, // 人员攀爬 + HUMAN_CROSSING_LINE = 221, // 人员越线 + VEHICLE_SNAPSHOT = 301, VEHICLE_RETROGRADE = 310, VEHICLE_TRESPASS = 311, VEHICLE_GATHER = 312, // 车辆聚集 + VEHICLE_ILLEGAL_CROSSING_LINE = 314, // 车辆压线 NONMOTOR_VEHICLE_SNAPSHOT = 401, TAKEAWAY_MEMBER_CLASSIFICATION = 402, @@ -390,6 +394,15 @@ typedef algor_config_param_pedestrian_safety_detector_basic algor_config_param_n +// 越线类 +typedef struct algor_config_param_illegal_crossing_line { + float conf_threshold{0.0}; // 目标检测阈值,小于该阈值不识别 + unsigned minmum_height, minmum_width; // 最小目标大小,小于该值不识别 + sy_point p1; // 线段起点 + sy_point p2; // 线段终点 +} algor_config_param_illegal_crossing_line; // 车辆压线/人员越线/人员攀爬 共用 + + // 行人安全检测参数 #ifndef ___RETROGRADE_ALGOR_CONFIG_PARAM__ #define ___RETROGRADE_ALGOR_CONFIG_PARAM__ diff --git a/src/helpers/common_tool.cpp b/src/helpers/common_tool.cpp new file mode 100644 index 0000000..a73b21d --- /dev/null +++ b/src/helpers/common_tool.cpp @@ -0,0 +1,24 @@ +#include "common_tool.h" + + +namespace common { + + bool is_intersect(jxline myline1, jxline myline2) + { + // 快速排斥实验 + if (myline1.get_max_x() < myline2.get_min_x() || + myline2.get_max_x() < myline1.get_min_x() || + myline1.get_max_y() < myline2.get_min_y() || + myline2.get_max_y() < myline1.get_min_y()) + return false; + + // 跨立实验(叉积异号) + if (((((float)myline1.xa - (float)myline2.xa)*((float)myline2.yb - (float)myline2.ya) - ((float)myline1.ya - (float)myline2.ya)*((float)myline2.xb - (float)myline2.xa))* + (((float)myline1.xb - (float)myline2.xa)*((float)myline2.yb - (float)myline2.ya) - ((float)myline1.yb - (float)myline2.ya)*((float)myline2.xb - (float)myline2.xa))) > 0 || + ((((float)myline2.xa - (float)myline1.xa)*((float)myline1.yb - (float)myline1.ya) - ((float)myline2.ya - (float)myline1.ya)*((float)myline1.xb - (float)myline1.xa))* + (((float)myline2.xb - (float)myline1.xa)*((float)myline1.yb - (float)myline1.ya) - ((float)myline2.yb - (float)myline1.ya)*((float)myline1.xb - (float)myline1.xa))) > 0) + return false; + + return true; + } +} diff --git a/src/helpers/common_tool.h b/src/helpers/common_tool.h new file mode 100644 index 0000000..16ae420 --- /dev/null +++ b/src/helpers/common_tool.h @@ -0,0 +1,43 @@ +#ifndef __COMMON_TOOL_H__ +#define __COMMON_TOOL_H__ + + +struct jxline +{ + int xa; + int ya; + int xb; + int yb; + + jxline() {} + jxline(int xa, int ya, int xb, int yb) + { + this->xa = xa; + this->ya = ya; + this->xb = xb; + this->yb = yb; + } + int get_max_x() + { + return xa > xb ? xa : xb; + } + int get_min_x() + { + return xa > xb ? xb : xa; + } + int get_max_y() + { + return ya > yb ? ya : yb; + } + int get_min_y() + { + return ya > yb ? yb : ya; + } +}; + +namespace common { + bool is_intersect(jxline myline1, jxline myline2); +} + + +#endif \ No newline at end of file diff --git a/src/reprocessing_module/save_snapshot_reprocessing.cpp b/src/reprocessing_module/save_snapshot_reprocessing.cpp index b783c52..a8236d2 100755 --- a/src/reprocessing_module/save_snapshot_reprocessing.cpp +++ b/src/reprocessing_module/save_snapshot_reprocessing.cpp @@ -24,7 +24,11 @@ save_snapshot_reprocessing::save_snapshot_reprocessing(int devId) { #endif bFinish = false; - m_save_img_thread = std::thread(save_img_thread_process, this); + + for (size_t i = 0; i < SAVE_THREAD_COUNT; i++) + { + m_save_img_thread[i] = std::thread(save_img_thread_process, this); + } m_devId = devId; jpegUtil.jpeg_init(m_devId); @@ -33,7 +37,10 @@ save_snapshot_reprocessing::save_snapshot_reprocessing(int devId) { save_snapshot_reprocessing::~save_snapshot_reprocessing(){ // 结束线程 bFinish = true; - m_save_img_thread.join(); + for (size_t i = 0; i < SAVE_THREAD_COUNT; i++) + { + m_save_img_thread[i].join(); + } jpegUtil.jpeg_release(); } diff --git a/src/reprocessing_module/save_snapshot_reprocessing.h b/src/reprocessing_module/save_snapshot_reprocessing.h index 7ddebc2..f19a64a 100755 --- a/src/reprocessing_module/save_snapshot_reprocessing.h +++ b/src/reprocessing_module/save_snapshot_reprocessing.h @@ -25,6 +25,8 @@ using namespace std; +#define SAVE_THREAD_COUNT 32 + class DeviceMemory; struct ImgSaveInfo{ @@ -55,7 +57,7 @@ private: queue waitforsave_img_queue; mutable std::mutex waitforsave_img_queue_mutex; - std::thread m_save_img_thread; + std::thread m_save_img_thread[SAVE_THREAD_COUNT]; bool bFinish = false; int m_devId;