Commit 39b31e88274544bc016a51b96030cb5a9f56246d

Authored by Hu Chunming
1 parent d2ab26d1

添加人员攀爬、人员越线、车辆压线

src/ai_platform/MultiSourceProcess.cpp
@@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
13 #include "../helpers/os_helper.hpp" 13 #include "../helpers/os_helper.hpp"
14 #include "../helpers/gen_json.hpp" 14 #include "../helpers/gen_json.hpp"
15 #include "../helpers/str_helper.hpp" 15 #include "../helpers/str_helper.hpp"
  16 +#include "../helpers/common_tool.h"
16 #include "../reprocessing_module/save_snapshot_reprocessing.h" 17 #include "../reprocessing_module/save_snapshot_reprocessing.h"
17 18
18 #include "macro_definition.h" 19 #include "macro_definition.h"
@@ -765,9 +766,7 @@ int CMultiSourceProcess::algorthim_process_thread(){ @@ -765,9 +766,7 @@ int CMultiSourceProcess::algorthim_process_thread(){
765 } 766 }
766 } 767 }
767 } 768 }
768 -  
769 769
770 -  
771 } 770 }
772 771
773 m_RgbDataList.pop_front(); 772 m_RgbDataList.pop_front();
@@ -890,26 +889,29 @@ int CMultiSourceProcess::algorthim_vpt(vector<DeviceMemory*> vec_gpuMem){ @@ -890,26 +889,29 @@ int CMultiSourceProcess::algorthim_vpt(vector<DeviceMemory*> vec_gpuMem){
890 } 889 }
891 890
892 /* 待检测的图片不为空 开始检测 */ 891 /* 待检测的图片不为空 开始检测 */
893 - if (!vpt_interest_imgs.empty()) {  
894 - vector<vector<int>> deleteObjectID;  
895 - deleteObjectID.resize(vpt_interest_task_id.size());  
896 - vector<vector<onelevel_det_result>> unUsedResult;  
897 - vector<onelevel_det_result> vptResult(0); 892 + if (vpt_interest_imgs.empty()) {
  893 + return 1;
  894 + }
  895 +
  896 + vector<vector<int>> deleteObjectID;
  897 + deleteObjectID.resize(vpt_interest_task_id.size());
  898 + vector<vector<onelevel_det_result>> unUsedResult;
  899 + vector<onelevel_det_result> vptResult(0);
898 900
899 - /* 一级检测器,内部已完成跟踪操作 */  
900 - vpt_process.process_gpu(vpt_interest_imgs.data(), vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // do det & track.  
901 - // vpt_process.process_gpu(vpt_interest_imgs.data(), vec_vptMem, vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // debug  
902 - m_snapshot_reprocessing->screen_effective_snapshot(vptResult); 901 + /* 一级检测器,内部已完成跟踪操作 */
  902 + vpt_process.process_gpu(vpt_interest_imgs.data(), vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // do det & track.
  903 + // vpt_process.process_gpu(vpt_interest_imgs.data(), vec_vptMem, vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // debug
  904 + m_snapshot_reprocessing->screen_effective_snapshot(vptResult);
903 905
904 #ifndef VEHICLE_MULTI_BOXES 906 #ifndef VEHICLE_MULTI_BOXES
905 - /* 快照优选(内部可实现不同的快照优选策略) */  
906 - m_snapshot_reprocessing->update_bestsnapshot(vec_vptMem, vptResult, deleteObjectID);  
907 - /* for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径)*/  
908 - vehicle_snapshot(vpt_interest_task_id, deleteObjectID); 907 + /* 快照优选(内部可实现不同的快照优选策略) */
  908 + m_snapshot_reprocessing->update_bestsnapshot(vec_vptMem, vptResult, deleteObjectID);
  909 + /* for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径)*/
  910 + vehicle_snapshot(vpt_interest_task_id, deleteObjectID);
909 #else 911 #else
910 - algorithm_vehicle_relult(vec_vptMem, vptResult, deleteObjectID); 912 + algorithm_vehicle_relult(vec_vptMem, vptResult, deleteObjectID);
911 913
912 - send_locus_finished_msg(vpt_interest_task_id, deleteObjectID); 914 + send_locus_finished_msg(vpt_interest_task_id, deleteObjectID);
913 #endif 915 #endif
914 916
915 // #ifdef WITH_SECOND_PROCESS 917 // #ifdef WITH_SECOND_PROCESS
@@ -925,6 +927,9 @@ int CMultiSourceProcess::algorthim_vpt(vector&lt;DeviceMemory*&gt; vec_gpuMem){ @@ -925,6 +927,9 @@ int CMultiSourceProcess::algorthim_vpt(vector&lt;DeviceMemory*&gt; vec_gpuMem){
925 927
926 // #endif 928 // #endif
927 #ifdef USE_VILLAGE 929 #ifdef USE_VILLAGE
  930 + cross_line_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_CROSSING_LINE);
  931 + cross_line_process(vec_vptMem, vptResult, algorithm_type_t::HUMAN_CLIMB);
  932 + cross_line_process(vec_vptMem, vptResult, algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE);
928 // 轨迹记录 933 // 轨迹记录
929 trace_record(vpt_interest_task_id, vptResult); 934 trace_record(vpt_interest_task_id, vptResult);
930 // 农村违法分析的快照缓存 935 // 农村违法分析的快照缓存
@@ -948,14 +953,13 @@ int CMultiSourceProcess::algorthim_vpt(vector&lt;DeviceMemory*&gt; vec_gpuMem){ @@ -948,14 +953,13 @@ int CMultiSourceProcess::algorthim_vpt(vector&lt;DeviceMemory*&gt; vec_gpuMem){
948 village_snapshot(vpt_interest_task_id, vec_vptMem, deleteObjectID); 953 village_snapshot(vpt_interest_task_id, vec_vptMem, deleteObjectID);
949 #endif 954 #endif
950 955
951 - vptResult.clear();  
952 - unUsedResult.clear();  
953 - // deleteObjectID.clear();  
954 - for (int i = 0; i < deleteObjectID.size(); i++) {  
955 - vector<int>().swap(deleteObjectID[i]); // free.  
956 - }  
957 - vector<vector<int>>().swap(deleteObjectID); // free. 956 + vptResult.clear();
  957 + unUsedResult.clear();
  958 + // deleteObjectID.clear();
  959 + for (int i = 0; i < deleteObjectID.size(); i++) {
  960 + vector<int>().swap(deleteObjectID[i]); // free.
958 } 961 }
  962 + vector<vector<int>>().swap(deleteObjectID); // free.
959 963
960 vec_vptMem.clear(); 964 vec_vptMem.clear();
961 vpt_interest_task_id.clear(); 965 vpt_interest_task_id.clear();
@@ -1331,7 +1335,6 @@ void CMultiSourceProcess::trace_record(vector&lt;string&gt;&amp; vpt_interest_task_id, vec @@ -1331,7 +1335,6 @@ void CMultiSourceProcess::trace_record(vector&lt;string&gt;&amp; vpt_interest_task_id, vec
1331 m_total_obj_info[new_obj].index = vptResult[bidx].obj[c].index; 1335 m_total_obj_info[new_obj].index = vptResult[bidx].obj[c].index;
1332 m_total_obj_info[new_obj].center_points.push_back(center_point); 1336 m_total_obj_info[new_obj].center_points.push_back(center_point);
1333 m_TotalObjMtx.unlock(); 1337 m_TotalObjMtx.unlock();
1334 -  
1335 } 1338 }
1336 } 1339 }
1337 } 1340 }
@@ -2141,6 +2144,106 @@ void CMultiSourceProcess::algorthim_face_detect(vector&lt;DeviceMemory*&gt; vec_gpuMem @@ -2141,6 +2144,106 @@ void CMultiSourceProcess::algorthim_face_detect(vector&lt;DeviceMemory*&gt; vec_gpuMem
2141 } 2144 }
2142 } 2145 }
2143 2146
  2147 +void CMultiSourceProcess::cross_line_process(vector<DeviceMemory*> vec_gpuMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType)
  2148 +{
  2149 + map<string, map<algo_type, task_param_manager::algo_param_type_t_*>> && algor_param = m_task_param_manager->get_task_other_params();
  2150 +
  2151 + for (int bidx = 0; bidx < vec_gpuMem.size(); ++ bidx) {
  2152 +
  2153 + DeviceMemory* gpuMem = vec_gpuMem[bidx];
  2154 + string task_id = gpuMem->getId();
  2155 +
  2156 + task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][eType];
  2157 + if (!cur_task_params)
  2158 + {
  2159 + continue;
  2160 + }
  2161 +
  2162 + bool b_src_saved = false;
  2163 +
  2164 + algor_config_param_illegal_crossing_line* algor_param = (algor_config_param_illegal_crossing_line*)cur_task_params->algor_param;
  2165 + algor_basic_config_param_t* basic_param = (algor_basic_config_param_t*)cur_task_params->basic_param;
  2166 + jxline std_line(algor_param->p1.x_, algor_param->p1.y_, algor_param->p2.x_, algor_param->p2.y_);
  2167 +
  2168 + std::string cur_src_ts = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>());
  2169 + std::string origin_file_path = basic_param->result_folder + helpers::os::sep + task_id + "_origin_" + cur_src_ts + ".jpg";
  2170 +
  2171 + std::vector<box_t> boxes;
  2172 + for (int c = 0; c < vptResult[bidx].obj_count; c++) {
  2173 + auto& obj_c = vptResult[bidx].obj[c];
  2174 +
  2175 + bool bHuman = eType == algorithm_type_t::HUMAN_CROSSING_LINE || eType == algorithm_type_t::HUMAN_CLIMB;
  2176 +
  2177 + bool bCount = false;
  2178 + if(bHuman && obj_c.index == (int)det_class_label_t::HUMAN) {
  2179 + bCount = true;
  2180 + } else if (eType == algorithm_type_t::VEHICLE_ILLEGAL_CROSSING_LINE && obj_c.index >= 4 && obj_c.index <= 8) {
  2181 + bCount = true;
  2182 + }
  2183 +
  2184 + if (!bCount || !snapshot_legal_inarea(basic_param->algor_valid_rect, obj_c.left, obj_c.top, obj_c.right, obj_c.bottom))
  2185 + {
  2186 + continue;
  2187 + }
  2188 +
  2189 + if (obj_c.confidence < algor_param->conf_threshold)
  2190 + {
  2191 + continue;
  2192 + }
  2193 +
  2194 + int obj_width = obj_c.right - obj_c.left;
  2195 + int obj_height = obj_c.right - obj_c.left;
  2196 + if (obj_width < algor_param->minmum_width || obj_height < algor_param->minmum_height)
  2197 + {
  2198 + continue;
  2199 + }
  2200 +
  2201 + //计算检测框坐标中心点
  2202 + sy_point center_point;
  2203 + center_point.x_ = obj_c.left + (obj_c.right - obj_c.left) * 0.5;
  2204 + center_point.y_ = obj_c.bottom;
  2205 +
  2206 + m_TotalObjMtx.lock();
  2207 +
  2208 + OBJ_KEY obj_key = { task_id, obj_c.id };
  2209 + auto it = m_total_obj_info.find(obj_key);
  2210 + if (it != m_total_obj_info.end())
  2211 + {
  2212 + vector<sy_point> center_points = m_total_obj_info[obj_key].center_points;
  2213 + sy_point last_pt = center_points[center_points.size() - 1];
  2214 + // 计算越线
  2215 + jxline cur_line(last_pt.x_, last_pt.y_, center_point.x_, center_point.y_);
  2216 + bool bflag = common::is_intersect(cur_line, std_line);
  2217 + if (bflag)
  2218 + {
  2219 + box_t box;
  2220 + box.left = obj_c.left;
  2221 + box.right = obj_c.right;
  2222 + box.top = obj_c.top;
  2223 + box.bottom = obj_c.bottom;
  2224 + box.score = obj_c.confidence;
  2225 + boxes.push_back(box);
  2226 + }
  2227 + }
  2228 + m_TotalObjMtx.unlock();
  2229 + }
  2230 +
  2231 + if (boxes.size() <= 0)
  2232 + {
  2233 + continue;
  2234 + }
  2235 +
  2236 + int algorithm_type = (int)eType;
  2237 + string json_str = helpers::gen_json::gen_boxes_json(task_id, algorithm_type, boxes, origin_file_path);
  2238 +
  2239 + ImgSaveInfo info_origin;
  2240 + info_origin.img_info = VPCUtil::vpc_devMem2vpcImg(gpuMem);
  2241 + info_origin.file_path = origin_file_path;
  2242 + info_origin.json_str = json_str;
  2243 + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(info_origin);
  2244 + }
  2245 +}
  2246 +
2144 void CMultiSourceProcess::face_locus_finished(const OBJ_KEY obj_key) { 2247 void CMultiSourceProcess::face_locus_finished(const OBJ_KEY obj_key) {
2145 map<OBJ_KEY, OBJ_VALUE> _total_face_snapshot_info = m_snapshot_reprocessing->get_total_face_snapshot_info(); 2248 map<OBJ_KEY, OBJ_VALUE> _total_face_snapshot_info = m_snapshot_reprocessing->get_total_face_snapshot_info();
2146 2249
src/ai_platform/MultiSourceProcess.h
@@ -122,6 +122,8 @@ private: @@ -122,6 +122,8 @@ private:
122 void face_locus_finished(const OBJ_KEY obj_key); 122 void face_locus_finished(const OBJ_KEY obj_key);
123 123
124 int snapshot_task(std::string& uri_or_name, const std::string& file_name, bool bInTask); 124 int snapshot_task(std::string& uri_or_name, const std::string& file_name, bool bInTask);
  125 +
  126 + void cross_line_process(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& vptResult, algorithm_type_t eType);
125 private: 127 private:
126 int m_devId; 128 int m_devId;
127 129
src/ai_platform/header.h
@@ -34,10 +34,14 @@ enum class algorithm_type_t { @@ -34,10 +34,14 @@ enum class algorithm_type_t {
34 PEDESTRIAN_TRESPASS = 211, 34 PEDESTRIAN_TRESPASS = 211,
35 ROAD_WORK_DET = 212, // 221026byzsh施工占道 35 ROAD_WORK_DET = 212, // 221026byzsh施工占道
36 36
  37 + HUMAN_CLIMB = 220, // 人员攀爬
  38 + HUMAN_CROSSING_LINE = 221, // 人员越线
  39 +
37 VEHICLE_SNAPSHOT = 301, 40 VEHICLE_SNAPSHOT = 301,
38 VEHICLE_RETROGRADE = 310, 41 VEHICLE_RETROGRADE = 310,
39 VEHICLE_TRESPASS = 311, 42 VEHICLE_TRESPASS = 311,
40 VEHICLE_GATHER = 312, // 车辆聚集 43 VEHICLE_GATHER = 312, // 车辆聚集
  44 + VEHICLE_ILLEGAL_CROSSING_LINE = 314, // 车辆压线
41 45
42 NONMOTOR_VEHICLE_SNAPSHOT = 401, 46 NONMOTOR_VEHICLE_SNAPSHOT = 401,
43 TAKEAWAY_MEMBER_CLASSIFICATION = 402, 47 TAKEAWAY_MEMBER_CLASSIFICATION = 402,
@@ -390,6 +394,15 @@ typedef algor_config_param_pedestrian_safety_detector_basic algor_config_param_n @@ -390,6 +394,15 @@ typedef algor_config_param_pedestrian_safety_detector_basic algor_config_param_n
390 394
391 395
392 396
  397 +// 越线类
  398 +typedef struct algor_config_param_illegal_crossing_line {
  399 + float conf_threshold{0.0}; // 目标检测阈值,小于该阈值不识别
  400 + unsigned minmum_height, minmum_width; // 最小目标大小,小于该值不识别
  401 + sy_point p1; // 线段起点
  402 + sy_point p2; // 线段终点
  403 +} algor_config_param_illegal_crossing_line; // 车辆压线/人员越线/人员攀爬 共用
  404 +
  405 +
393 // 行人安全检测参数 406 // 行人安全检测参数
394 #ifndef ___RETROGRADE_ALGOR_CONFIG_PARAM__ 407 #ifndef ___RETROGRADE_ALGOR_CONFIG_PARAM__
395 #define ___RETROGRADE_ALGOR_CONFIG_PARAM__ 408 #define ___RETROGRADE_ALGOR_CONFIG_PARAM__
src/helpers/common_tool.cpp 0 → 100644
  1 +#include "common_tool.h"
  2 +
  3 +
  4 +namespace common {
  5 +
  6 + bool is_intersect(jxline myline1, jxline myline2)
  7 + {
  8 + // 快速排斥实验
  9 + if (myline1.get_max_x() < myline2.get_min_x() ||
  10 + myline2.get_max_x() < myline1.get_min_x() ||
  11 + myline1.get_max_y() < myline2.get_min_y() ||
  12 + myline2.get_max_y() < myline1.get_min_y())
  13 + return false;
  14 +
  15 + // 跨立实验(叉积异号)
  16 + 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))*
  17 + (((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 ||
  18 + ((((float)myline2.xa - (float)myline1.xa)*((float)myline1.yb - (float)myline1.ya) - ((float)myline2.ya - (float)myline1.ya)*((float)myline1.xb - (float)myline1.xa))*
  19 + (((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)
  20 + return false;
  21 +
  22 + return true;
  23 + }
  24 +}
src/helpers/common_tool.h 0 → 100644
  1 +#ifndef __COMMON_TOOL_H__
  2 +#define __COMMON_TOOL_H__
  3 +
  4 +
  5 +struct jxline
  6 +{
  7 + int xa;
  8 + int ya;
  9 + int xb;
  10 + int yb;
  11 +
  12 + jxline() {}
  13 + jxline(int xa, int ya, int xb, int yb)
  14 + {
  15 + this->xa = xa;
  16 + this->ya = ya;
  17 + this->xb = xb;
  18 + this->yb = yb;
  19 + }
  20 + int get_max_x()
  21 + {
  22 + return xa > xb ? xa : xb;
  23 + }
  24 + int get_min_x()
  25 + {
  26 + return xa > xb ? xb : xa;
  27 + }
  28 + int get_max_y()
  29 + {
  30 + return ya > yb ? ya : yb;
  31 + }
  32 + int get_min_y()
  33 + {
  34 + return ya > yb ? yb : ya;
  35 + }
  36 +};
  37 +
  38 +namespace common {
  39 + bool is_intersect(jxline myline1, jxline myline2);
  40 +}
  41 +
  42 +
  43 +#endif
0 \ No newline at end of file 44 \ No newline at end of file
src/reprocessing_module/save_snapshot_reprocessing.cpp
@@ -24,7 +24,11 @@ save_snapshot_reprocessing::save_snapshot_reprocessing(int devId) { @@ -24,7 +24,11 @@ save_snapshot_reprocessing::save_snapshot_reprocessing(int devId) {
24 #endif 24 #endif
25 25
26 bFinish = false; 26 bFinish = false;
27 - m_save_img_thread = std::thread(save_img_thread_process, this); 27 +
  28 + for (size_t i = 0; i < SAVE_THREAD_COUNT; i++)
  29 + {
  30 + m_save_img_thread[i] = std::thread(save_img_thread_process, this);
  31 + }
28 32
29 m_devId = devId; 33 m_devId = devId;
30 jpegUtil.jpeg_init(m_devId); 34 jpegUtil.jpeg_init(m_devId);
@@ -33,7 +37,10 @@ save_snapshot_reprocessing::save_snapshot_reprocessing(int devId) { @@ -33,7 +37,10 @@ save_snapshot_reprocessing::save_snapshot_reprocessing(int devId) {
33 save_snapshot_reprocessing::~save_snapshot_reprocessing(){ 37 save_snapshot_reprocessing::~save_snapshot_reprocessing(){
34 // 结束线程 38 // 结束线程
35 bFinish = true; 39 bFinish = true;
36 - m_save_img_thread.join(); 40 + for (size_t i = 0; i < SAVE_THREAD_COUNT; i++)
  41 + {
  42 + m_save_img_thread[i].join();
  43 + }
37 jpegUtil.jpeg_release(); 44 jpegUtil.jpeg_release();
38 } 45 }
39 46
src/reprocessing_module/save_snapshot_reprocessing.h
@@ -25,6 +25,8 @@ @@ -25,6 +25,8 @@
25 25
26 using namespace std; 26 using namespace std;
27 27
  28 +#define SAVE_THREAD_COUNT 32
  29 +
28 class DeviceMemory; 30 class DeviceMemory;
29 31
30 struct ImgSaveInfo{ 32 struct ImgSaveInfo{
@@ -55,7 +57,7 @@ private: @@ -55,7 +57,7 @@ private:
55 57
56 queue<ImgSaveInfo> waitforsave_img_queue; 58 queue<ImgSaveInfo> waitforsave_img_queue;
57 mutable std::mutex waitforsave_img_queue_mutex; 59 mutable std::mutex waitforsave_img_queue_mutex;
58 - std::thread m_save_img_thread; 60 + std::thread m_save_img_thread[SAVE_THREAD_COUNT];
59 61
60 bool bFinish = false; 62 bool bFinish = false;
61 int m_devId; 63 int m_devId;