Commit 83f4facfb2f8b0767d740687bd436ccb15bcb79c

Authored by Zhao Shuaihua
1 parent 27f0a463

目标消失时增加一次推送;修复算法框和目标不匹配问题,改善跟踪效果

src/ai_engine_module/VPTProcess.cpp
@@ -138,7 +138,8 @@ int VPTProcess::process_gpu(sy_img * batch_img, vector<string>& tasklist, @@ -138,7 +138,8 @@ int VPTProcess::process_gpu(sy_img * batch_img, vector<string>& tasklist,
138 /* 跟踪:第一帧 带检测框信息的跟踪,取结果返回 */ 138 /* 跟踪:第一帧 带检测框信息的跟踪,取结果返回 */
139 if (j == 0) 139 if (j == 0)
140 { 140 {
141 - int objCount = cur_sort.update_v2(isUseDet, /*save lk = */false, /*center_dist = */true, maxLen, detectResult[detectIndex], result[detectIndex].obj, deleteObjectID[detectIndex]); 141 + // int objCount = cur_sort.update_v2(isUseDet, /*save lk = */false, /*center_dist = */true, maxLen, detectResult[detectIndex], result[detectIndex].obj, deleteObjectID[detectIndex]);
  142 + int objCount = cur_sort.update_v3(isUseDet, /*save lk = */false, /*center_dist = */false, maxLen, detectResult[detectIndex], result[detectIndex].obj, deleteObjectID[detectIndex]);
142 result[detectIndex].obj_count = objCount; 143 result[detectIndex].obj_count = objCount;
143 result[detectIndex].task_id = task_id; 144 result[detectIndex].task_id = task_id;
144 145
@@ -149,7 +150,8 @@ int VPTProcess::process_gpu(sy_img * batch_img, vector<string>& tasklist, @@ -149,7 +150,8 @@ int VPTProcess::process_gpu(sy_img * batch_img, vector<string>& tasklist,
149 { 150 {
150 onelevel_det_result un_result; 151 onelevel_det_result un_result;
151 //un_result.obj_count = cur_sort.update(isUseDet, false, detectResult[detectIndex], un_result.obj, deleteObjectID[detectIndex]); 152 //un_result.obj_count = cur_sort.update(isUseDet, false, detectResult[detectIndex], un_result.obj, deleteObjectID[detectIndex]);
152 - un_result.obj_count = cur_sort.update_v2(isUseDet, false, true, maxLen, detectResult[detectIndex], un_result.obj, deleteObjectID[detectIndex]); 153 + // un_result.obj_count = cur_sort.update_v2(isUseDet, false, true, maxLen, detectResult[detectIndex], un_result.obj, deleteObjectID[detectIndex]);
  154 + un_result.obj_count = cur_sort.update_v3(isUseDet, false, false, maxLen, detectResult[detectIndex], un_result.obj, deleteObjectID[detectIndex]);
153 } 155 }
154 } 156 }
155 } 157 }
src/ai_engine_module/VPTProcess.cpp_debug 0 → 100755
  1 +#include "VPTProcess.h"
  2 +#include "../common/logger.hpp"
  3 +#include "../ai_platform/task_param_manager.h"
  4 +
  5 +#include <stdlib.h>
  6 +#include <time.h>
  7 +#include <fstream>
  8 +
  9 +#include "vpt.h"
  10 +#include "../ai_platform/macro_definition.h"
  11 +#include "../ai_platform/det_obj_header.h"
  12 +
  13 +#include "opencv2/opencv.hpp"
  14 +
  15 +#include "../util/vpc_util.h"
  16 +
  17 +VPTProcess::VPTProcess(){
  18 + m_max_batchsize = 16;
  19 +}
  20 +
  21 +VPTProcess::~VPTProcess(){
  22 + release();
  23 +}
  24 +
  25 +/* 算法初始化 */
  26 +int VPTProcess::init(VPTProcess_PARAM vparam){
  27 +
  28 + string model_path = vparam.model_dir + "/models/vpt230323_310p.om" ;
  29 +
  30 + LOG_INFO("vpt 版本:{} 模型路径:{}", vpt_get_version(), model_path);
  31 +
  32 + vpt_param param;
  33 + char modelNames[100];
  34 + strcpy(modelNames, model_path.c_str());
  35 + param.modelNames = modelNames;
  36 + param.threshold = vparam.threshold;
  37 + param.devId = vparam.gpuid;
  38 + param.isTrk = false;
  39 +
  40 + m_devId = param.devId;
  41 + ACL_CALL(aclrtSetDevice(m_devId), ACL_ERROR_NONE, -1);
  42 + ACL_CALL(aclrtCreateContext(&m_algorthim_ctx, m_devId), ACL_ERROR_NONE, -1);
  43 +
  44 + int ret = vpt_init(&m_det_handle, param);
  45 + if(ret != 0){
  46 + LOG_DEBUG("vpt init error.");
  47 + return -1;
  48 + }
  49 + jpegUtil.jpeg_init(m_devId);
  50 +
  51 + return 0;
  52 +}
  53 +
  54 +/* 算法计算 */
  55 +// int VPTProcess::process_gpu(sy_img * batch_img, vector<string>& tasklist,
  56 +// vector<onelevel_det_result>& result, vector<vector<int>>& deleteObjectID, vector<vector<onelevel_det_result>>& unUsedResult)
  57 +int VPTProcess::process_gpu(sy_img * batch_img, vector<DeviceMemory*> vec_vptMem, vector<string>& tasklist,
  58 + vector<onelevel_det_result>& result, vector<vector<int>>& deleteObjectID, vector<vector<onelevel_det_result>>& unUsedResult)
  59 +{
  60 + int batchsize = tasklist.size();
  61 +
  62 + if (result.empty())
  63 + result.resize(batchsize);
  64 +
  65 + /* 结果结构体初始化 */
  66 + vpt_result *vpt_det_result = new vpt_result[batchsize];
  67 + for (int b = 0; b < batchsize; b++){
  68 + vpt_det_result[b].obj_count_ = 0;
  69 + vpt_det_result[b].obj_results_ = new vpt_obj_result[MAX_DET_COUNT];
  70 + }
  71 +
  72 + do{
  73 + /* 路数太多时 按照最大batchsize数 拆批次运行 */
  74 + int cur_batch_size = m_max_batchsize;
  75 + int cycleTimes = batchsize / cur_batch_size + (batchsize % cur_batch_size == 0 ? 0 : 1);
  76 +
  77 + for (int c = 0; c < cycleTimes; c++){
  78 +
  79 + int real_batchsize = c == cycleTimes - 1 ? (batchsize - cur_batch_size*c) : cur_batch_size;
  80 + int startbatch = c*cur_batch_size;
  81 +
  82 + vpt_result *real_res = vpt_det_result + startbatch;
  83 +
  84 + aclrtSetDevice(m_devId);
  85 + int ret = aclrtSetCurrentContext(m_algorthim_ctx);
  86 + if(ACL_ERROR_NONE != ret){
  87 + break;
  88 + }
  89 + ret = vpt_batch(m_det_handle, batch_img + startbatch, real_batchsize, real_res);
  90 + if(ret != 0){
  91 + break;
  92 + }
  93 + }
  94 +
  95 + vector <vector< vector <float>>> detectResult(batchsize); // sort
  96 +
  97 + /* 将检测的结果放进数组 转换为跟踪的输入需要(若为人脸 则检测结果可能跟多,比如需要带上ldmk点) */
  98 + // filter by threshold.
  99 + for (int b = 0; b < batchsize; b++)
  100 + {
  101 + vpt_result cur_result = vpt_det_result[b];
  102 +
  103 + for (int c = 0; c < cur_result.obj_count_ && c < MAX_OBJ_COUNT; c++)
  104 + {
  105 + float x1 = vpt_det_result[b].obj_results_[c].obj_rect.left_;
  106 + float y1 = vpt_det_result[b].obj_results_[c].obj_rect.top_;
  107 + float x2 = vpt_det_result[b].obj_results_[c].obj_rect.left_ + vpt_det_result[b].obj_results_[c].obj_rect.width_;
  108 + float y2 = vpt_det_result[b].obj_results_[c].obj_rect.top_ + vpt_det_result[b].obj_results_[c].obj_rect.height_;
  109 +
  110 + float class_id = vpt_det_result[b].obj_results_[c].obj_index;
  111 + float score = vpt_det_result[b].obj_results_[c].obj_score;
  112 +
  113 + if (score >= THRESHOLD)
  114 + {
  115 + vector <float> obj;
  116 + obj.push_back(x1);
  117 + obj.push_back(y1);
  118 + obj.push_back(x2);
  119 + obj.push_back(y2);
  120 + obj.push_back(score);
  121 + obj.push_back(class_id);
  122 + detectResult[b].push_back(obj);
  123 + }
  124 + }
  125 + }
  126 +
  127 +#if 0
  128 + for (int b = 0; b < batchsize; b++)
  129 + {
  130 + std::string file_path = "res/vpt_test/";
  131 + auto time_now = std::chrono::system_clock::now();
  132 + std::string cur_timestamp_us = std::to_string(std::chrono::duration_cast<std::chrono::microseconds>(time_now.time_since_epoch()).count());
  133 + std::string img_filename = file_path + cur_timestamp_us + "_" + std::to_string(detectResult[b].size()) + ".jpg";
  134 +
  135 + vpc_img_info src_img_info = VPCUtil::vpc_devMem2vpcImg(vec_vptMem[b]);
  136 + bool bSaved = jpegUtil.jpeg_encode(src_img_info.pic_desc, img_filename);
  137 +
  138 + cv::Mat big_img = cv::imread(img_filename);
  139 + for (int c = 0; c < detectResult[b].size(); c++) {
  140 + cv::rectangle(big_img, cv::Rect(detectResult[b][c][0], detectResult[b][c][1], detectResult[b][c][2] - detectResult[b][c][0],
  141 + detectResult[b][c][3] - detectResult[b][c][1]), cv::Scalar(158, 52, 254), 3, 1, 0);
  142 + }
  143 + cv::imwrite(img_filename, big_img);
  144 +
  145 + VPCUtil::vpc_img_release(src_img_info);
  146 + }
  147 +#endif
  148 +
  149 + bool isUseDet = true;
  150 + for (size_t detectIndex = 0; detectIndex < batchsize; detectIndex++) {
  151 + string task_id = tasklist[detectIndex];
  152 +
  153 + if (! taskTrackers[task_id].tracker.GetState())
  154 + continue;
  155 +
  156 + Sort &cur_sort = taskTrackers[task_id].tracker;
  157 + isUseDet = true;
  158 +
  159 + const float maxLen = std::sqrt(batch_img[detectIndex].w_ * batch_img[detectIndex].w_ + batch_img[detectIndex].h_ * batch_img[detectIndex].h_); //-modified by zsh 220719
  160 + /* FusionInterval是跳帧参数,以十类人车物为例,一般跳5帧,所以第一帧检测,后续四帧纯跟踪 */
  161 + for (int j = 0; j < taskTrackers[task_id].tracker.FusionInterval; j++)
  162 + {
  163 + /* 跟踪:第一帧 带检测框信息的跟踪,取结果返回 */
  164 + if (j == 0)
  165 + {
  166 + // int objCount = cur_sort.update_v2(isUseDet, /*save lk = */false, /*center_dist = */true, maxLen, detectResult[detectIndex], result[detectIndex].obj, deleteObjectID[detectIndex]);
  167 + int objCount = cur_sort.update_v3(isUseDet, /*save lk = */false, /*center_dist = */true, maxLen, detectResult[detectIndex], result[detectIndex].obj, deleteObjectID[detectIndex]);
  168 + result[detectIndex].obj_count = objCount;
  169 + result[detectIndex].task_id = task_id;
  170 +
  171 + // vector<vector<float>>().swap(detectResult[detectIndex]);
  172 + // detectResult[detectIndex].clear();
  173 + isUseDet = false;
  174 + } else /* 跟踪:后四帧 纯粹跟踪 纯跟踪结果不返回 */
  175 + {
  176 + onelevel_det_result un_result;
  177 + //un_result.obj_count = cur_sort.update(isUseDet, false, detectResult[detectIndex], un_result.obj, deleteObjectID[detectIndex]);
  178 + // un_result.obj_count = cur_sort.update_v2(isUseDet, false, true, maxLen, detectResult[detectIndex], un_result.obj, deleteObjectID[detectIndex]);
  179 + un_result.obj_count = cur_sort.update_v3(isUseDet, false, true, maxLen, detectResult[detectIndex], un_result.obj, deleteObjectID[detectIndex]);
  180 + }
  181 + }
  182 + }
  183 +#if 1
  184 + for (int b = 0; b < batchsize; b++)
  185 + {
  186 + std::string file_path = "res/vpt_track/";
  187 + auto time_now = std::chrono::system_clock::now();
  188 + std::string cur_timestamp_us = std::to_string(std::chrono::duration_cast<std::chrono::microseconds>(time_now.time_since_epoch()).count());
  189 + std::string img_filename = file_path + cur_timestamp_us + "_" + std::to_string(result[b].obj_count) + ".jpg";
  190 + vpc_img_info src_img_info = VPCUtil::vpc_devMem2vpcImg(vec_vptMem[b]);
  191 + bool flag = false;
  192 + for (int c = 0; c < result[b].obj_count; c++) {
  193 + if (result[b].obj[c].id > 7700 && result[b].obj[c].id < 8000) flag = true;
  194 + }
  195 +
  196 + if (flag) {
  197 + bool bSaved = jpegUtil.jpeg_encode(src_img_info.pic_desc, img_filename);
  198 + cv::Mat big_img = cv::imread(img_filename);
  199 +
  200 + for (int c = 0; c < result[b].obj_count; c++) {
  201 + cv::putText(big_img, std::to_string(result[b].obj[c].id), cv::Point(result[b].obj[c].left, result[b].obj[c].top-5), cv::FONT_HERSHEY_SIMPLEX, 0.75, cv::Scalar(255,0,0),2,8);
  202 + cv::rectangle(big_img, cv::Rect(result[b].obj[c].left, result[b].obj[c].top, result[b].obj[c].right - result[b].obj[c].left,
  203 + result[b].obj[c].bottom - result[b].obj[c].top), cv::Scalar(158, 52, 254), 3, 1, 0);
  204 + }
  205 +
  206 + for (int c = 0; c < detectResult[b].size(); c++) {
  207 + cv::rectangle(big_img, cv::Rect(detectResult[b][c][0], detectResult[b][c][1], detectResult[b][c][2] - detectResult[b][c][0],
  208 + detectResult[b][c][3] - detectResult[b][c][1]), cv::Scalar(0, 0, 255), 3, 1, 0);
  209 + }
  210 + cv::imwrite(img_filename, big_img);
  211 + }
  212 + VPCUtil::vpc_img_release(src_img_info);
  213 + }
  214 +#endif
  215 +
  216 + vector <vector< vector <float>>>().swap(detectResult); // free memory.
  217 + } while (0);
  218 +
  219 + if(vpt_det_result){
  220 + for (int b = 0; b < batchsize; b++){
  221 + delete[] vpt_det_result[b].obj_results_;
  222 + }
  223 + delete[] vpt_det_result;
  224 + }
  225 +
  226 + return 0;
  227 +}
  228 +
  229 +
  230 +/* 算法句柄 资源释放 */
  231 +void VPTProcess::release(){
  232 + if (m_det_handle){
  233 + vpt_release(&m_det_handle);
  234 + m_det_handle = NULL;
  235 + }
  236 + jpegUtil.jpeg_release();
  237 + if(m_algorthim_ctx){
  238 + aclrtDestroyContext(m_algorthim_ctx);
  239 + }
  240 +}
  241 +
  242 +// 221117byzsh
  243 +void VPTProcess::addTaskTracker(const string taskID, double rWidth, double rHeight, int skip_frame)
  244 +{
  245 + TaskTracker t;
  246 + t.TaskID = taskID;
  247 + t.ratioWidth = rWidth;
  248 + t.ratioHeight = rHeight;
  249 + t.tracker.FusionInterval = skip_frame;
  250 +
  251 + taskTrackers[taskID] = t;
  252 +}
  253 +
  254 +/* 任务结束跟踪器 */
  255 +bool VPTProcess::finishTaskTracker(const string taskID)
  256 +{
  257 + taskTrackers.erase(taskID);
  258 + return true;
  259 +}
0 \ No newline at end of file 260 \ No newline at end of file
src/ai_engine_module/VPTProcess.h
@@ -11,6 +11,8 @@ @@ -11,6 +11,8 @@
11 #include "sort/Sort.h" 11 #include "sort/Sort.h"
12 #include "acl/acl.h" 12 #include "acl/acl.h"
13 #include "acl/ops/acl_dvpp.h" 13 #include "acl/ops/acl_dvpp.h"
  14 +#include "../util/vpc_util.h"
  15 +#include "../util/JpegUtil.h"
14 16
15 using namespace std; 17 using namespace std;
16 18
@@ -68,7 +70,8 @@ public: @@ -68,7 +70,8 @@ public:
68 */ 70 */
69 int process_gpu(sy_img * batch_img, vector<string>& tasklist, 71 int process_gpu(sy_img * batch_img, vector<string>& tasklist,
70 vector<onelevel_det_result>& result, vector<vector<int>>& deleteObjectID, vector<vector<onelevel_det_result>>& unUsedResult); 72 vector<onelevel_det_result>& result, vector<vector<int>>& deleteObjectID, vector<vector<onelevel_det_result>>& unUsedResult);
71 - 73 + int process_gpu(sy_img * batch_img, vector<DeviceMemory*> vec_vptMem, vector<string>& tasklist,
  74 + vector<onelevel_det_result>& result, vector<vector<int>>& deleteObjectID, vector<vector<onelevel_det_result>>& unUsedResult);
72 75
73 /************************************************************************* 76 /*************************************************************************
74 * FUNCTION: VPT_Release 77 * FUNCTION: VPT_Release
@@ -87,7 +90,7 @@ public: @@ -87,7 +90,7 @@ public:
87 private: 90 private:
88 int m_devId; 91 int m_devId;
89 aclrtContext m_algorthim_ctx; 92 aclrtContext m_algorthim_ctx;
90 - 93 + JpegUtil jpegUtil;
91 void* m_det_handle{nullptr}; 94 void* m_det_handle{nullptr};
92 float threshold{0.6}; 95 float threshold{0.6};
93 int m_max_batchsize; 96 int m_max_batchsize;
src/ai_engine_module/sort/Sort.cpp
@@ -380,6 +380,232 @@ int Sort::update_v2(bool isUseDet, bool copy_ldmk, bool center_dist, float maxLe @@ -380,6 +380,232 @@ int Sort::update_v2(bool isUseDet, bool copy_ldmk, bool center_dist, float maxLe
380 380
381 } 381 }
382 382
  383 +int Sort::update_v3(bool isUseDet, bool copy_ldmk, bool center_dist, float maxLen, vector< vector<float> > &dets, det_objinfo *result, vector<int> &deleteObjectID)
  384 +{
  385 + //get predicted locations from existing trackers.
  386 + vector< vector<float> > trks;
  387 + vector<float> pos;
  388 + int ObjCount = 0; //by zl 本帧图像中的有效前景个数
  389 + vector<float> bbox;
  390 +
  391 + for (int i = 0; i < trackers.size(); i++ )
  392 + {
  393 + pos = trackers[i].predict(); // 对跟踪列表中的框进行预测(包含初始化的和匹配后update的)
  394 + pos.push_back(1);
  395 + pos.push_back(trackers[i].cls);
  396 + trks.push_back(pos);
  397 + pos.clear();
  398 + }
  399 +
  400 + if (isUseDet == true)
  401 + {
  402 + vector< vector<int> > matched;
  403 + vector<int> unmatched_dets;
  404 + vector<int> unmatched_trks;
  405 +
  406 + if(center_dist) {
  407 + Sort::associate_detections_to_trackers_v2(matched, unmatched_dets, unmatched_trks, dets, trks, maxLen); // 中心距离匹配
  408 + }
  409 + else {
  410 + Sort::associate_detections_to_trackers(matched, unmatched_dets, unmatched_trks, dets, trks, 0.3); // iou匹配
  411 + }
  412 + //update matched trackers with assigned detections----匹配上的更新跟踪信息
  413 + for (int matched_number = 0; matched_number < matched.size(); matched_number++)
  414 + {
  415 + trackers[matched[matched_number][1]].update(dets[matched[matched_number][0]]);
  416 + trackers[matched[matched_number][1]].score = dets[matched[matched_number][0]][4];
  417 + trackers[matched[matched_number][1]].cls = dets[matched[matched_number][0]][5];
  418 + if (copy_ldmk)//存入关键点信息
  419 + {
  420 + for (int m = 0; m < 50; ++m)
  421 + {
  422 + trackers[matched[matched_number][1]].ldmk.push_back(dets[matched[matched_number][0]][m + 6]);
  423 + }
  424 + // added by zsh 姿态角信息--------------------------------------------------------
  425 + trackers[matched[matched_number][1]].roll = dets[matched[matched_number][0]][56];
  426 + trackers[matched[matched_number][1]].yaw = dets[matched[matched_number][0]][57];
  427 + trackers[matched[matched_number][1]].pitch = dets[matched[matched_number][0]][58];
  428 + //--------------------------------------------------------------------------------
  429 + }
  430 +#if 1
  431 + //返回加上ID信息的检测框===================================================================
  432 + if (ObjCount < MAX_OBJ_COUNT) {
  433 + // if (ObjCount < MAX_OBJ_COUNT && (trackers[matched[matched_number][1]].time_since_update < FusionInterval) && ((trackers[matched[matched_number][1]].hit_streak >= min_hits) || (frame_count <= (min_hits * FusionInterval)))) {
  434 + if (trackers[matched[matched_number][1]].id == -1)
  435 + trackers[matched[matched_number][1]].id = trackcount++;
  436 + result[ObjCount].id = trackers[matched[matched_number][1]].id;
  437 + result[ObjCount].num = trackers[matched[matched_number][1]].frame_count;
  438 +
  439 + result[ObjCount].left = dets[matched[matched_number][0]][0];
  440 + result[ObjCount].top = dets[matched[matched_number][0]][1];
  441 + result[ObjCount].right = dets[matched[matched_number][0]][2];
  442 + result[ObjCount].bottom = dets[matched[matched_number][0]][3];
  443 + result[ObjCount].confidence = dets[matched[matched_number][0]][4];
  444 + result[ObjCount].index = dets[matched[matched_number][0]][5];
  445 + result[ObjCount].center_x = result[ObjCount].left + (result[ObjCount].right - result[ObjCount].left) * 0.5; // 中心点 add by 20170227
  446 + result[ObjCount].center_y = result[ObjCount].top + (result[ObjCount].bottom - result[ObjCount].top) * 0.5; // 中心点
  447 + if (trackers[matched[matched_number][1]].age == 2 * FusionInterval) {
  448 + result[ObjCount].snap_flag = 1; // 中心点
  449 + }
  450 + else {
  451 + result[ObjCount].snap_flag = 0; // 中心点
  452 + }
  453 +
  454 + if (copy_ldmk) // 存入关键点信息
  455 + {
  456 + for (int m = 0; m < 25; ++m)
  457 + {
  458 + result[ObjCount].landmark_point[m].x_ = trackers[matched[matched_number][1]].ldmk[2 * m];
  459 + result[ObjCount].landmark_point[m].y_ = trackers[matched[matched_number][1]].ldmk[2 * m + 1];
  460 + }
  461 + // added by zsh 姿态角信息--------------------------------
  462 + result[ObjCount].roll = trackers[matched[matched_number][1]].roll;
  463 + result[ObjCount].yaw = trackers[matched[matched_number][1]].yaw;
  464 + result[ObjCount].pitch = trackers[matched[matched_number][1]].pitch;
  465 + //--------------------------------------------------------
  466 + }
  467 +
  468 + ObjCount++;
  469 + }
  470 + //===================================================================================
  471 +#endif
  472 + }
  473 +
  474 + //create and initialise new trackers for unmatched detections----为未匹配上的检测框分配新tracker
  475 + for (int unmatched_dets_number = 0; unmatched_dets_number < unmatched_dets.size(); unmatched_dets_number++)
  476 + {
  477 + KalmanBoxTracker tracker = KalmanBoxTracker(dets[unmatched_dets[unmatched_dets_number]], max_track_length);
  478 + tracker.id = -1;
  479 + tracker.FusionInterval = FusionInterval; //221117byzsh
  480 + trackers.push_back(tracker);
  481 + trackers[trackers.size() - 1].score = dets[unmatched_dets[unmatched_dets_number]][4];//by zl 20170525 解决第一次检测时置信度为0问题
  482 +
  483 + if (copy_ldmk)//存入关键点信息
  484 + {
  485 + for (int m = 0; m < 50; ++m)
  486 + {
  487 + trackers[trackers.size() - 1].ldmk.push_back(dets[unmatched_dets[unmatched_dets_number]][m + 6]);
  488 + }
  489 + // added by zsh 姿态角信息------------------------------------------------------------
  490 + trackers[trackers.size() - 1].roll = dets[unmatched_dets[unmatched_dets_number]][56];
  491 + trackers[trackers.size() - 1].yaw = dets[unmatched_dets[unmatched_dets_number]][57];
  492 + trackers[trackers.size() - 1].pitch = dets[unmatched_dets[unmatched_dets_number]][58];
  493 + //-----------------------------------------------------------------------------------
  494 + }
  495 +
  496 + // cout << "trackers size: " << trackers.size() << endl;
  497 +
  498 + }
  499 +
  500 + for (int trackers_number = 0; trackers_number < trackers.size();)
  501 + {
  502 + // cout << trackers[trackers_number].id << " " <<trackers[trackers_number].time_since_update << " " << trackers[trackers_number].hit_streak << " " << min_hits << " " << frame_count << endl;
  503 + if (trackers[trackers_number].time_since_update > max_age) // 失配次数超过max_age,放入轨迹消失列表,从跟踪列表中删除
  504 + {
  505 + if (trackers[trackers_number].id != -1)
  506 + {
  507 + deleteObjectID.push_back(trackers[trackers_number].id);
  508 + }
  509 +
  510 + trackcount++;
  511 + std::vector<float>().swap(trackers[trackers_number].ldmk);
  512 + trackers.erase(trackers.begin() + trackers_number);
  513 + continue;
  514 + }
  515 +#if 0
  516 + // 失配次数小于FusionInterval且满足最小匹配次数则返回
  517 + if (ObjCount < MAX_OBJ_COUNT && (trackers[trackers_number].time_since_update < FusionInterval) && ((trackers[trackers_number].hit_streak >= min_hits) || (frame_count <= (min_hits * FusionInterval))))
  518 + {
  519 + if (trackers[trackers_number].id == -1)
  520 + trackers[trackers_number].id = trackcount++;
  521 + result[ObjCount].id = trackers[trackers_number].id;
  522 + result[ObjCount].num = trackers[trackers_number].frame_count;
  523 +
  524 + bbox = trackers[trackers_number].get_state(); // 跟踪框
  525 + result[ObjCount].left = bbox[0]; // bbout[i][0];
  526 + result[ObjCount].top = bbox[1]; //bbout[i][1];
  527 + result[ObjCount].right = bbox[2]; //bbout[i][2];
  528 + result[ObjCount].bottom = bbox[3]; //bbout[i][3];
  529 + result[ObjCount].confidence = trackers[trackers_number].score; // bbout[i][4];
  530 + result[ObjCount].index = trackers[trackers_number].cls; // bbout[i][5] - 1;
  531 + result[ObjCount].center_x = result[ObjCount].left + (result[ObjCount].right - result[ObjCount].left) * 0.5; // 中心点 add by 20170227
  532 + result[ObjCount].center_y = result[ObjCount].top + (result[ObjCount].bottom - result[ObjCount].top) * 0.5; // 中心点
  533 + if (trackers[trackers_number].age == 2 * FusionInterval)
  534 + {
  535 + result[ObjCount].snap_flag = 1; // 中心点
  536 + }
  537 + else
  538 + {
  539 + result[ObjCount].snap_flag = 0; // 中心点
  540 + }
  541 +
  542 + if (copy_ldmk) // 存入关键点信息
  543 + {
  544 + for (int m = 0; m < 25; ++m)
  545 + {
  546 + result[ObjCount].landmark_point[m].x_ = trackers[trackers_number].ldmk[2 * m];
  547 + result[ObjCount].landmark_point[m].y_ = trackers[trackers_number].ldmk[2 * m + 1];
  548 + }
  549 + // added by zsh 姿态角信息--------------------------------
  550 + result[ObjCount].roll = trackers[trackers_number].roll;
  551 + result[ObjCount].yaw = trackers[trackers_number].yaw;
  552 + result[ObjCount].pitch = trackers[trackers_number].pitch;
  553 + //--------------------------------------------------------
  554 + }
  555 +#if _Debug
  556 + printf("trackers_number = %d, trackers.size() = %d, update: index = %d, id = %d, (%d, %d), (%d, %d)\n", trackers_number, trackers.size(), result[ObjCount].index, result[ObjCount].id, result[ObjCount].left, result[ObjCount].top, result[ObjCount].right, result[ObjCount].bottom);
  557 +#endif
  558 + ObjCount++;
  559 + }
  560 +#endif
  561 + trackers_number++;//共多少条轨迹
  562 + }
  563 + }
  564 + else
  565 + {
  566 + for (int trackers_number = 0; trackers_number < trackers.size() && ObjCount < MAX_OBJ_COUNT; trackers_number++)
  567 + {
  568 + if (trackers[trackers_number].id == -1)
  569 + trackers[trackers_number].id = trackcount++;
  570 + result[trackers_number].num = trackers[trackers_number].frame_count;
  571 + bbox = trackers[trackers_number].get_state();
  572 + result[trackers_number].id = trackers[trackers_number].id;
  573 + result[trackers_number].left = bbox[0]; // bbout[i][0];
  574 + result[trackers_number].top = bbox[1]; //bbout[i][1];
  575 + result[trackers_number].right = bbox[2]; //bbout[i][2];
  576 + result[trackers_number].bottom = bbox[3]; //bbout[i][3];
  577 + result[trackers_number].confidence = trackers[trackers_number].score; // bbout[i][4];
  578 + result[trackers_number].index = trackers[trackers_number].cls;//bbox[5] - 1;// trackers[trackers_number].cls - 1; // bbout[i][5] - 1;
  579 + result[trackers_number].center_x = (int)(result[trackers_number].left + (result[trackers_number].right - result[trackers_number].left) * 0.5); // 中心点 add by 20170227
  580 + result[trackers_number].center_y = (int)(result[trackers_number].top + (result[trackers_number].bottom - result[trackers_number].top) * 0.5); // 中心点
  581 +
  582 + if (copy_ldmk)//存入关键点信息
  583 + {
  584 + for (int m = 0; m < 25; ++m)
  585 + {
  586 + result[trackers_number].landmark_point[m].x_ = trackers[trackers_number].ldmk[2 * m];
  587 + result[trackers_number].landmark_point[m].y_ = trackers[trackers_number].ldmk[2 * m + 1];
  588 + }
  589 + // added by zsh 姿态角信息---------------------------------------
  590 + result[trackers_number].roll = trackers[trackers_number].roll;
  591 + result[trackers_number].yaw = trackers[trackers_number].yaw;
  592 + result[trackers_number].pitch = trackers[trackers_number].pitch;
  593 + //--------------------------------------------------------------
  594 + }
  595 +
  596 + result[ObjCount].snap_flag = 0; // 中心点
  597 +
  598 + ObjCount++;
  599 + }
  600 + }
  601 +
  602 + //---------------------------注释掉了这步操作 用了新的绘制轨迹的函数 需要绘制调用addTracker(Mat *img)方法 by lm---------------------------------------------/
  603 + //addTracker(result, ObjCount);
  604 +
  605 + frame_count += 1; //帧数加一
  606 + return ObjCount;
  607 +
  608 +}
383 609
384 //---------------------------利用trackers中的history 绘制路径 -by lm ---------------------------------------------/ 610 //---------------------------利用trackers中的history 绘制路径 -by lm ---------------------------------------------/
385 //固定长度的轨迹,采用循环队列,仅保存目前最前N length的轨迹,避免对于停留在画面中目标 导致的内存一直增长 611 //固定长度的轨迹,采用循环队列,仅保存目前最前N length的轨迹,避免对于停留在画面中目标 导致的内存一直增长
src/ai_engine_module/sort/Sort.h
@@ -47,6 +47,7 @@ public: @@ -47,6 +47,7 @@ public:
47 Sort(); 47 Sort();
48 int update(bool isUseDet, bool copy_ldmk, vector< vector<float> > &dets, det_objinfo *result, vector<int> &deleteObjectID); 48 int update(bool isUseDet, bool copy_ldmk, vector< vector<float> > &dets, det_objinfo *result, vector<int> &deleteObjectID);
49 int update_v2(bool isUseDet, bool copy_ldmk, bool center_dist, float maxLen, vector< vector<float> > &dets, det_objinfo *result, vector<int> &deleteObjectID); // added by zsh 220719 49 int update_v2(bool isUseDet, bool copy_ldmk, bool center_dist, float maxLen, vector< vector<float> > &dets, det_objinfo *result, vector<int> &deleteObjectID); // added by zsh 220719
  50 + int update_v3(bool isUseDet, bool copy_ldmk, bool center_dist, float maxLen, vector< vector<float> > &dets, det_objinfo *result, vector<int> &deleteObjectID);
50 void Release(); 51 void Release();
51 void ReSet(); 52 void ReSet();
52 void Pause(); 53 void Pause();
src/ai_engine_module/traffic_light_process.cpp
@@ -454,8 +454,11 @@ namespace ai_engine_module @@ -454,8 +454,11 @@ namespace ai_engine_module
454 // LOG_TRACE("task id is {} algor type is {} obj_id {}", task_id, int(algor_type), objId); 454 // LOG_TRACE("task id is {} algor type is {} obj_id {}", task_id, int(algor_type), objId);
455 if (algor_type == algorithm_type_t::PERSON_RUNNING_REDLIGHTS && static_cast<det_class_label_t>(det_result.box.cls) != det_class_label_t::HUMAN) 455 if (algor_type == algorithm_type_t::PERSON_RUNNING_REDLIGHTS && static_cast<det_class_label_t>(det_result.box.cls) != det_class_label_t::HUMAN)
456 continue; 456 continue;
457 - if (algor_type == algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS && (static_cast<det_class_label_t>(det_result.box.cls) != det_class_label_t::MOTOCYCLE ||  
458 - static_cast<det_class_label_t>(det_result.box.cls) != det_class_label_t::BICYCLE)) 457 + // if (algor_type == algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS && (static_cast<det_class_label_t>(det_result.box.cls) != det_class_label_t::MOTOCYCLE ||
  458 + // static_cast<det_class_label_t>(det_result.box.cls) != det_class_label_t::BICYCLE))
  459 + // continue;
  460 +
  461 + if (algor_type == algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS && static_cast<det_class_label_t>(det_result.box.cls) == det_class_label_t::HUMAN)
459 continue; 462 continue;
460 463
461 auto& e = id_to_mn_[obj_key]; 464 auto& e = id_to_mn_[obj_key];
src/ai_platform/MultiSourceProcess.cpp
@@ -869,7 +869,7 @@ int CMultiSourceProcess::algorthim_vpt(vector&lt;DeviceMemory*&gt; vec_gpuMem){ @@ -869,7 +869,7 @@ int CMultiSourceProcess::algorthim_vpt(vector&lt;DeviceMemory*&gt; vec_gpuMem){
869 869
870 /* 一级检测器,内部已完成跟踪操作 */ 870 /* 一级检测器,内部已完成跟踪操作 */
871 vpt_process.process_gpu(vpt_interest_imgs.data(), vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // do det & track. 871 vpt_process.process_gpu(vpt_interest_imgs.data(), vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // do det & track.
872 - 872 + // vpt_process.process_gpu(vpt_interest_imgs.data(), vec_vptMem, vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // debug
873 m_snapshot_reprocessing->screen_effective_snapshot(vptResult); 873 m_snapshot_reprocessing->screen_effective_snapshot(vptResult);
874 874
875 #ifndef VEHICLE_MULTI_BOXES 875 #ifndef VEHICLE_MULTI_BOXES
@@ -1698,6 +1698,27 @@ void CMultiSourceProcess::village_snapshot(vector&lt;string&gt;&amp; vpt_interest_task_id, @@ -1698,6 +1698,27 @@ void CMultiSourceProcess::village_snapshot(vector&lt;string&gt;&amp; vpt_interest_task_id,
1698 } 1698 }
1699 1699
1700 1700
  1701 + // 推送轨迹结束的目标用于数量统计
  1702 + {
  1703 + const OBJ_VALUES obj_value = it->second;
  1704 + std::vector<video_object_snapshot> algo_results;
  1705 + std::vector<int> algorithm_types;
  1706 + algorithm_types.push_back((int)algorithm_type_t::FLOW_STATISTICS);
  1707 +#ifdef POST_USE_RABBITMQ
  1708 + video_object_snapshot new_obj_ss_info;
  1709 + new_obj_ss_info.analysisRes = nullptr;
  1710 + new_obj_ss_info.object_id = obj_key.obj_id;
  1711 + new_obj_ss_info.obj_info.set_data(obj_value.snapShots[1].index.index, obj_value.snapShots[1].confidence, 0, 0, 0, 0);
  1712 + strcpy(new_obj_ss_info.task_id, obj_key.video_id.c_str());
  1713 + strcpy(new_obj_ss_info.video_image_path, "");
  1714 + strcpy(new_obj_ss_info.snapshot_image_path, "");
  1715 + algo_results.push_back(new_obj_ss_info);
  1716 + auto json_str = helpers::gen_json::gen_village_json(task_id, obj_key.obj_id, algorithm_types, algo_results, "");
  1717 + mq_manager_->publish(mq_type_t::ALARM_MQ, json_str.c_str(), true);
  1718 +#endif
  1719 + }
  1720 +
  1721 +
1701 if (village_alarm) { 1722 if (village_alarm) {
1702 const OBJ_VALUES obj_value = it->second; 1723 const OBJ_VALUES obj_value = it->second;
1703 std::string cur_timestamp_ms = std::to_string(helpers::timer::get_cur_time_ms()); 1724 std::string cur_timestamp_ms = std::to_string(helpers::timer::get_cur_time_ms());
src/ai_platform/header.h
@@ -41,6 +41,7 @@ enum class algorithm_type_t { @@ -41,6 +41,7 @@ enum class algorithm_type_t {
41 NONMOTOR_VEHICLE_SNAPSHOT = 401, 41 NONMOTOR_VEHICLE_SNAPSHOT = 401,
42 TAKEAWAY_MEMBER_CLASSIFICATION = 402, 42 TAKEAWAY_MEMBER_CLASSIFICATION = 402,
43 43
  44 + FLOW_STATISTICS = 500, // 用于数量统计
44 NONMOTOR_VEHICLE_NOHELMET = 501,// 电动/摩托车不戴头盔 45 NONMOTOR_VEHICLE_NOHELMET = 501,// 电动/摩托车不戴头盔
45 NONMOTOR_VEHICLE_OVERMAN = 502, // 电动/摩托车超员 46 NONMOTOR_VEHICLE_OVERMAN = 502, // 电动/摩托车超员
46 TRICYCLE_MANNED = 503, // 三轮车载人 47 TRICYCLE_MANNED = 503, // 三轮车载人
src/demo/demo.cpp
@@ -774,7 +774,8 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi, @@ -774,7 +774,8 @@ string createTask(void *handle, std::vector&lt;algorithm_type_t&gt; algor_vec, int gi,
774 tparam.ipc_url = "/data/share/data/燕高路口高点_CVR_2015-12-30_09-00-00_2015-12-30.mp4"; 774 tparam.ipc_url = "/data/share/data/燕高路口高点_CVR_2015-12-30_09-00-00_2015-12-30.mp4";
775 break; 775 break;
776 case 9: 776 case 9:
777 - tparam.ipc_url = "/opt/share/data/1-00000002d55_h265.mp4"; 777 + // tparam.ipc_url = "/opt/share/data/1-00000002d55_h265.mp4";
  778 + tparam.ipc_url = "/data/share/data/燕高路口高点_CVR_2015-12-30_09-00-00_2015-12-30.mp4";
778 break; 779 break;
779 case 10: 780 case 10:
780 tparam.ipc_url = "/opt/share/data/1-00000002d55.mp4"; 781 tparam.ipc_url = "/opt/share/data/1-00000002d55.mp4";
@@ -894,7 +895,7 @@ void test_gpu(int gpuID){ @@ -894,7 +895,7 @@ void test_gpu(int gpuID){
894 895
895 std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE, 896 std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE,
896 algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS}; 897 algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS};
897 - std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::FACE_SNAPSHOT}; 898 + std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN};
898 899
899 /* 900 /*
900 int repeat_num = 1000; 901 int repeat_num = 1000;
@@ -921,7 +922,7 @@ void test_gpu(int gpuID){ @@ -921,7 +922,7 @@ void test_gpu(int gpuID){
921 createTask(handle, algor_vec2, 6); 922 createTask(handle, algor_vec2, 6);
922 createTask(handle, algor_vec2, 7); 923 createTask(handle, algor_vec2, 7);
923 createTask(handle, algor_vec2, 8); 924 createTask(handle, algor_vec2, 8);
924 - // createTask(handle, algor_vec, 9); 925 + createTask(handle, algor_vec2, 9);
925 // createTask(handle, algor_vec, 10); 926 // createTask(handle, algor_vec, 10);
926 // createTask(handle, algor_vec, 11); 927 // createTask(handle, algor_vec, 11);
927 // createTask(handle, algor_vec, 12); 928 // createTask(handle, algor_vec, 12);