Commit b17e0e6904f447786b42261fe27a03521160d681

Authored by Zhao Shuaihua
1 parent 7c962865

闯红灯增加场景自适应、轨迹约束;逆行过滤横向场景;代码同步

src/ai_engine_module/road_seg_correlation_algor.cpp
@@ -234,7 +234,8 @@ namespace ai_engine_module @@ -234,7 +234,8 @@ namespace ai_engine_module
234 int deg1 = atan2(car_toward.y, car_toward.x) * 180 / Pi; // 返回与x轴的夹角 234 int deg1 = atan2(car_toward.y, car_toward.x) * 180 / Pi; // 返回与x轴的夹角
235 int deg_std = atan2(std_toward.y, std_toward.x) * 180 / Pi; 235 int deg_std = atan2(std_toward.y, std_toward.x) * 180 / Pi;
236 int deg_diff = abs(deg1 - deg_std); 236 int deg_diff = abs(deg1 - deg_std);
237 - if (deg_diff < 135) { return false; } 237 + // if (deg_diff < 135) { return false; }
  238 + if (abs(deg_std) < 30 || abs(deg_std) > 150 || deg_diff < 135) return false; // 过滤横向绿化带
238 else { /*std::cout << flag1 << " " << flag2 << std::endl;*/ 239 else { /*std::cout << flag1 << " " << flag2 << std::endl;*/
239 return true; } 240 return true; }
240 } 241 }
src/ai_engine_module/traffic_light_process.cpp
@@ -5,9 +5,8 @@ @@ -5,9 +5,8 @@
5 #include "../common/logger.hpp" 5 #include "../common/logger.hpp"
6 #include "../ai_platform/mvpt_process_assist.h" 6 #include "../ai_platform/mvpt_process_assist.h"
7 7
8 -#if 0 8 +#if 1
9 #include "opencv2/opencv.hpp" 9 #include "opencv2/opencv.hpp"
10 -#include "opencv2/imgcodecs/legacy/constants_c.h"  
11 #endif 10 #endif
12 11
13 namespace ai_engine_module 12 namespace ai_engine_module
@@ -39,6 +38,7 @@ namespace ai_engine_module @@ -39,6 +38,7 @@ namespace ai_engine_module
39 38
40 bool is_valid_box(const int top, const int left, const int right, const int bottom, const float score, 39 bool is_valid_box(const int top, const int left, const int right, const int bottom, const float score,
41 const algorithm_type_t &algor_type, 40 const algorithm_type_t &algor_type,
  41 + const int src_img_w, const int src_img_h,
42 const task_param_manager::algo_param_type_t_ *params_ptr = nullptr) { 42 const task_param_manager::algo_param_type_t_ *params_ptr = nullptr) {
43 if (!params_ptr) 43 if (!params_ptr)
44 return false; 44 return false;
@@ -49,10 +49,10 @@ namespace ai_engine_module @@ -49,10 +49,10 @@ namespace ai_engine_module
49 if (params_ptr->algor_param == nullptr) 49 if (params_ptr->algor_param == nullptr)
50 return false; 50 return false;
51 51
52 -  
53 - const unsigned width = right - left;  
54 - const unsigned height = bottom - top;  
55 - 52 + float scale_w = src_img_w / 1920.0;
  53 + float scale_h = src_img_h / 1080.0;
  54 + const unsigned width = (right - left) / scale_w; //归一化为1080p下的宽高,用于大小过滤(尺寸阈值按1080p设置)
  55 + const unsigned height = (bottom - top) / scale_h;
56 if (width == 0 || height == 0) 56 if (width == 0 || height == 0)
57 return false; 57 return false;
58 58
@@ -126,6 +126,98 @@ namespace ai_engine_module @@ -126,6 +126,98 @@ namespace ai_engine_module
126 return (nCross % 2 == 1); 126 return (nCross % 2 == 1);
127 } 127 }
128 128
  129 + float contourArea(const vector<tr_point>& polygon, cv::Point2f* quad_point) {
  130 + std::vector<cv::Point> contour;
  131 + for (int i = 0; i < polygon.size(); ++i) {
  132 + cv::Point tmp_p; tmp_p.x = polygon[i].x; tmp_p.y = polygon[i].y;
  133 + contour.push_back(tmp_p);
  134 + }
  135 + cv::Point2f rect_point[4];
  136 + cv::RotatedRect rect = cv::minAreaRect(contour); // 最小外接矩形 rect[0]中心点 rect[1]宽 高 rect[2]旋转角度
  137 + rect.points(rect_point); // 求外接矩形顶点坐标,顺时针依次为box[0] box[1] box[2] box[3], -45 <= angle <= 0:box[0]在左下角; angle > 45:box[0]在右下角
  138 +
  139 + // 根据外接矩形求外接四边形(有可能求出三角形):取距矩形顶点近的4个点
  140 + for (int k = 0; k < 4; k ++) {
  141 + quad_point[k] = rect_point[k];
  142 + float sum_min_dist = 100000;
  143 + for (int j = 0; j < polygon.size(); ++j) {
  144 + float t_diff_x = polygon[j].x - rect_point[k].x, t_diff_y = polygon[j].y - rect_point[k].y;
  145 + float temp_dist = sqrt(t_diff_x * t_diff_x + t_diff_y * t_diff_y);
  146 + float temp_min_dist = temp_dist + 3*fabs(t_diff_y); //提高纵坐标的权重
  147 + if (temp_min_dist < sum_min_dist) {
  148 + quad_point[k].x = polygon[j].x; quad_point[k].y = polygon[j].y;
  149 + sum_min_dist = temp_min_dist;
  150 + }
  151 + }
  152 + }
  153 + return fabs(rect.angle);
  154 + }
  155 +
  156 + // 与0作比较,小于精度则认为是和0相等,返回0 1 -1
  157 + int cmpzero(double d) { return (fabs(d) < PRECISION)? 0: (d > 0? 1:-1); }
  158 +
  159 + // 向量叉积
  160 + double cross_det(double x1, double y1, double x2, double y2) { return x1*y2 - x2*y1; }
  161 +
  162 + // 判断是否在区域两侧
  163 + bool inBothSidesOfArea(tr_point curpos, cv::Point2f* boxPoints, float angle) {
  164 + // 根据叉积判断目标相对于区域边界的位置,大于0:左 小于0:右 等于0:共线 (左侧/右侧和向量起始方向有关,当前设定的起始方向是y小的那侧)
  165 + if (angle > 45) {
  166 + // 左边界
  167 + int l_flag = cmpzero(cross_det(boxPoints[1].x-boxPoints[2].x, boxPoints[1].y-boxPoints[2].y, curpos.x-boxPoints[2].x, curpos.y-boxPoints[2].y));
  168 + // 右边界
  169 + int r_flag = cmpzero(cross_det(boxPoints[0].x-boxPoints[3].x, boxPoints[0].y-boxPoints[3].y, curpos.x-boxPoints[0].x, curpos.y-boxPoints[3].y));
  170 + if (l_flag > 0 || r_flag < 0) return true;
  171 + }
  172 + else {
  173 + // 左边界
  174 + int l_flag = cmpzero(cross_det(boxPoints[0].x-boxPoints[1].x, boxPoints[0].y-boxPoints[1].y, curpos.x-boxPoints[1].x, curpos.y-boxPoints[1].y));
  175 + // 右边界
  176 + int r_flag = cmpzero(cross_det(boxPoints[3].x-boxPoints[2].x, boxPoints[3].y-boxPoints[2].y, curpos.x-boxPoints[2].x, curpos.y-boxPoints[2].y));
  177 + if (l_flag > 0 || r_flag < 0) return true;
  178 + }
  179 +
  180 + return false;
  181 + }
  182 +
  183 + // 判断目标是否在区域两侧且轨迹为南北走向
  184 + bool inBothSidesOfAreaV2(tr_point curpos, cv::Point2f* boxPoints, float angle, const vector<sy_point>& tracker_list, int check_frames) {
  185 + int trackcnt = tracker_list.size();
  186 + tr_point p_start, p_end;
  187 + p_start.x = tracker_list[trackcnt-check_frames-1].x_; p_start.y = tracker_list[trackcnt-check_frames-1].y_;
  188 + p_end.x = tracker_list[trackcnt-1].x_; p_end.y = tracker_list[trackcnt-1].y_;
  189 +
  190 + // 目标方向
  191 + tr_point obj_toward;
  192 + obj_toward.x = p_end.x - p_start.x;
  193 + obj_toward.y = p_end.y - p_start.y;
  194 +
  195 + // 根据叉积判断目标相对于区域边界的位置,大于0:左 小于0:右 等于0:共线 (左侧/右侧和向量起始方向有关,当前设定的起始方向是y小的那侧)
  196 + bool flag = false;
  197 + if (angle > 45) {
  198 + // 左边界
  199 + int l_flag = cmpzero(cross_det(boxPoints[1].x-boxPoints[2].x, boxPoints[1].y-boxPoints[2].y, curpos.x-boxPoints[2].x, curpos.y-boxPoints[2].y));
  200 + // 右边界
  201 + int r_flag = cmpzero(cross_det(boxPoints[0].x-boxPoints[3].x, boxPoints[0].y-boxPoints[3].y, curpos.x-boxPoints[0].x, curpos.y-boxPoints[3].y));
  202 + if (l_flag > 0 || r_flag < 0) flag = true;
  203 + }
  204 + else {
  205 + // 左边界
  206 + int l_flag = cmpzero(cross_det(boxPoints[0].x-boxPoints[1].x, boxPoints[0].y-boxPoints[1].y, curpos.x-boxPoints[1].x, curpos.y-boxPoints[1].y));
  207 + // 右边界
  208 + int r_flag = cmpzero(cross_det(boxPoints[3].x-boxPoints[2].x, boxPoints[3].y-boxPoints[2].y, curpos.x-boxPoints[2].x, curpos.y-boxPoints[2].y));
  209 + if (l_flag > 0 || r_flag < 0) flag = true;
  210 + }
  211 +
  212 + if (flag) {
  213 + int deg = atan2(obj_toward.y, obj_toward.x) * 180 / Pi; // 返回轨迹与x轴的夹角
  214 + if (abs(deg) < 30 || abs(deg) > 150) return false;
  215 + else return true;
  216 + }
  217 +
  218 + return false;
  219 + }
  220 +
129 #if 0 221 #if 0
130 void CvtYuvToBgr(sy_img src, sy_img dst) { 222 void CvtYuvToBgr(sy_img src, sy_img dst) {
131 const int uvStart = src.w_ * src.h_; 223 const int uvStart = src.w_ * src.h_;
@@ -239,7 +331,7 @@ namespace ai_engine_module @@ -239,7 +331,7 @@ namespace ai_engine_module
239 return res; 331 return res;
240 } 332 }
241 333
242 - bool TrafficLightProcess::update_mstreams(const std::vector<task_id_t>& taskIds, vector<sy_img> src_interest_imgs, vector<DeviceMemory*> vec_det_input_images, const std::vector<onelevel_det_result> &det_results) 334 + bool TrafficLightProcess::update_mstreams(const std::vector<task_id_t>& taskIds, vector<sy_img> src_interest_imgs, vector<DeviceMemory*> vec_det_input_images, const vector<vector<vector<int>>>& traffic_region, const vector<vector<int>>& labels, map<OBJ_KEY, OBJ_INDEX> &m_total_obj_info, const std::vector<onelevel_det_result> &det_results)
243 { 335 {
244 if (!check_initied()) 336 if (!check_initied())
245 return false; 337 return false;
@@ -275,6 +367,22 @@ namespace ai_engine_module @@ -275,6 +367,22 @@ namespace ai_engine_module
275 int src_img_w = src_img->getWidth(); 367 int src_img_w = src_img->getWidth();
276 int src_img_h = src_img->getHeight(); 368 int src_img_h = src_img->getHeight();
277 369
  370 + auto seg_regions = traffic_region[n];
  371 + auto seg_labels = labels[n];
  372 + vector<vector<int>> crosswalk_regions; //人行道区域
  373 + vector<vector<int>> interestion_regions; //十字路口区域
  374 + for (unsigned i = 0; i < seg_labels.size(); ++i) {
  375 + const seg_label_t seg_label = static_cast<seg_label_t>(seg_labels[i]);
  376 + if ((seg_label == seg_label_t::crosswalk)) {
  377 + vector<int> cur_region(seg_regions[i].begin(),seg_regions[i].end());
  378 + crosswalk_regions.push_back(cur_region);
  379 + }
  380 + if ((seg_label == seg_label_t::interestion_area)) {
  381 + vector<int> cur_region(seg_regions[i].begin(),seg_regions[i].end());
  382 + interestion_regions.push_back(cur_region);
  383 + }
  384 + }
  385 +
278 auto& boxes_of_one_image = det_results[n].obj; 386 auto& boxes_of_one_image = det_results[n].obj;
279 for (int i = 0; i < det_results[n].obj_count; ++i) 387 for (int i = 0; i < det_results[n].obj_count; ++i)
280 { 388 {
@@ -301,17 +409,43 @@ namespace ai_engine_module @@ -301,17 +409,43 @@ namespace ai_engine_module
301 continue; 409 continue;
302 } 410 }
303 411
304 - if (!is_valid_box(top, left, right, bottom, box.confidence, algor_type, algor_param_wrap)) 412 + if (!is_valid_box(top, left, right, bottom, box.confidence, algor_type, src_img_w, src_img_h, algor_param_wrap))
305 continue; 413 continue;
306 414
307 //DEBUG增加多边形区域选择及判断================================================================ 415 //DEBUG增加多边形区域选择及判断================================================================
308 tr_point curpos; 416 tr_point curpos;
309 curpos.x = (left + right) * 0.5; curpos.y = bottom; 417 curpos.x = (left + right) * 0.5; curpos.y = bottom;
  418 +#if 0
310 vector<int> args = {1552,435,1756,537,1915,537,1915,499,1725,435}; //区域(泰兴黄桥锦润福府路口) 419 vector<int> args = {1552,435,1756,537,1915,537,1915,499,1725,435}; //区域(泰兴黄桥锦润福府路口)
311 // vector<int> args = {0,0,0,1080,1920,1080,1920,0}; //区域 420 // vector<int> args = {0,0,0,1080,1920,1080,1920,0}; //区域
312 vector<tr_point> tr_boxes = Mbuild_area(args); 421 vector<tr_point> tr_boxes = Mbuild_area(args);
313 int cur_flag = McheckPointPolygon(tr_boxes, curpos); //cur_flag==true表示在区域内 422 int cur_flag = McheckPointPolygon(tr_boxes, curpos); //cur_flag==true表示在区域内
314 if (!cur_flag) continue; 423 if (!cur_flag) continue;
  424 +#else
  425 + // 目标在人行道区域且在十字路口区域的左侧或右侧---->只判南北向
  426 + int check_frames = 5; //1s 25
  427 + OBJ_KEY trace_obj_key = {taskId, box.id};
  428 + if (m_total_obj_info[trace_obj_key].center_points.size() < check_frames) continue; //忽略太短的轨迹
  429 + bool interestion_flag = false;
  430 + for (auto region : interestion_regions) {
  431 + vector<tr_point> tr_boxes = Mbuild_area(region);
  432 + vector<cv::Point> boxPoints;
  433 + cv::Point2f quad_point[4];
  434 + float angle = contourArea(tr_boxes, quad_point);
  435 + // interestion_flag = inBothSidesOfArea(curpos, quad_point, angle);
  436 + interestion_flag = inBothSidesOfAreaV2(curpos, quad_point, angle, m_total_obj_info[trace_obj_key].center_points, check_frames); //判断轨迹是否是南北向
  437 + if (interestion_flag) break;
  438 + }
  439 + if (!interestion_flag) continue;
  440 +
  441 + bool cur_flag = false;
  442 + for (auto region : crosswalk_regions) {
  443 + vector<tr_point> tr_boxes = Mbuild_area(region);
  444 + cur_flag = McheckPointPolygon(tr_boxes, curpos); //cur_flag==true表示在区域内
  445 + if (cur_flag) break;
  446 + }
  447 + if (!cur_flag) continue;
  448 +#endif
315 //DEBUG END================================================================================== 449 //DEBUG END==================================================================================
316 stream_idx_and_algor_seq.algors.emplace(algor_type); 450 stream_idx_and_algor_seq.algors.emplace(algor_type);
317 } 451 }
@@ -399,7 +533,7 @@ namespace ai_engine_module @@ -399,7 +533,7 @@ namespace ai_engine_module
399 const label_t label = static_cast<label_t>(box.index); 533 const label_t label = static_cast<label_t>(box.index);
400 if (!is_valid_label(label)) 534 if (!is_valid_label(label))
401 continue; 535 continue;
402 - if (box.left < 1200 || box.top < 159 || box.right > 1307 || box.bottom > 212) continue; // 限制红绿灯的出现位置(泰兴黄桥锦润福府路口) 536 + // if (box.left < 1200 || box.top < 159 || box.right > 1307 || box.bottom > 212) continue; // 限制红绿灯的出现位置(泰兴黄桥锦润福府路口)
403 LOG_TRACE("task id is {} obj_id {} label {} index {} score {}", task_id, objId, label, box.index, box.confidence); 537 LOG_TRACE("task id is {} obj_id {} label {} index {} score {}", task_id, objId, label, box.index, box.confidence);
404 red_cnt ++; 538 red_cnt ++;
405 } 539 }
src/ai_engine_module/traffic_light_process.h
@@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
15 #define IMAGE_CROP_EXPAND_RATIO 0 15 #define IMAGE_CROP_EXPAND_RATIO 0
16 #define MAX_OBJ_BOX_COUNT 100 16 #define MAX_OBJ_BOX_COUNT 100
17 #define MAX_LANE_NUM 100 17 #define MAX_LANE_NUM 100
  18 +#define PRECISION 1e-8
  19 +#define Pi 3.14159265358979
18 20
19 namespace ai_engine_module 21 namespace ai_engine_module
20 { 22 {
@@ -42,6 +44,22 @@ namespace ai_engine_module @@ -42,6 +44,22 @@ namespace ai_engine_module
42 no = 12, //灭灯 44 no = 12, //灭灯
43 }; 45 };
44 46
  47 + enum class seg_label_t {
  48 + PLACEHOLDER = -1,
  49 + background = 0, //背景
  50 + vehicle_lanes = 1, //机动车道
  51 + nonvehicle_lanes = 2, //非机动车道
  52 + emerg_lanes = 3, //应急车道
  53 + guide_line = 4, //导流线
  54 + crosswalk = 5, //人行横道
  55 + no_parking_area = 6, //禁停区域
  56 + interestion_area = 7, //十字路口区域
  57 + yellow_solidline = 8, //黄实线
  58 + white_solidline = 9, //白实线
  59 + white_dottedline = 10, //虚线
  60 + yellow_dottedline = 11, //黄虚线
  61 + };
  62 +
45 typedef struct input_data_wrap_t 63 typedef struct input_data_wrap_t
46 { 64 {
47 id_t id; 65 id_t id;
@@ -99,7 +117,8 @@ namespace ai_engine_module @@ -99,7 +117,8 @@ namespace ai_engine_module
99 117
100 bool check_initied(); 118 bool check_initied();
101 bool init(int gpu_id, string models_dir); 119 bool init(int gpu_id, string models_dir);
102 - bool update_mstreams(const std::vector<task_id_t>& taskIds, vector<sy_img> src_interest_imgs, vector<DeviceMemory*> vec_det_input_images, const std::vector<onelevel_det_result> &det_results); 120 + // bool update_mstreams(const std::vector<task_id_t>& taskIds, vector<sy_img> src_interest_imgs, vector<DeviceMemory*> vec_det_input_images, const std::vector<onelevel_det_result> &det_results);
  121 + bool update_mstreams(const std::vector<task_id_t>& taskIds, vector<sy_img> src_interest_imgs, vector<DeviceMemory*> vec_det_input_images, const vector<vector<vector<int>>>& traffic_region, const vector<vector<int>>& labels, map<OBJ_KEY, OBJ_INDEX> &m_total_obj_info, const std::vector<onelevel_det_result> &det_results);
103 std::shared_ptr<results_data_t> get_result_by_objectid(const id_t& id, bool do_erase = true); 122 std::shared_ptr<results_data_t> get_result_by_objectid(const id_t& id, bool do_erase = true);
104 123
105 void force_release_result(const task_id_t& task_id); 124 void force_release_result(const task_id_t& task_id);
src/ai_platform/MultiSourceProcess.cpp
@@ -462,7 +462,7 @@ bool CMultiSourceProcess::AddTask(task_param _cur_task_param){ @@ -462,7 +462,7 @@ bool CMultiSourceProcess::AddTask(task_param _cur_task_param){
462 // if(algor_face != algor_map->end()){ 462 // if(algor_face != algor_map->end()){
463 // const algor_basic_config_param_t *cur_param = ((algor_init_config_param_t *)(algor_face->second))->basic_param; 463 // const algor_basic_config_param_t *cur_param = ((algor_init_config_param_t *)(algor_face->second))->basic_param;
464 // LOG_INFO("face_snapshot, result_folder: {} result_folder_little: {}", cur_param->result_folder, cur_param->result_folder_little); 464 // LOG_INFO("face_snapshot, result_folder: {} result_folder_little: {}", cur_param->result_folder, cur_param->result_folder_little);
465 - // } 465 + // }
466 } 466 }
467 467
468 LOG_INFO("started task {} successed!", config.name); 468 LOG_INFO("started task {} successed!", config.name);
@@ -470,6 +470,11 @@ bool CMultiSourceProcess::AddTask(task_param _cur_task_param){ @@ -470,6 +470,11 @@ bool CMultiSourceProcess::AddTask(task_param _cur_task_param){
470 return true; 470 return true;
471 } 471 }
472 472
  473 +int CMultiSourceProcess::CountRunningTask() {
  474 + DecoderManager* pDecManager = DecoderManager::getInstance();
  475 + return pDecManager->count();
  476 +}
  477 +
473 bool CMultiSourceProcess::task_has_vpt_algor(const std::string &task_id){ 478 bool CMultiSourceProcess::task_has_vpt_algor(const std::string &task_id){
474 //! TODO: create enum iterator. 479 //! TODO: create enum iterator.
475 auto algor_map = m_task_param_manager->get_task_other_param(task_id); 480 auto algor_map = m_task_param_manager->get_task_other_param(task_id);
@@ -684,6 +689,11 @@ void CMultiSourceProcess::CloseAllTask(){ @@ -684,6 +689,11 @@ void CMultiSourceProcess::CloseAllTask(){
684 LOG_INFO("CloseAllTask exit."); 689 LOG_INFO("CloseAllTask exit.");
685 } 690 }
686 691
  692 +void CMultiSourceProcess::CloseAllTask2() {
  693 + DecoderManager* pDecManager = DecoderManager::getInstance();
  694 + pDecManager->closeAllDecoder();
  695 +}
  696 +
687 void CMultiSourceProcess::clear_finished_task(){// 清理已经结束的任务 697 void CMultiSourceProcess::clear_finished_task(){// 清理已经结束的任务
688 698
689 std::lock_guard<std::mutex> l1(m_FinishedTaskMtx); 699 std::lock_guard<std::mutex> l1(m_FinishedTaskMtx);
@@ -720,6 +730,12 @@ bool CMultiSourceProcess::finish_task(const string taskID, const bool delete_sna @@ -720,6 +730,12 @@ bool CMultiSourceProcess::finish_task(const string taskID, const bool delete_sna
720 // 任务结束,关闭跟踪 730 // 任务结束,关闭跟踪
721 if (!vpt_process.finishTaskTracker(taskID)) 731 if (!vpt_process.finishTaskTracker(taskID))
722 LOG_ERROR("Finish VPT Tracker failed, task_id: {}", taskID); 732 LOG_ERROR("Finish VPT Tracker failed, task_id: {}", taskID);
  733 +
  734 +#ifdef WITH_FACE_DET_SS
  735 + // 人脸任务结束
  736 + if (task_has_face_algor(taskID))
  737 + m_face_det_ai_engine.finish_task(taskID);
  738 +#endif
723 739
724 #ifdef POST_USE_RABBITMQ 740 #ifdef POST_USE_RABBITMQ
725 { 741 {
@@ -897,7 +913,7 @@ int CMultiSourceProcess::algorthim_process_thread(){ @@ -897,7 +913,7 @@ int CMultiSourceProcess::algorthim_process_thread(){
897 } 913 }
898 914
899 aclrtDestroyContext(ctx); 915 aclrtDestroyContext(ctx);
900 - 916 + aclrtResetDevice(m_devId);
901 LOG_INFO("algorthim_process_thread exit."); 917 LOG_INFO("algorthim_process_thread exit.");
902 918
903 return 0; 919 return 0;
@@ -1595,6 +1611,8 @@ void CMultiSourceProcess::algorithm_traffic_light_process(vector&lt;string&gt;&amp; vpt_in @@ -1595,6 +1611,8 @@ void CMultiSourceProcess::algorithm_traffic_light_process(vector&lt;string&gt;&amp; vpt_in
1595 vector<onelevel_det_result> interest_vpt_result; 1611 vector<onelevel_det_result> interest_vpt_result;
1596 vector<DeviceMemory*> interest_imgs; 1612 vector<DeviceMemory*> interest_imgs;
1597 vector<sy_img> sy_interest_imgs; 1613 vector<sy_img> sy_interest_imgs;
  1614 + vector<vector<vector<int>>> interest_traffic_region;
  1615 + vector<vector<int>> interest_labels;
1598 1616
1599 int _idx = 0; 1617 int _idx = 0;
1600 for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); 1618 for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end();
@@ -1605,6 +1623,15 @@ void CMultiSourceProcess::algorithm_traffic_light_process(vector&lt;string&gt;&amp; vpt_in @@ -1605,6 +1623,15 @@ void CMultiSourceProcess::algorithm_traffic_light_process(vector&lt;string&gt;&amp; vpt_in
1605 1623
1606 if (algor_map->find(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) != algor_map->end() || 1624 if (algor_map->find(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) != algor_map->end() ||
1607 algor_map->find(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) != algor_map->end()) { 1625 algor_map->find(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) != algor_map->end()) {
  1626 +
  1627 + m_RoadSegTaskMtx.lock();
  1628 + if (!m_RoadSegTaskMap[task_id].isseg) continue;
  1629 + else {
  1630 + interest_traffic_region.push_back(m_RoadSegTaskMap[task_id].traffic_region);
  1631 + interest_labels.push_back(m_RoadSegTaskMap[task_id].labels);
  1632 + }
  1633 + m_RoadSegTaskMtx.unlock();
  1634 +
1608 DeviceMemory* mem = vpt_interest_imgs[_idx]; 1635 DeviceMemory* mem = vpt_interest_imgs[_idx];
1609 sy_img img; 1636 sy_img img;
1610 img.w_ = mem->getWidth(); img.h_ = mem->getHeight(); 1637 img.w_ = mem->getWidth(); img.h_ = mem->getHeight();
@@ -1618,7 +1645,9 @@ void CMultiSourceProcess::algorithm_traffic_light_process(vector&lt;string&gt;&amp; vpt_in @@ -1618,7 +1645,9 @@ void CMultiSourceProcess::algorithm_traffic_light_process(vector&lt;string&gt;&amp; vpt_in
1618 } 1645 }
1619 1646
1620 if (!interest_imgs.empty()){ 1647 if (!interest_imgs.empty()){
1621 - traffic_lightprocess_.update_mstreams(interest_task_id, sy_interest_imgs, interest_imgs, interest_vpt_result); 1648 + m_TotalObjMtx.lock();
  1649 + traffic_lightprocess_.update_mstreams(interest_task_id, sy_interest_imgs, interest_imgs, interest_traffic_region, interest_labels, m_total_obj_info, interest_vpt_result);
  1650 + m_TotalObjMtx.unlock();
1622 } 1651 }
1623 } 1652 }
1624 1653
@@ -2274,4 +2303,4 @@ bool CMultiSourceProcess::CheckTime() { @@ -2274,4 +2303,4 @@ bool CMultiSourceProcess::CheckTime() {
2274 { 2303 {
2275 return false; 2304 return false;
2276 } 2305 }
2277 -} 2306 -}
  2307 +}
2278 \ No newline at end of file 2308 \ No newline at end of file
src/ai_platform/MultiSourceProcess.h
@@ -46,6 +46,9 @@ public: @@ -46,6 +46,9 @@ public:
46 bool FinishTask(const string taskID); 46 bool FinishTask(const string taskID);
47 void CloseAllTask(); 47 void CloseAllTask();
48 int SnapShot(task_param param); 48 int SnapShot(task_param param);
  49 + int CountRunningTask();
  50 +
  51 + void CloseAllTask2();
49 52
50 #ifdef POST_USE_RABBITMQ 53 #ifdef POST_USE_RABBITMQ
51 int AddMqConn(mq_type_t mq_type, rabbitmq_conn_params_t mq_conn_param); 54 int AddMqConn(mq_type_t mq_type, rabbitmq_conn_params_t mq_conn_param);
src/ai_platform/stl_aiplatform.cpp
@@ -95,6 +95,17 @@ int tsl_aiplatform_release(void **handle) @@ -95,6 +95,17 @@ int tsl_aiplatform_release(void **handle)
95 return SUCCESS; 95 return SUCCESS;
96 } 96 }
97 97
  98 +int count_running_task(void *handle)
  99 +{
  100 + CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
  101 + return tools->CountRunningTask();
  102 +}
  103 +
  104 +void close_all_task(void *handle)
  105 +{
  106 + CMultiSourceProcess* tools = (CMultiSourceProcess*)handle;
  107 + tools->CloseAllTask2();
  108 +}
98 109
99 const char* get_tsl_aiplatform_version() 110 const char* get_tsl_aiplatform_version()
100 { 111 {
src/ai_platform/stl_aiplatform.h
@@ -120,6 +120,11 @@ extern &quot;C&quot; @@ -120,6 +120,11 @@ extern &quot;C&quot;
120 TSL_AIPLATFORM_API int tsl_aiplatform_release(void **handle); 120 TSL_AIPLATFORM_API int tsl_aiplatform_release(void **handle);
121 121
122 122
  123 + TSL_AIPLATFORM_API int count_running_task(void *handle);
  124 +
  125 + TSL_AIPLATFORM_API void close_all_task(void *handle);
  126 +
  127 +
123 /************************************************************************* 128 /*************************************************************************
124 * FUNCTION: get_tsl_aiplatform_version 129 * FUNCTION: get_tsl_aiplatform_version
125 * PURPOSE: 获取SDK版本号 130 * PURPOSE: 获取SDK版本号
@@ -129,4 +134,4 @@ extern &quot;C&quot; @@ -129,4 +134,4 @@ extern &quot;C&quot;
129 *************************************************************************/ 134 *************************************************************************/
130 TSL_AIPLATFORM_API const char* get_tsl_aiplatform_version(); 135 TSL_AIPLATFORM_API const char* get_tsl_aiplatform_version();
131 } 136 }
132 -#endif 137 -#endif
  138 +#endif
133 \ No newline at end of file 139 \ No newline at end of file
src/decoder/dvpp/DvppDataMemory.hpp
@@ -25,7 +25,7 @@ public: @@ -25,7 +25,7 @@ public:
25 25
26 ~DvppDataMemory(){ 26 ~DvppDataMemory(){
27 if (pHwRgb) { 27 if (pHwRgb) {
28 - int ret = acldvppFree((uint8_t*)pHwRgb); 28 + int ret = acldvppFree(pHwRgb);
29 if(ret != ACL_ERROR_NONE){ 29 if(ret != ACL_ERROR_NONE){
30 cout << "acldvppFree failed" << endl; 30 cout << "acldvppFree failed" << endl;
31 } 31 }
src/decoder/dvpp/DvppDecoder.cpp
@@ -335,6 +335,7 @@ void DvppDecoder::read_thread() { @@ -335,6 +335,7 @@ void DvppDecoder::read_thread() {
335 int frame_count = 0; 335 int frame_count = 0;
336 int ret = -1; 336 int ret = -1;
337 337
  338 + m_bExitDecodeThd = false;
338 pthread_t m_decode_thread; 339 pthread_t m_decode_thread;
339 pthread_create(&m_decode_thread,0, 340 pthread_create(&m_decode_thread,0,
340 [](void* arg) 341 [](void* arg)
@@ -429,8 +430,11 @@ void DvppDecoder::read_thread() { @@ -429,8 +430,11 @@ void DvppDecoder::read_thread() {
429 } 430 }
430 } 431 }
431 432
432 - m_bRunning=false; 433 + while(m_bRunning && m_pktQueue.size() > 0) {
  434 + std::this_thread::sleep_for(std::chrono::milliseconds(5));
  435 + }
433 436
  437 + m_bExitDecodeThd = true;
434 if(m_decode_thread != 0){ 438 if(m_decode_thread != 0){
435 pthread_join(m_decode_thread,0); 439 pthread_join(m_decode_thread,0);
436 } 440 }
@@ -444,6 +448,8 @@ void DvppDecoder::read_thread() { @@ -444,6 +448,8 @@ void DvppDecoder::read_thread() {
444 } 448 }
445 m_pktQueue_mutex.unlock(); 449 m_pktQueue_mutex.unlock();
446 450
  451 + m_bRunning=false;
  452 +
447 if(decode_finished_cbk) { 453 if(decode_finished_cbk) {
448 decode_finished_cbk(m_finishedDecArg); 454 decode_finished_cbk(m_finishedDecArg);
449 } 455 }
@@ -618,6 +624,7 @@ void DvppDecoder::decode_thread(){ @@ -618,6 +624,7 @@ void DvppDecoder::decode_thread(){
618 return; 624 return;
619 } 625 }
620 626
  627 + m_bExitDisplayThd = false;
621 pthread_t display_thread; 628 pthread_t display_thread;
622 pthread_create(&display_thread,0, 629 pthread_create(&display_thread,0,
623 [](void* arg) 630 [](void* arg)
@@ -655,7 +662,7 @@ void DvppDecoder::decode_thread(){ @@ -655,7 +662,7 @@ void DvppDecoder::decode_thread(){
655 662
656 uint64_t frame_count = 0; 663 uint64_t frame_count = 0;
657 bool bBreak = false; 664 bool bBreak = false;
658 - while (m_bRunning) { 665 + while (!m_bExitDecodeThd) {
659 if (m_bPause){ 666 if (m_bPause){
660 std::this_thread::sleep_for(std::chrono::milliseconds(3)); 667 std::this_thread::sleep_for(std::chrono::milliseconds(3));
661 continue; 668 continue;
@@ -694,18 +701,26 @@ void DvppDecoder::decode_thread(){ @@ -694,18 +701,26 @@ void DvppDecoder::decode_thread(){
694 701
695 CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed"); 702 CHECK_NOT_RETURN(aclvdecDestroyChannel(vdecChannelDesc), "aclvdecDestroyChannel failed");
696 }while(0); 703 }while(0);
697 -  
698 - CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed");  
699 704
  705 + // 退出 report thread
  706 + while(m_bRunning && m_vdecQueue.size() > 0) {
  707 + std::this_thread::sleep_for(std::chrono::milliseconds(5));
  708 + }
  709 + CHECK_NOT_RETURN(aclvdecDestroyChannelDesc(vdecChannelDesc), "aclvdecDestroyChannelDesc failed");
700 // report_thread 需后于destroy退出 710 // report_thread 需后于destroy退出
701 - m_bRunning = false;  
702 m_bExitReportThd = true; 711 m_bExitReportThd = true;
703 - CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "pthread_join failed");  
704 - CHECK_NOT_RETURN(pthread_join(display_thread, nullptr), "pthread_join failed"); 712 + CHECK_NOT_RETURN(pthread_join(report_thread, nullptr), "report_thread join failed");
  713 +
  714 + // 退出 display thread
  715 + while(m_bRunning && m_decoded_data_queue.size() > 0) {
  716 + std::this_thread::sleep_for(std::chrono::milliseconds(5));
  717 + }
  718 + m_bExitDisplayThd = true;
  719 + CHECK_NOT_RETURN(pthread_join(display_thread, nullptr), "display_thread join failed");
705 720
706 // 最后清理一遍未解码的数据 721 // 最后清理一遍未解码的数据
707 m_vdecQueue_mutex.lock(); 722 m_vdecQueue_mutex.lock();
708 - if(m_vdecQueue.size() > 0){ 723 + while(m_vdecQueue.size() > 0){
709 void* inputData = m_vdecQueue.front(); 724 void* inputData = m_vdecQueue.front();
710 acldvppFree(inputData); 725 acldvppFree(inputData);
711 inputData = nullptr; 726 inputData = nullptr;
@@ -872,7 +887,7 @@ bool DvppDecoder::sendVdecEos(aclvdecChannelDesc *vdecChannelDesc) { @@ -872,7 +887,7 @@ bool DvppDecoder::sendVdecEos(aclvdecChannelDesc *vdecChannelDesc) {
872 887
873 void DvppDecoder::display_thread(){ 888 void DvppDecoder::display_thread(){
874 LOG_INFO("[{}]- display_thread start...", m_dec_name); 889 LOG_INFO("[{}]- display_thread start...", m_dec_name);
875 - while(m_bRunning) { 890 + while(!m_bExitDisplayThd) {
876 m_decoded_data_queue_mtx.lock(); 891 m_decoded_data_queue_mtx.lock();
877 if(m_decoded_data_queue.size() <= 0) { 892 if(m_decoded_data_queue.size() <= 0) {
878 m_decoded_data_queue_mtx.unlock(); 893 m_decoded_data_queue_mtx.unlock();
@@ -898,7 +913,7 @@ void DvppDecoder::display_thread(){ @@ -898,7 +913,7 @@ void DvppDecoder::display_thread(){
898 mem = nullptr; 913 mem = nullptr;
899 } 914 }
900 915
901 - LOG_INFO("[{}]- display_thread end.", m_dec_name); 916 + LOG_INFO("[{}]- display_thread exit.", m_dec_name);
902 } 917 }
903 918
904 void DvppDecoder::release_dvpp(){ 919 void DvppDecoder::release_dvpp(){
src/decoder/dvpp/DvppDecoder.h
@@ -83,7 +83,10 @@ private: @@ -83,7 +83,10 @@ private:
83 bool m_bFinished{false}; 83 bool m_bFinished{false};
84 bool m_bRunning{false}; 84 bool m_bRunning{false};
85 bool m_bPause{false}; 85 bool m_bPause{false};
  86 +
86 bool m_bExitReportThd{false}; 87 bool m_bExitReportThd{false};
  88 + bool m_bExitDisplayThd{false};
  89 + bool m_bExitDecodeThd{false};
87 90
88 // 读取数据 91 // 读取数据
89 AVStream* stream{nullptr}; 92 AVStream* stream{nullptr};
src/decoder/dvpp/FFRecoderTaskManager.cpp
@@ -92,8 +92,6 @@ void FFRecoderTaskManager::cache_pkt(AVPacket* pkt, long long frame_nb){ @@ -92,8 +92,6 @@ void FFRecoderTaskManager::cache_pkt(AVPacket* pkt, long long frame_nb){
92 newDataPkt->pkt = new_pkt; 92 newDataPkt->pkt = new_pkt;
93 newDataPkt->frame_nb = frame_nb; 93 newDataPkt->frame_nb = frame_nb;
94 94
95 - m_pkt_list.emplace_back(newDataPkt);  
96 -  
97 if(is_key_frame(pkt)){ 95 if(is_key_frame(pkt)){
98 // 越来越大的值 96 // 越来越大的值
99 newDataPkt->isKeyFrame = true; 97 newDataPkt->isKeyFrame = true;
@@ -102,6 +100,8 @@ void FFRecoderTaskManager::cache_pkt(AVPacket* pkt, long long frame_nb){ @@ -102,6 +100,8 @@ void FFRecoderTaskManager::cache_pkt(AVPacket* pkt, long long frame_nb){
102 newDataPkt->isKeyFrame = false; 100 newDataPkt->isKeyFrame = false;
103 } 101 }
104 102
  103 + m_pkt_list.emplace_back(newDataPkt);
  104 +
105 std::lock_guard<std::mutex> l_info(m_recoderinfo_list_mtx); 105 std::lock_guard<std::mutex> l_info(m_recoderinfo_list_mtx);
106 if(m_recoderinfo_list.size() <= 0){ 106 if(m_recoderinfo_list.size() <= 0){
107 // 没有任务的时候,维持500的长度 107 // 没有任务的时候,维持500的长度
src/demo/demo.cpp
@@ -1105,11 +1105,11 @@ void test_gpu(int gpuID){ @@ -1105,11 +1105,11 @@ void test_gpu(int gpuID){
1105 // createTask(handle, algor_vec, 1); 1105 // createTask(handle, algor_vec, 1);
1106 // createTask(handle, algor_vec, 2); 1106 // createTask(handle, algor_vec, 2);
1107 // createTask(handle, algor_vec, 3); 1107 // createTask(handle, algor_vec, 3);
1108 - createTask(handle, algor_vec3, 4);  
1109 - createTask(handle, algor_vec3, 5);  
1110 - createTask(handle, algor_vec3, 6);  
1111 - createTask(handle, algor_vec3, 7);  
1112 - createTask(handle, algor_vec3, 8); 1108 + // createTask(handle, algor_vec3, 4);
  1109 + // createTask(handle, algor_vec3, 5);
  1110 + // createTask(handle, algor_vec3, 6);
  1111 + // createTask(handle, algor_vec3, 7);
  1112 + // createTask(handle, algor_vec3, 8);
1113 // createTask(handle, algor_vec3, 9); 1113 // createTask(handle, algor_vec3, 9);
1114 // createTask(handle, algor_vec3, 10); 1114 // createTask(handle, algor_vec3, 10);
1115 // createTask(handle, algor_vec3, 11); 1115 // createTask(handle, algor_vec3, 11);
@@ -1129,12 +1129,46 @@ void test_gpu(int gpuID){ @@ -1129,12 +1129,46 @@ void test_gpu(int gpuID){
1129 1129
1130 /* 1130 /*
1131 1131
  1132 + createTask(handle, algor_vec, 0, false);
  1133 + createTask(handle, algor_vec, 0, false);
  1134 + createTask(handle, algor_vec, 0, false);
  1135 + createTask(handle, algor_vec, 0, false);
  1136 + createTask(handle, algor_vec, 0, false);
  1137 + createTask(handle, algor_vec, 0, false);
  1138 + createTask(handle, algor_vec, 2, false);
  1139 + createTask(handle, algor_vec, 2, false);
  1140 + createTask(handle, algor_vec, 2, false);
  1141 + createTask(handle, algor_vec, 2, false);
  1142 + createTask(handle, algor_vec, 2, false);
  1143 + createTask(handle, algor_vec, 2, false);
  1144 +
  1145 +/*
1132 // test_snapshot(handle); 1146 // test_snapshot(handle);
1133 sleep(60); //60s 1147 sleep(60); //60s
1134 finish_task(handle, (char*)task_id2.data(), 0); 1148 finish_task(handle, (char*)task_id2.data(), 0);
1135 finish_task(handle, (char*)task_id1.data(), 0); 1149 finish_task(handle, (char*)task_id1.data(), 0);
1136 }*/ 1150 }*/
1137 - while (getchar() != 'q'); 1151 +
  1152 + char ch = 'a';
  1153 + while (ch != 'q') {
  1154 + ch = getchar();
  1155 + switch (ch)
  1156 + {
  1157 + case 'a':
  1158 + createTask(handle, algor_vec3, 4, false);
  1159 + createTask(handle, algor_vec3, 5, false);
  1160 + createTask(handle, algor_vec3, 6, false);
  1161 + createTask(handle, algor_vec3, 7, false);
  1162 + createTask(handle, algor_vec3, 8, false);
  1163 + break;
  1164 + case 'c':
  1165 + close_all_task(handle);
  1166 + break;
  1167 + default:
  1168 + break;
  1169 + }
  1170 +
  1171 + }
1138 1172
1139 // finish_task(handle, (char*)task_id.data(), 0); 1173 // finish_task(handle, (char*)task_id.data(), 0);
1140 1174
@@ -1167,4 +1201,4 @@ int main(int argc, char *argv[]) { @@ -1167,4 +1201,4 @@ int main(int argc, char *argv[]) {
1167 printf("Done.\n"); 1201 printf("Done.\n");
1168 1202
1169 return 0; 1203 return 0;
1170 -} 1204 -}
  1205 +}
1171 \ No newline at end of file 1206 \ No newline at end of file