Commit afd07f06f52edb35ddfea046b54ad502fd954e11
Merge branch 'dev-shzhao' into dev-cmhu
Showing
10 changed files
with
26 additions
and
2356 deletions
bin/libhcp_vdec.so
No preview for this file type
bin/libhs_motor_process.so
No preview for this file type
bin/libhs_tri_process.so
No preview for this file type
bin/libhs_truck_process.so
No preview for this file type
bin/libmotor_rainshed_vdec.so
No preview for this file type
bin/libphone_motor_det.so
No preview for this file type
bin/libtraffic_light_vdec.so
No preview for this file type
bin/libvpt_det_vdec.so
No preview for this file type
src/ai_platform/MultiSourceProcess.cpp-- deleted
1 | -#include "MultiSourceProcess.h" | ||
2 | -#include "../common/logger.hpp" | ||
3 | - | ||
4 | -#include <string> | ||
5 | -#include <queue> | ||
6 | -#include <mutex> | ||
7 | -#include <chrono> | ||
8 | -#include <thread> | ||
9 | - | ||
10 | -#include "../decoder/interface/DecoderManager.h" | ||
11 | -#include "../decoder/interface/utiltools.hpp" | ||
12 | -#include "../helpers/time_helper.hpp" | ||
13 | -#include "../helpers/os_helper.hpp" | ||
14 | -#include "../helpers/gen_json.hpp" | ||
15 | -#include "../helpers/str_helper.hpp" | ||
16 | -#include "../reprocessing_module/save_snapshot_reprocessing.h" | ||
17 | - | ||
18 | -#include "macro_definition.h" | ||
19 | -#include "ErrorInfo.h" | ||
20 | -#include "SourceSingleton.hpp" | ||
21 | -#include "mvpt_process_assist.h" | ||
22 | - | ||
23 | -#include "../util/vpc_util.h" | ||
24 | - | ||
25 | -// #define VEHICLE_MULTI_BOXES | ||
26 | - | ||
27 | -#define WITH_FACE_DET_SS | ||
28 | - | ||
29 | -#define productSN "51C4B28135604F649671727185949A91" //linux 通途抓拍引擎产品序列号 | ||
30 | - | ||
31 | -using namespace std; | ||
32 | - | ||
33 | -map<int, algo_type> index_to_algo_type = {{0, algorithm_type_t::HUMAN_SNAPSHOT}, | ||
34 | - {1, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, | ||
35 | - {2, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, | ||
36 | - {3, algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT}, | ||
37 | - {4, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
38 | - {5, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
39 | - {6, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
40 | - {7, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
41 | - {8, algorithm_type_t::VEHICLE_SNAPSHOT}, | ||
42 | - {9, algorithm_type_t::FACE_SNAPSHOT}}; | ||
43 | - | ||
44 | - | ||
45 | -struct decode_cbk_userdata{ | ||
46 | - string task_id; | ||
47 | - void* opaque; | ||
48 | - void* opaque1; | ||
49 | -}; | ||
50 | - | ||
51 | - | ||
52 | -/** | ||
53 | - * 注意: gpuFrame 在解码器设置的显卡上,后续操作要十分注意这一点,尤其是多线程情况 | ||
54 | - * */ | ||
55 | -void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){ | ||
56 | - decode_cbk_userdata* ptr = (decode_cbk_userdata*)userPtr; | ||
57 | - if (ptr!= nullptr) | ||
58 | - { | ||
59 | - CMultiSourceProcess* _this = (CMultiSourceProcess*)ptr->opaque; | ||
60 | - if(nullptr != _this){ | ||
61 | - _this->decoded_cbk(devFrame); | ||
62 | - } | ||
63 | - } | ||
64 | -} | ||
65 | - | ||
66 | -void decode_finished_cbk(const void * userPtr){ | ||
67 | - decode_cbk_userdata* ptr = (decode_cbk_userdata*)userPtr; | ||
68 | - if (ptr!= nullptr) | ||
69 | - { | ||
70 | - CMultiSourceProcess* _this = (CMultiSourceProcess*)ptr->opaque; | ||
71 | - if(nullptr != _this){ | ||
72 | - _this->task_finished(ptr->task_id); | ||
73 | - } | ||
74 | - } | ||
75 | - delete ptr; | ||
76 | - ptr = nullptr; | ||
77 | -} | ||
78 | - | ||
79 | -CMultiSourceProcess::CMultiSourceProcess(){ | ||
80 | - m_timing_snapshot_thread = nullptr; | ||
81 | -} | ||
82 | - | ||
83 | -CMultiSourceProcess::~CMultiSourceProcess(){ | ||
84 | -} | ||
85 | - | ||
86 | -int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ | ||
87 | -#ifdef USE_VILLAGE | ||
88 | - if (!CheckTime()) { | ||
89 | - std::cout << "sy_licence_check failed." << std::endl; | ||
90 | - return AUTHOR_ERROR; | ||
91 | - } | ||
92 | -#else | ||
93 | - //授权相关------------------------------------ | ||
94 | - //授权init----------- | ||
95 | - const char *token_password = "Capture_atlas_arm_2023"; | ||
96 | - std::string guid = std::string("Capture_atlas_arm")+std::to_string(vptParam.gpuid); | ||
97 | - atlas_licence_param lic_param; | ||
98 | - memset(&lic_param, 0, sizeof(atlas_licence_param)); | ||
99 | - sprintf(lic_param.product_id, "%s", productSN); | ||
100 | - sprintf(lic_param.guid, "%s",guid.c_str()); | ||
101 | - sprintf(lic_param.token_pwd, "%s", token_password); | ||
102 | - lic_param.channel_num = 1; | ||
103 | - atlas_licence_token param_token; | ||
104 | - memset(¶m_token, 0, sizeof(atlas_licence_token)); | ||
105 | - | ||
106 | - int result = atlas_licence_connect(&(skt_handle), lic_param, ¶m_token); | ||
107 | - //printf("result:%d,code:%d,msg:%s \n", result, param_token.code, param_token.msg); | ||
108 | - //printf("token:%s\n", param_token.token); | ||
109 | - std::string recv_token = std::string(param_token.token); | ||
110 | - | ||
111 | - //atlas_licence_check_param check_param; | ||
112 | - memset(&(check_param), 0, sizeof(atlas_licence_check_param)); | ||
113 | - sprintf(check_param.token_pwd, "%s", token_password); | ||
114 | - sprintf(check_param.time, "%s", "2023-01-10 20:00:00"); | ||
115 | - sprintf(check_param.token, "%s", recv_token .c_str()); | ||
116 | - check_param.consume = 2; | ||
117 | - | ||
118 | - //授权check------------ | ||
119 | - check_label = -1;//初始值 | ||
120 | - std::cout << "sy_licence_check start." << std::endl; | ||
121 | - atlas_licence_check_result check_result; | ||
122 | - memset(&check_result, 0, sizeof(atlas_licence_check_result)); | ||
123 | - check_result.code = -1; | ||
124 | - | ||
125 | - int res = atlas_licence_check(skt_handle, check_param, &check_result); | ||
126 | - if(res!=0) { | ||
127 | - std::cout << "sy_licence_check failed." << std::endl; | ||
128 | - return AUTHOR_ERROR; | ||
129 | - } | ||
130 | - //std::cout << "code:" << check_result.code << ",msg:" << check_result.msg << std::endl; | ||
131 | - if(check_result.code!=0) { | ||
132 | - std::cout << "code:" << check_result.code << ",msg:" << check_result.msg << std::endl; | ||
133 | - return AUTHOR_ERROR; | ||
134 | - } | ||
135 | - std::cout << "sy_licence_check end." << std::endl; | ||
136 | - | ||
137 | - check_label = 0;//授权成功 | ||
138 | - //授权相关------------------------------------ | ||
139 | -#endif | ||
140 | - set_default_logger(LogLevel(vptParam.log_level), "multi_source_process", vptParam.log_path, vptParam.log_mem, vptParam.log_mem); | ||
141 | - LOG_INFO("编译时间:{} {}", __DATE__, __TIME__); | ||
142 | - | ||
143 | - SourceSingleton::getInstance(); | ||
144 | - | ||
145 | - skip_frame_ = 5; | ||
146 | - m_batch_size = 20; | ||
147 | - | ||
148 | - m_devId = vptParam.gpuid; | ||
149 | - | ||
150 | - string models_dir = vptParam.models_dir; | ||
151 | - | ||
152 | - VPTProcess_PARAM vparam; | ||
153 | - vparam.gpuid = m_devId; | ||
154 | - vparam.max_batch = m_batch_size; | ||
155 | - vparam.threshold = 0.4; | ||
156 | - vparam.model_dir = models_dir; | ||
157 | - | ||
158 | - aclrtSetDevice(m_devId); | ||
159 | - | ||
160 | - int ret = vpt_process.init(vparam); | ||
161 | - if (ret < 0){ | ||
162 | - return ret; | ||
163 | - } | ||
164 | - | ||
165 | -#ifdef USE_VILLAGE | ||
166 | - //道路分割 | ||
167 | - if(seg_process.init(vptParam.gpuid, models_dir) != 0) { | ||
168 | - LOG_FATAL("Init road_seg failed"); | ||
169 | - return -1; | ||
170 | - } | ||
171 | - if(seg3cls_process.init(vptParam.gpuid, models_dir) != 0) { | ||
172 | - LOG_FATAL("Init road_3clsseg failed"); | ||
173 | - return -1; | ||
174 | - } | ||
175 | - | ||
176 | - | ||
177 | - //三轮车头肩检测 | ||
178 | - if (!tricycle_manned_.init(vptParam.gpuid, models_dir)) { | ||
179 | - LOG_FATAL("Init tricycle_hs failed"); | ||
180 | - return -1; | ||
181 | - } | ||
182 | - //货车头肩检测 | ||
183 | - if (!truck_manned_.init(vptParam.gpuid, models_dir)) { | ||
184 | - LOG_FATAL("Init truck_hs failed"); | ||
185 | - return -1; | ||
186 | - } | ||
187 | - //二轮车头肩检测 | ||
188 | - if (!motor_hsprocess_.init(vptParam.gpuid, models_dir)) { | ||
189 | - LOG_FATAL("Init motor_hs failed"); | ||
190 | - return -1; | ||
191 | - } | ||
192 | - | ||
193 | - //二轮车使用手机及加雨棚 | ||
194 | - if (!motor_refit_phoneprocess_.init(vptParam.gpuid, models_dir)) { | ||
195 | - LOG_FATAL("Init motor_phone failed"); | ||
196 | - return -1; | ||
197 | - } | ||
198 | - /* | ||
199 | - //二轮车使用手机检测 | ||
200 | - if (!motor_phoneprocess_.init(vptParam.gpuid, models_dir)) { | ||
201 | - LOG_FATAL("Init motor_phone failed"); | ||
202 | - return -1; | ||
203 | - }*/ | ||
204 | - //电动车改装(加雨棚) | ||
205 | - if (!motor_refitprocess_.init(vptParam.gpuid, models_dir)) { | ||
206 | - LOG_FATAL("Init motor_refit failed"); | ||
207 | - return -1; | ||
208 | - } | ||
209 | - // 行人/二轮车闯红灯 | ||
210 | - if (!traffic_lightprocess_.init(vptParam.gpuid, models_dir)) { | ||
211 | - LOG_FATAL("Init traffic_light failed"); | ||
212 | - return -1; | ||
213 | - } | ||
214 | - // 与道路分割相关的算法 | ||
215 | - if (!roadseg_corrprocess_.init(vptParam.gpuid, models_dir)) { | ||
216 | - LOG_FATAL("Init roadseg_corrprocess failed"); | ||
217 | - return -1; | ||
218 | - } | ||
219 | -#endif | ||
220 | - | ||
221 | - #ifdef WITH_FACE_DET_SS | ||
222 | - // 人脸检测初始化 | ||
223 | - facedet_ai_engine_param fd_param; | ||
224 | - char model_path_yolov5s[100]; | ||
225 | - strcpy(model_path_yolov5s, (models_dir + "/models/face_detect/face_det_yolov5s_310p.om").c_str()); | ||
226 | - fd_param.sdk_param.det_modelNames = model_path_yolov5s; | ||
227 | - char model_path_ldmk[100]; | ||
228 | - strcpy(model_path_ldmk, (models_dir + "/models/face_detect/face_ldmk_310p.om").c_str()); | ||
229 | - fd_param.sdk_param.ldmk_modelNames = model_path_ldmk; | ||
230 | - char model_path_pose[100]; | ||
231 | - strcpy(model_path_pose, (models_dir + "/models/face_detect/face_pose_310p.om").c_str()); | ||
232 | - fd_param.sdk_param.pose_modelNames = model_path_pose; | ||
233 | - char model_path_score[100]; | ||
234 | - strcpy(model_path_score, (models_dir + "/models/face_detect/face_score_310p.om").c_str()); | ||
235 | - fd_param.sdk_param.score_modelNames = model_path_score; | ||
236 | - char model_path_fuzzy[100]; | ||
237 | - strcpy(model_path_fuzzy, (models_dir + "/models/face_detect/face_fuzzy_310p.om").c_str()); | ||
238 | - fd_param.sdk_param.fuzzy_modelNames = model_path_fuzzy; | ||
239 | - char model_path_occlusion[100]; | ||
240 | - strcpy(model_path_occlusion, (models_dir + "/models/face_detect/face_occlusion_310p.om").c_str()); | ||
241 | - fd_param.sdk_param.occlusion_modelNames = model_path_occlusion; | ||
242 | - fd_param.sdk_param.thresld = 0.6; | ||
243 | - fd_param.sdk_param.devId = m_devId; | ||
244 | - fd_param.sdk_param.auth_license = "sy_tongtu_aiplatform_sdk_2023"; | ||
245 | - fd_param.sdk_param.facial_fea_point_config = SY_CONFIG_OPEN; //是否启动关键点检测 | ||
246 | - fd_param.sdk_param.pose_config = SY_CONFIG_OPEN; //是否启动姿态角 | ||
247 | - fd_param.sdk_param.quality_config = SY_CONFIG_OPEN; //是否启动质量检测 | ||
248 | - fd_param.sdk_param.score_config = SY_CONFIG_OPEN; //是否启动人脸置信度 //SY_CONFIG_OPEN SY_CONFIG_CLOSE | ||
249 | - fd_param.sdk_param.max_result_count = 50; | ||
250 | - ret = m_face_det_ai_engine.init_ai_engine(fd_param); | ||
251 | - if (ret < 0 ) { | ||
252 | - LOG_FATAL("Init face detection failed"); | ||
253 | - return ret; | ||
254 | - } | ||
255 | -#endif | ||
256 | - | ||
257 | - m_task_param_manager = task_param_manager::getInstance(); | ||
258 | - m_snapshot_reprocessing = new snapshot_reprocessing(m_devId); | ||
259 | - m_save_snapshot_reprocessing = new save_snapshot_reprocessing(m_devId); | ||
260 | - | ||
261 | -#ifdef POST_USE_RABBITMQ | ||
262 | - mq_manager_ = new mq::Manager(); | ||
263 | -#endif | ||
264 | - | ||
265 | - VPCUtil* pVpcUtil = VPCUtil::getInstance(); | ||
266 | - pVpcUtil->init(m_devId); | ||
267 | - | ||
268 | - m_pAlgorthimThread = new thread([](void* arg) { | ||
269 | - CMultiSourceProcess* process = (CMultiSourceProcess*)arg ; | ||
270 | - process->algorthim_process_thread(); | ||
271 | - return (void*)0; | ||
272 | - } | ||
273 | - , this); | ||
274 | - | ||
275 | - m_recode_thread = new thread([](void* arg) { | ||
276 | - CMultiSourceProcess* process = (CMultiSourceProcess*)arg ; | ||
277 | - process->recode_thread(); | ||
278 | - return (void*)0; | ||
279 | - } | ||
280 | - , this); | ||
281 | - | ||
282 | - m_timing_snapshot_thread = new std::thread( | ||
283 | - [](void* arg) | ||
284 | - { | ||
285 | - CMultiSourceProcess* _this=(CMultiSourceProcess*)arg; | ||
286 | - if(_this != nullptr){ | ||
287 | - _this->timing_snapshot_thread(); | ||
288 | - }else{ | ||
289 | - LOG_ERROR("定时抓拍线程启动失败 !"); | ||
290 | - } | ||
291 | - return (void*)0; | ||
292 | - }, this); | ||
293 | - | ||
294 | - if(nullptr == m_timing_snapshot_thread){ | ||
295 | - LOG_ERROR("定时抓拍线程启动失败 !"); | ||
296 | - } | ||
297 | - | ||
298 | - LOG_INFO("InitAlgorthim succeed !"); | ||
299 | - | ||
300 | - return 0; | ||
301 | -} | ||
302 | - | ||
303 | -#ifdef POST_USE_RABBITMQ | ||
304 | -/* MQ队列的初始化 */ | ||
305 | -int CMultiSourceProcess::AddMqConn(mq_type_t mq_type, rabbitmq_conn_params_t mq_conn_param) { | ||
306 | - /* 初始化MQ队列 */ | ||
307 | - LOG_INFO("初始化MQ队列"); | ||
308 | - if(mq_manager_ == nullptr){ | ||
309 | - LOG_ERROR("mq_manager_ is null"); | ||
310 | - return FAILED; | ||
311 | - } | ||
312 | - | ||
313 | - if (!mq_manager_->add_conn(mq_type, mq_conn_param)) { | ||
314 | - LOG_ERROR("Connection MQ failed, ip: {} port: {} uname: {} passwd: {}", mq_conn_param.ip, mq_conn_param.port, | ||
315 | - mq_conn_param.uname, mq_conn_param.passwd); | ||
316 | - return MQ_CONN_ERROR; | ||
317 | - } | ||
318 | - | ||
319 | - LOG_INFO("为报警类 绑定MQ回调"); | ||
320 | - /* 为报警类 绑定回调 传入mq_manager_.publish 内部直接调用*/ | ||
321 | - if (m_save_snapshot_reprocessing!= nullptr && mq_type_t::ALARM_MQ == mq_type) { | ||
322 | - m_save_snapshot_reprocessing->set_callback( | ||
323 | - std::bind(&mq::Manager::publish, mq_manager_, mq_type, std::placeholders::_1, true)); | ||
324 | - LOG_INFO("为报警类 绑定MQ回调 成功!"); | ||
325 | - } | ||
326 | - | ||
327 | - LOG_INFO("初始化MQ队列成功!"); | ||
328 | - | ||
329 | - return SUCCESS; | ||
330 | -} | ||
331 | - | ||
332 | -/* 获取任务的状态 MQ返回 */ | ||
333 | -int CMultiSourceProcess::GetTaskStatus(const string taskID) { | ||
334 | - | ||
335 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
336 | - | ||
337 | - std::vector<std::string> taskids; | ||
338 | - std::vector<int> statues; | ||
339 | - if(pDecManager->isPausing(taskID)){ | ||
340 | - taskids.emplace_back(taskID); | ||
341 | - statues.emplace_back(2); | ||
342 | - }else if(pDecManager->isRunning(taskID)){ | ||
343 | - taskids.emplace_back(taskID); | ||
344 | - statues.emplace_back(1); | ||
345 | - } | ||
346 | - | ||
347 | - if (!taskids.empty()) { | ||
348 | - auto json_str = helpers::gen_json::gen_task_status_json(taskids, statues); | ||
349 | - mq_manager_->publish(mq_type_t::GET_TASK_MQ, json_str.c_str(),true); | ||
350 | - } | ||
351 | - | ||
352 | - return SUCCESS; | ||
353 | -} | ||
354 | -#endif | ||
355 | - | ||
356 | -bool CMultiSourceProcess::AddTask(task_param _cur_task_param){ | ||
357 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
358 | - | ||
359 | - const char* task_id = _cur_task_param.task_id; | ||
360 | - | ||
361 | - MgrDecConfig config; | ||
362 | - config.name = task_id; | ||
363 | - config.cfg.uri = _cur_task_param.ipc_url; | ||
364 | - config.cfg.post_decoded_cbk = post_decod_cbk; | ||
365 | - config.cfg.decode_finished_cbk = decode_finished_cbk; | ||
366 | - config.cfg.force_tcp = true; // rtsp用tcp | ||
367 | - config.cfg.gpuid = to_string(m_devId); | ||
368 | - config.cfg.skip_frame = skip_frame_; | ||
369 | - | ||
370 | - if (1 == _cur_task_param.dec_type){ | ||
371 | - config.cfg.port = _cur_task_param.port; | ||
372 | - config.dec_type = DECODER_TYPE_GB28181; | ||
373 | - config.cfg.uri = task_id; | ||
374 | - if(_cur_task_param.protocal == 0){ | ||
375 | - // 指定用udp协议 | ||
376 | - config.cfg.force_tcp = false; | ||
377 | - } | ||
378 | - config.cfg.request_stream_cbk = _cur_task_param.gb28181_request_stream_callback ; | ||
379 | - }else if (2 == _cur_task_param.dec_type){ | ||
380 | - config.dec_type = DECODER_TYPE_DVPP; | ||
381 | - }else { | ||
382 | - config.dec_type = DECODER_TYPE_FFMPEG; | ||
383 | - } | ||
384 | - | ||
385 | - AbstractDecoder* dec = pDecManager->createDecoder(config); | ||
386 | - if (!dec){ | ||
387 | - return false; | ||
388 | - } | ||
389 | - | ||
390 | - decode_cbk_userdata* userPtr = new decode_cbk_userdata; | ||
391 | - userPtr->task_id = string(task_id); | ||
392 | - userPtr->opaque = this; | ||
393 | - userPtr->opaque1 = dec; | ||
394 | - pDecManager->setPostDecArg(config.name, userPtr); | ||
395 | - pDecManager->setFinishedDecArg(config.name, userPtr); | ||
396 | - | ||
397 | - // pDecManager->setDecKeyframe(config.name, true); // 只对关键帧解码 | ||
398 | - | ||
399 | - | ||
400 | - // 保存新添加任务的配置参数 | ||
401 | - m_task_param_manager->add_task_param(task_id, _cur_task_param); | ||
402 | - | ||
403 | - int input_image_width = 0; | ||
404 | - int input_image_height = 0; | ||
405 | - pDecManager->getResolution(config.name, input_image_width, input_image_height); | ||
406 | - LOG_INFO("task_id: {} width: {} height:{}", task_id, input_image_width, input_image_height); | ||
407 | - | ||
408 | - // 所有参数都准备好之后再启动解码 | ||
409 | - bool bStart = pDecManager->startDecodeByName(config.name); | ||
410 | - if (!bStart){ | ||
411 | - LOG_INFO("started task {} failed!", config.name); | ||
412 | - pDecManager->closeDecoderByName(config.name); | ||
413 | - return false; | ||
414 | - } | ||
415 | - | ||
416 | -#ifdef POST_USE_RABBITMQ | ||
417 | - mq_type_t mq_type = mq_type_t::ALARM_MQ; | ||
418 | - pDecManager->set_mq_callback(config.name, std::bind(&mq::Manager::publish, mq_manager_, mq_type, std::placeholders::_1, true)); | ||
419 | -#endif | ||
420 | - | ||
421 | - // 人车物跟踪 | ||
422 | - if (task_has_vpt_algor(task_id)) | ||
423 | - vpt_process.addTaskTracker(task_id, 1, 1, skip_frame_); | ||
424 | - | ||
425 | - // 人脸跟踪 | ||
426 | -#ifdef WITH_FACE_DET_SS | ||
427 | - if (task_has_face_algor(task_id)) | ||
428 | - m_face_det_ai_engine.add_tracker(task_id, skip_frame_); // 跳帧数暂时写死 | ||
429 | -#endif | ||
430 | - | ||
431 | - m_FinishedTaskMtx.lock(); | ||
432 | - m_FinishedTaskMap[task_id] = false; | ||
433 | - m_FinishedTaskMtx.unlock(); | ||
434 | - | ||
435 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
436 | - if (algor_map != nullptr){ | ||
437 | - /* 如果开启了行人 机动车非法闯入功能 生成闯入区域mask */ | ||
438 | - if (algor_map->find(algorithm_type_t::PEDESTRIAN_TRESPASS) != algor_map->end()) { | ||
439 | - pedestrian_vehicle_trespass_.pedestrianvehicletrespass_init_region( | ||
440 | - task_id, algorithm_type_t::PEDESTRIAN_TRESPASS, input_image_width, input_image_height); | ||
441 | - } | ||
442 | - | ||
443 | - if (algor_map->find(algorithm_type_t::VEHICLE_TRESPASS) != algor_map->end()) { | ||
444 | - pedestrian_vehicle_trespass_.pedestrianvehicletrespass_init_region( | ||
445 | - task_id, algorithm_type_t::VEHICLE_TRESPASS, input_image_width, input_image_height); | ||
446 | - } | ||
447 | - | ||
448 | - // 设置定时截图的时间间隔 | ||
449 | - auto algor = algor_map->find(algorithm_type_t::VIDEO_TIMING_SNAPSHOT); | ||
450 | - if(algor != algor_map->end()){ | ||
451 | - task_param_manager::algo_param_type_t_* cur_task_params = algor->second; | ||
452 | - if(cur_task_params){ | ||
453 | - int frame_stride = ((algor_config_video_timing_snapshot*)cur_task_params->algor_param)->frame_stride; | ||
454 | - LOG_INFO("task {} snap time interval: {} s", config.name, frame_stride); | ||
455 | - // 单位是ms, 乘以 1000 编成s | ||
456 | - dec->setSnapTimeInterval(frame_stride * 1000); | ||
457 | - } | ||
458 | - } | ||
459 | - | ||
460 | - // 测试代码 | ||
461 | - // auto algor_face = algor_map->find(algorithm_type_t::FACE_SNAPSHOT); | ||
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; | ||
464 | - // LOG_INFO("face_snapshot, result_folder: {} result_folder_little: {}", cur_param->result_folder, cur_param->result_folder_little); | ||
465 | - // } | ||
466 | - } | ||
467 | - | ||
468 | - LOG_INFO("started task {} successed!", config.name); | ||
469 | - | ||
470 | - return true; | ||
471 | -} | ||
472 | - | ||
473 | -int CMultiSourceProcess::CountRunningTask() { | ||
474 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
475 | - return pDecManager->count(); | ||
476 | -} | ||
477 | - | ||
478 | -bool CMultiSourceProcess::task_has_vpt_algor(const std::string &task_id){ | ||
479 | - //! TODO: create enum iterator. | ||
480 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
481 | - if (algor_map == nullptr) | ||
482 | - return false; | ||
483 | - | ||
484 | - return (algor_map->find(algorithm_type_t::HUMAN_GATHER) != algor_map->end() || | ||
485 | - algor_map->find(algorithm_type_t::HUMAN_SNAPSHOT) != algor_map->end() || | ||
486 | - algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT) != algor_map->end() || | ||
487 | - algor_map->find(algorithm_type_t::SMOKING_DET) != algor_map->end() || | ||
488 | - algor_map->find(algorithm_type_t::NO_REFLECTIVE_CLOTHING) != algor_map->end() || | ||
489 | - algor_map->find(algorithm_type_t::NO_SAFETY_HELMET) != algor_map->end() || | ||
490 | - algor_map->find(algorithm_type_t::CALL_PHONE_DET) != algor_map->end() || | ||
491 | - algor_map->find(algorithm_type_t::VEHICLE_SNAPSHOT) != algor_map->end() || | ||
492 | - algor_map->find(algorithm_type_t::TAKEAWAY_MEMBER_CLASSIFICATION) != algor_map->end() || | ||
493 | - algor_map->find(algorithm_type_t::PEDESTRIAN_FALL) != algor_map->end() || | ||
494 | - algor_map->find(algorithm_type_t::PEDESTRIAN_FIGHT) != algor_map->end() || | ||
495 | - algor_map->find(algorithm_type_t::PEDESTRIAN_RETROGRADE) != algor_map->end() || | ||
496 | - algor_map->find(algorithm_type_t::VEHICLE_RETROGRADE) != algor_map->end() || | ||
497 | - algor_map->find(algorithm_type_t::PEDESTRIAN_TRESPASS) != algor_map->end() || | ||
498 | - algor_map->find(algorithm_type_t::VEHICLE_TRESPASS) != algor_map->end() || | ||
499 | - algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET) != algor_map->end() || | ||
500 | - algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN) != algor_map->end() || | ||
501 | - algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != algor_map->end() || | ||
502 | - algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) != algor_map->end() || | ||
503 | - algor_map->find(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) != algor_map->end() || | ||
504 | - algor_map->find(algorithm_type_t::NONMOTOR_CEOSSPARKLINE) != algor_map->end() || | ||
505 | - algor_map->find(algorithm_type_t::NONMOTOR_IN_VEHICLELANE) != algor_map->end() || | ||
506 | - algor_map->find(algorithm_type_t::NONMOTOR_WRONGDIRECTION) != algor_map->end() || | ||
507 | - algor_map->find(algorithm_type_t::PERSON_IN_VEHICLELANE) != algor_map->end() || | ||
508 | - algor_map->find(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) != algor_map->end() || | ||
509 | - algor_map->find(algorithm_type_t::PERSON_CROSS) != algor_map->end() || | ||
510 | - algor_map->find(algorithm_type_t::VEHICLE_WRONGDIRECTION) != algor_map->end() || | ||
511 | - algor_map->find(algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) != algor_map->end() || | ||
512 | - algor_map->find(algorithm_type_t::VEHICLE_NOTGIVEWAY) != algor_map->end() || | ||
513 | - algor_map->find(algorithm_type_t::VEHICLE_NOTDECELERATION) != algor_map->end() || | ||
514 | - algor_map->find(algorithm_type_t::TRICYCLE_MANNED) != algor_map->end() || | ||
515 | - algor_map->find(algorithm_type_t::TRUCK_MANNED) != algor_map->end()); | ||
516 | -} | ||
517 | - | ||
518 | -bool CMultiSourceProcess::task_has_face_algor(const std::string &task_id){ | ||
519 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
520 | - if (nullptr != algor_map){ | ||
521 | - return algor_map->find(algorithm_type_t::FACE_SNAPSHOT) != algor_map->end(); | ||
522 | - } | ||
523 | - | ||
524 | - return false; | ||
525 | -} | ||
526 | - | ||
527 | -void CMultiSourceProcess::decoded_cbk(DeviceMemory* devFrame){ | ||
528 | - | ||
529 | - do{ | ||
530 | - if(m_bfinish){ | ||
531 | - break; | ||
532 | - } | ||
533 | - m_DataListMtx.lock(); | ||
534 | - if(m_RgbDataList.size() >= 100){ //缓存100帧 | ||
535 | - m_DataListMtx.unlock(); | ||
536 | - std::this_thread::sleep_for(std::chrono::milliseconds(3)); | ||
537 | - continue; | ||
538 | - } | ||
539 | - m_RgbDataList.push_back(devFrame); | ||
540 | - m_DataListMtx.unlock(); | ||
541 | - break; | ||
542 | - }while (true); | ||
543 | -} | ||
544 | - | ||
545 | -void CMultiSourceProcess::task_finished(const string task_id){ | ||
546 | - | ||
547 | - std::lock_guard<std::mutex> l(m_FinishedTaskMtx); | ||
548 | - | ||
549 | - m_FinishedTaskMap[task_id] = true; | ||
550 | - | ||
551 | - LOG_INFO("task {} finished!", task_id); | ||
552 | -} | ||
553 | - | ||
554 | -bool CMultiSourceProcess::PauseTask(const string taskID){ | ||
555 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
556 | - return pDecManager->pauseDecoder(taskID); | ||
557 | -} | ||
558 | - | ||
559 | -bool CMultiSourceProcess::RestartTask(const string taskID){ | ||
560 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
561 | - return pDecManager->resumeDecoder(taskID); | ||
562 | -} | ||
563 | - | ||
564 | -bool CMultiSourceProcess::FinishTask(const string taskID){ | ||
565 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
566 | - // return pDecManager->closeDecoderByName(taskID); | ||
567 | - | ||
568 | - // 记录主动结束的任务 | ||
569 | - bool flag = pDecManager->closeDecoderByName(taskID); | ||
570 | -#ifdef POST_USE_RABBITMQ | ||
571 | - if (flag) { | ||
572 | - std::lock_guard<std::mutex> l1(m_ActiveFinishedTaskMtx); | ||
573 | - m_ActiveFinishedTaskMap[taskID] = true; | ||
574 | - } | ||
575 | -#endif | ||
576 | - return flag; | ||
577 | -} | ||
578 | - | ||
579 | -int CMultiSourceProcess::snapshot_task(std::string& uri_or_name, const std::string& file_name, bool bInTask) { | ||
580 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
581 | - | ||
582 | - DeviceMemory* devMem = nullptr; | ||
583 | - if(bInTask) { | ||
584 | - LOG_INFO("snap in task"); | ||
585 | - devMem = pDecManager->snapshot_in_task(uri_or_name); | ||
586 | - } else { | ||
587 | - LOG_INFO("snap out task"); | ||
588 | - devMem = pDecManager->snapshot_out_task(uri_or_name, m_devId); | ||
589 | - } | ||
590 | - if(devMem != nullptr) { | ||
591 | - JpegUtil jpegUtil; | ||
592 | - jpegUtil.jpeg_init(m_devId); | ||
593 | - | ||
594 | - acldvppPicDesc *vpcDesc= acldvppCreatePicDesc(); | ||
595 | - acldvppSetPicDescData(vpcDesc, devMem->getMem()); | ||
596 | - acldvppSetPicDescFormat(vpcDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420); | ||
597 | - acldvppSetPicDescWidth(vpcDesc, devMem->getWidth()); | ||
598 | - acldvppSetPicDescHeight(vpcDesc, devMem->getHeight()); | ||
599 | - acldvppSetPicDescWidthStride(vpcDesc, devMem->getWidthStride()); | ||
600 | - acldvppSetPicDescHeightStride(vpcDesc, devMem->getHeightStride()); | ||
601 | - acldvppSetPicDescSize(vpcDesc, devMem->getSize()); | ||
602 | - | ||
603 | - jpegUtil.jpeg_encode(vpcDesc, file_name); | ||
604 | - | ||
605 | - acldvppDestroyPicDesc(vpcDesc); | ||
606 | - | ||
607 | - jpegUtil.jpeg_release(); | ||
608 | - | ||
609 | - delete devMem; | ||
610 | - devMem = nullptr; | ||
611 | - | ||
612 | - return SUCCESS; | ||
613 | - } | ||
614 | - | ||
615 | - return FAILED; | ||
616 | -} | ||
617 | - | ||
618 | -int CMultiSourceProcess::SnapShot(task_param _cur_task_param) { | ||
619 | - LOG_INFO("begin SnapShot task: {}", _cur_task_param.task_id); | ||
620 | - | ||
621 | - /* 添加任务参数 */ | ||
622 | - auto &algor_config_param = _cur_task_param.algor_config_params[0]; // 默认算法数量为1 | ||
623 | - | ||
624 | - /* 拷贝通用的算法参数 */ | ||
625 | - auto src_basic_param = algor_config_param.algor_init_config_param->basic_param; | ||
626 | - if (src_basic_param->result_folder) { | ||
627 | - CreateResultFolder(src_basic_param->result_folder, ""); | ||
628 | - } else { | ||
629 | - src_basic_param->result_folder = ""; | ||
630 | - } | ||
631 | - | ||
632 | - std::string cur_timestamp_ms = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>()); | ||
633 | - std::string file_name = std::string(src_basic_param->result_folder) + helpers::os::sep + _cur_task_param.task_id + "_snap_" + cur_timestamp_ms + ".jpg"; | ||
634 | - | ||
635 | - // file_name = "/mnt/data/cmhu/tongtu/Linux_3rdparty/tsl_sdk_20220801/res/snap.jpg"; | ||
636 | - string task_id = _cur_task_param.task_id; | ||
637 | - int bSnapShot = snapshot_task(task_id, file_name, true); | ||
638 | - if (FAILED == bSnapShot){ | ||
639 | - string url = _cur_task_param.ipc_url; | ||
640 | - bSnapShot = snapshot_task(url, file_name, false); | ||
641 | - } | ||
642 | - if(SUCCESS == bSnapShot){ | ||
643 | -#ifdef POST_USE_RABBITMQ | ||
644 | - auto json_str = helpers::gen_json::gen_screen_json(task_id, file_name); | ||
645 | - // mq_manager_->publish(mq_type_t::GET_TASK_MQ, json_str.c_str(), true); | ||
646 | - mq_manager_->publish(mq_type_t::SCREENSHORT_TASK_MQ, json_str.c_str(), true); | ||
647 | -#endif | ||
648 | - LOG_INFO("SnapShot task: {} success", task_id); | ||
649 | - } else { | ||
650 | - LOG_ERROR("SnapShot task: {} failed !", task_id); | ||
651 | - } | ||
652 | - | ||
653 | - return bSnapShot; | ||
654 | -} | ||
655 | - | ||
656 | -void CMultiSourceProcess::CloseAllTask(){ | ||
657 | - m_bfinish = true; | ||
658 | - atlas_licence_close(&(skt_handle)); //授权 | ||
659 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
660 | - pDecManager->closeAllDecoder(); | ||
661 | - | ||
662 | - if(m_pAlgorthimThread){ | ||
663 | - m_pAlgorthimThread->join(); | ||
664 | - m_pAlgorthimThread = nullptr; | ||
665 | - } | ||
666 | - | ||
667 | - if(m_recode_thread){ | ||
668 | - m_recode_thread->join(); | ||
669 | - m_recode_thread = nullptr; | ||
670 | - } | ||
671 | - | ||
672 | - if(m_timing_snapshot_thread != nullptr && m_timing_snapshot_thread->joinable()){ | ||
673 | - m_timing_snapshot_thread->join(); | ||
674 | - m_timing_snapshot_thread = nullptr; | ||
675 | - } | ||
676 | - | ||
677 | - m_DataListMtx.lock(); | ||
678 | - while (!m_RgbDataList.empty()){ | ||
679 | - DeviceMemory* gpuMem = m_RgbDataList.front(); | ||
680 | - delete gpuMem; | ||
681 | - gpuMem = nullptr; | ||
682 | - m_RgbDataList.pop_front(); | ||
683 | - } | ||
684 | - m_DataListMtx.unlock(); | ||
685 | - | ||
686 | - int size = m_RgbDataList.size(); | ||
687 | - bool bEmpty = m_RgbDataList.empty(); | ||
688 | - | ||
689 | - LOG_INFO("CloseAllTask exit."); | ||
690 | -} | ||
691 | - | ||
692 | -void CMultiSourceProcess::CloseAllTask2() { | ||
693 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
694 | - pDecManager->closeAllDecoder(); | ||
695 | -} | ||
696 | - | ||
697 | -void CMultiSourceProcess::clear_finished_task(){// 清理已经结束的任务 | ||
698 | - | ||
699 | - std::lock_guard<std::mutex> l1(m_FinishedTaskMtx); | ||
700 | - std::lock_guard<std::mutex> l2(m_DataListMtx); | ||
701 | - | ||
702 | - for (auto iter_finished = m_FinishedTaskMap.begin(); iter_finished!=m_FinishedTaskMap.end(); ){ | ||
703 | - if(iter_finished->second){ | ||
704 | - // 解码已经结束 | ||
705 | - // 判断数据对列中是否还有数据 | ||
706 | - string task_id = iter_finished->first; | ||
707 | - bool bFinished = true; | ||
708 | - for (auto iter = m_RgbDataList.begin(); iter!=m_RgbDataList.end(); ++ iter){ | ||
709 | - DeviceMemory* gpuMem = *iter; | ||
710 | - if(task_id == gpuMem->getId()){ | ||
711 | - bFinished = false; | ||
712 | - break; | ||
713 | - } | ||
714 | - } | ||
715 | - | ||
716 | - if (bFinished){ | ||
717 | - // 解码器已经结束,且数据队列中没有改任务的数据,则做最后任务清理工作 | ||
718 | - finish_task(task_id,false); | ||
719 | - iter_finished = m_FinishedTaskMap.erase(iter_finished); | ||
720 | - continue; | ||
721 | - } | ||
722 | - } | ||
723 | - | ||
724 | - ++ iter_finished; | ||
725 | - } | ||
726 | -} | ||
727 | - | ||
728 | -bool CMultiSourceProcess::finish_task(const string taskID, const bool delete_snapshot){ | ||
729 | - | ||
730 | - // 任务结束,关闭跟踪 | ||
731 | - if (!vpt_process.finishTaskTracker(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 | ||
739 | - | ||
740 | -#ifdef POST_USE_RABBITMQ | ||
741 | - { | ||
742 | - // 外部主动结束的任务不推送mq | ||
743 | - std::lock_guard<std::mutex> mlock(m_ActiveFinishedTaskMtx); | ||
744 | - if (!(m_ActiveFinishedTaskMap.count(taskID) && m_ActiveFinishedTaskMap[taskID])) { | ||
745 | - auto json_str = helpers::gen_json::gen_office_task_heart_beat_json({taskID}); | ||
746 | - mq_manager_->publish(mq_type_t::HEART_BEAT_MQ, json_str.c_str(), true); | ||
747 | - } | ||
748 | - if (m_ActiveFinishedTaskMap.count(taskID)) m_ActiveFinishedTaskMap.erase(taskID); | ||
749 | - } | ||
750 | -#endif | ||
751 | - | ||
752 | -// #ifdef WITH_SECOND_PROCESS | ||
753 | - pedestrian_vehicle_retrograde_.force_release_result(taskID); //221024 byzsh | ||
754 | -// #endif | ||
755 | -#ifdef USE_VILLAGE | ||
756 | - tricycle_manned_.force_release_result(taskID); | ||
757 | - truck_manned_.force_release_result(taskID); | ||
758 | - motor_hsprocess_.force_release_result(taskID); | ||
759 | - motor_refit_phoneprocess_.force_release_result(taskID); | ||
760 | - // motor_phoneprocess_.force_release_result(taskID); | ||
761 | - motor_refitprocess_.force_release_result(taskID); | ||
762 | - traffic_lightprocess_.force_release_result(taskID); | ||
763 | - roadseg_corrprocess_.force_release_result(taskID); | ||
764 | - | ||
765 | - m_RoadSegTaskMtx.lock(); | ||
766 | - if (m_RoadSegTaskMap.count(taskID)) { | ||
767 | - for (int i = 0; i < m_RoadSegTaskMap[taskID].traffic_region.size(); i++) { | ||
768 | - vector<int>().swap(m_RoadSegTaskMap[taskID].traffic_region[i]); | ||
769 | - } | ||
770 | - for (int i = 0; i < m_RoadSegTaskMap[taskID].fence_region.size(); i++) { | ||
771 | - vector<int>().swap(m_RoadSegTaskMap[taskID].fence_region[i]); | ||
772 | - } | ||
773 | - vector<int>().swap(m_RoadSegTaskMap[taskID].labels); | ||
774 | - vector<int>().swap(m_RoadSegTaskMap[taskID].fence_labels); | ||
775 | - vector<vector<int>>().swap(m_RoadSegTaskMap[taskID].traffic_region); | ||
776 | - vector<vector<int>>().swap(m_RoadSegTaskMap[taskID].fence_region); | ||
777 | - m_RoadSegTaskMap.erase(taskID); | ||
778 | - } | ||
779 | - m_RoadSegTaskMtx.unlock(); | ||
780 | - m_TotalObjMtx.lock(); | ||
781 | - for(auto ss = m_total_obj_info.begin(); ss != m_total_obj_info.end(); ) { | ||
782 | - if (strcmp(ss->first.video_id.c_str(), taskID.c_str()) == 0) { | ||
783 | - vector<sy_point>().swap(ss->second.center_points); | ||
784 | - m_total_obj_info.erase(ss++); | ||
785 | - } | ||
786 | - else ss++; | ||
787 | - } | ||
788 | - m_TotalObjMtx.unlock(); | ||
789 | -#endif | ||
790 | - m_task_param_manager->delete_task_param(taskID); | ||
791 | - m_snapshot_reprocessing->release_finished_locus_snapshot(taskID); | ||
792 | - m_snapshot_reprocessing->release_finished_face_locus_snapshot(taskID); | ||
793 | - m_snapshot_reprocessing->release_village_finished_locus_snapshot(taskID); | ||
794 | - | ||
795 | - return true; | ||
796 | -} | ||
797 | - | ||
798 | -int CMultiSourceProcess::algorthim_process_thread(){ | ||
799 | - LOG_INFO("algorthim_process_thread start..."); | ||
800 | - | ||
801 | - ACL_CALL(aclrtSetDevice(m_devId), ACL_SUCCESS, 1); | ||
802 | - aclrtContext ctx; | ||
803 | - ACL_CALL(aclrtCreateContext(&ctx, m_devId), ACL_SUCCESS, 1); | ||
804 | - | ||
805 | - while (true){ | ||
806 | -#ifdef USE_VILLAGE | ||
807 | - if (!CheckTime()) { | ||
808 | - LOG_FATAL("authority failed!"); | ||
809 | - break; | ||
810 | - } | ||
811 | -#else | ||
812 | - //授权相关------------------------------------ | ||
813 | - if(check_label == -1) { | ||
814 | - printf("sy_atlas_licence_check failed.\n"); | ||
815 | - break; | ||
816 | - } | ||
817 | - //获取系统时间,每个月1号check一次授权 | ||
818 | - struct tm* info; | ||
819 | - int nYear, nMonth, nDay; | ||
820 | - time_t raw; | ||
821 | - time(&raw); | ||
822 | - info = localtime(&raw); | ||
823 | - //nYear = info->tm_year + 1900; | ||
824 | - //nMonth = info->tm_mon + 1; | ||
825 | - nDay = info->tm_mday; | ||
826 | - if(nDay==1) { | ||
827 | - if(check_label ==0) { | ||
828 | - std::cout << "atlas_licence_check start." << std::endl; | ||
829 | - atlas_licence_check_result check_result; | ||
830 | - memset(&check_result, 0, sizeof(atlas_licence_check_result)); | ||
831 | - check_result.code = -1; | ||
832 | - | ||
833 | - int res = atlas_licence_check(skt_handle, check_param, &check_result); | ||
834 | - if(res!=0) { | ||
835 | - std::cout << "sy_licence_check failed." << std::endl; | ||
836 | - break; | ||
837 | - } | ||
838 | - //std::cout << "code:" << check_result.code << ",msg:" << check_result.msg << std::endl; | ||
839 | - if(check_result.code!=0) { | ||
840 | - check_label = -1; | ||
841 | - std::cout << "code:" << check_result.code << ",msg:" << check_result.msg << std::endl; | ||
842 | - break; | ||
843 | - } | ||
844 | - std::cout << "atlas_licence_check end." << std::endl; | ||
845 | - check_label =1; | ||
846 | - } | ||
847 | - } | ||
848 | - else { | ||
849 | - check_label =0; | ||
850 | - } | ||
851 | - //授权相关------------------------------------ | ||
852 | -#endif | ||
853 | - if(m_bfinish){ | ||
854 | - break; | ||
855 | - } | ||
856 | - | ||
857 | - clear_finished_task(); | ||
858 | - | ||
859 | - vector<DeviceMemory*> vec_gpuMem; | ||
860 | - m_DataListMtx.lock(); | ||
861 | - | ||
862 | - while (!m_RgbDataList.empty()){ | ||
863 | - DeviceMemory* gpuMem = m_RgbDataList.front(); | ||
864 | - // if(gpuMem->getMem() == nullptr) { | ||
865 | - if(gpuMem->getMem() == nullptr || gpuMem->getFrameNb() % skip_frame_) { //跳帧 | ||
866 | - // 错误数据,直接删除 | ||
867 | - if(gpuMem->getMem() == nullptr) LOG_WARN("mem is null"); | ||
868 | - delete gpuMem; | ||
869 | - gpuMem = nullptr; | ||
870 | - } else { | ||
871 | - vec_gpuMem.push_back(gpuMem); | ||
872 | - } | ||
873 | - | ||
874 | - m_RgbDataList.pop_front(); | ||
875 | - if(vec_gpuMem.size() >= m_batch_size){ | ||
876 | - break; | ||
877 | - } | ||
878 | - } | ||
879 | - m_DataListMtx.unlock(); | ||
880 | - | ||
881 | - if(vec_gpuMem.size() <= 0){ | ||
882 | - std::this_thread::sleep_for(std::chrono::milliseconds(3)); | ||
883 | - continue; | ||
884 | - } | ||
885 | - | ||
886 | - aclrtSetCurrentContext(ctx); | ||
887 | - // auto record_t1 = std::chrono::system_clock::now(); | ||
888 | -#ifdef USE_VILLAGE | ||
889 | - algorthim_road_seg(vec_gpuMem); | ||
890 | -#endif | ||
891 | - auto vptprocess1 = std::chrono::system_clock::now(); | ||
892 | - algorthim_vpt(vec_gpuMem); | ||
893 | - auto vptprocess2 = std::chrono::system_clock::now(); | ||
894 | - auto vptprocess_time = std::chrono::duration_cast<std::chrono::milliseconds>(vptprocess2 - vptprocess1).count(); | ||
895 | - LOG_INFO("Process per frame cost time: {} ms fps: {}", vptprocess_time/vec_gpuMem.size(), 1000/(vptprocess_time/vec_gpuMem.size())); | ||
896 | - | ||
897 | -#ifdef WITH_FACE_DET_SS | ||
898 | - algorthim_face_detect(vec_gpuMem); | ||
899 | -#endif | ||
900 | - // auto record_t2 = std::chrono::system_clock::now(); | ||
901 | - // auto record_time = std::chrono::duration_cast<std::chrono::milliseconds>(record_t2 - record_t1).count(); | ||
902 | - // LOG_INFO("Record per frame cost time: {} ms fps: {}", record_time/vec_gpuMem.size(), 1000/(record_time/vec_gpuMem.size())); | ||
903 | - for(int i=0;i < vec_gpuMem.size(); i++){ | ||
904 | - DeviceMemory* mem = vec_gpuMem[i]; | ||
905 | - if(mem->getSize() <= 0){ | ||
906 | - continue; | ||
907 | - } | ||
908 | - delete mem; | ||
909 | - mem = nullptr; | ||
910 | - } | ||
911 | - vec_gpuMem.clear(); | ||
912 | - vector<DeviceMemory*>().swap(vec_gpuMem); // free. | ||
913 | - | ||
914 | - } | ||
915 | - | ||
916 | - aclrtDestroyContext(ctx); | ||
917 | - aclrtResetDevice(m_devId); | ||
918 | - LOG_INFO("algorthim_process_thread exit."); | ||
919 | - | ||
920 | - return 0; | ||
921 | -} | ||
922 | - | ||
923 | - | ||
924 | -int CMultiSourceProcess::algorthim_road_seg(vector<DeviceMemory*> vec_gpuMem) { | ||
925 | - | ||
926 | - vector<string> roadSeg_task_id; | ||
927 | - vector<sy_img> roadSeg_imgs; | ||
928 | - vector<DeviceMemory*> vec_segMem; | ||
929 | - m_RoadSegTaskMtx.lock(); | ||
930 | - for (int i = 0; i < vec_gpuMem.size(); i++) { | ||
931 | - DeviceMemory* mem = vec_gpuMem[i]; | ||
932 | - long long frame_number = mem->getFrameNb(); | ||
933 | - if (m_RoadSegTaskMap[mem->getId()].isseg && frame_number % 15000) { //10min重复一次 | ||
934 | - continue; | ||
935 | - } | ||
936 | - LOG_INFO("task: {} frame_num: {} perform road_seg.", mem->getId(), mem->getFrameNb()); | ||
937 | - sy_img img; | ||
938 | - img.w_ = mem->getWidth(); img.h_ = mem->getHeight(); | ||
939 | - img.c_ = mem->getChannel(); img.data_ = mem->getMem(); | ||
940 | - roadSeg_imgs.push_back(img); | ||
941 | - roadSeg_task_id.push_back(mem->getId()); | ||
942 | - vec_segMem.push_back(mem); | ||
943 | - m_RoadSegTaskMap[mem->getId()].isseg = true; // | ||
944 | - } | ||
945 | - m_RoadSegTaskMtx.unlock(); | ||
946 | - | ||
947 | - /* 待检测的图片不为空 开始检测 */ | ||
948 | - if (!roadSeg_imgs.empty()) { | ||
949 | - vector<vector<vector<int>>> traffic_region, fence_region; //道路区域(多个) | ||
950 | - vector<vector<int>> labels, fence_labels; //道路区域对应的类别:机动车道、非机动车道等 | ||
951 | - seg_process.process_gpu(roadSeg_imgs.data(), vec_segMem, roadSeg_task_id, traffic_region, labels); | ||
952 | - seg3cls_process.process_gpu(roadSeg_imgs.data(), vec_segMem, roadSeg_task_id, fence_region, fence_labels); | ||
953 | - | ||
954 | - int bidx = 0; | ||
955 | - m_RoadSegTaskMtx.lock(); | ||
956 | - for (auto _task_id_iter = roadSeg_task_id.begin(); _task_id_iter != roadSeg_task_id.end(); ++_task_id_iter, ++ bidx) { | ||
957 | - auto task_id = *_task_id_iter; | ||
958 | - m_RoadSegTaskMap[task_id].traffic_region.assign(traffic_region[bidx].begin(), traffic_region[bidx].end()); | ||
959 | - m_RoadSegTaskMap[task_id].labels.assign(labels[bidx].begin(), labels[bidx].end()); | ||
960 | - m_RoadSegTaskMap[task_id].fence_region.assign(fence_region[bidx].begin(), fence_region[bidx].end()); | ||
961 | - m_RoadSegTaskMap[task_id].fence_labels.assign(fence_labels[bidx].begin(), fence_labels[bidx].end()); | ||
962 | - m_RoadSegTaskMap[task_id].isseg = true; | ||
963 | - } | ||
964 | - m_RoadSegTaskMtx.unlock(); | ||
965 | - } | ||
966 | - vec_segMem.clear(); | ||
967 | - roadSeg_task_id.clear(); | ||
968 | - roadSeg_imgs.clear(); | ||
969 | - | ||
970 | - return 0; | ||
971 | -} | ||
972 | - | ||
973 | -int CMultiSourceProcess::algorthim_vpt(vector<DeviceMemory*> vec_gpuMem){ | ||
974 | - | ||
975 | - vector<string> vpt_interest_task_id; | ||
976 | - vector<sy_img> vpt_interest_imgs; | ||
977 | - vector<DeviceMemory*> vec_vptMem; | ||
978 | - for (int i = 0; i < vec_gpuMem.size(); i++) { | ||
979 | - DeviceMemory* mem = vec_gpuMem[i]; | ||
980 | - if (!task_has_vpt_algor(mem->getId())){ | ||
981 | - continue; | ||
982 | - } | ||
983 | - | ||
984 | - sy_img img; | ||
985 | - img.w_ = mem->getWidth(); img.h_ = mem->getHeight(); | ||
986 | - img.c_ = mem->getChannel(); img.data_ = mem->getMem(); | ||
987 | - vpt_interest_imgs.push_back(img); | ||
988 | - vpt_interest_task_id.push_back(mem->getId()); | ||
989 | - vec_vptMem.push_back(mem); | ||
990 | - } | ||
991 | - | ||
992 | - /* 待检测的图片不为空 开始检测 */ | ||
993 | - if (!vpt_interest_imgs.empty()) { | ||
994 | - vector<vector<int>> deleteObjectID; | ||
995 | - deleteObjectID.resize(vpt_interest_task_id.size()); | ||
996 | - vector<vector<onelevel_det_result>> unUsedResult; | ||
997 | - vector<onelevel_det_result> vptResult(0); | ||
998 | - | ||
999 | - /* 一级检测器,内部已完成跟踪操作 */ | ||
1000 | - vpt_process.process_gpu(vpt_interest_imgs.data(), vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // do det & track. | ||
1001 | - // vpt_process.process_gpu(vpt_interest_imgs.data(), vec_vptMem, vpt_interest_task_id, vptResult, deleteObjectID, unUsedResult); // debug | ||
1002 | - m_snapshot_reprocessing->screen_effective_snapshot(vptResult); | ||
1003 | - | ||
1004 | -#ifndef VEHICLE_MULTI_BOXES | ||
1005 | - /* 快照优选(内部可实现不同的快照优选策略) */ | ||
1006 | - m_snapshot_reprocessing->update_bestsnapshot(vec_vptMem, vptResult, deleteObjectID); | ||
1007 | - /* for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径)*/ | ||
1008 | - vehicle_snapshot(vpt_interest_task_id, deleteObjectID); | ||
1009 | -#else | ||
1010 | - algorithm_vehicle_relult(vec_vptMem, vptResult, deleteObjectID); | ||
1011 | - | ||
1012 | - send_locus_finished_msg(vpt_interest_task_id, deleteObjectID); | ||
1013 | -#endif | ||
1014 | - | ||
1015 | -// #ifdef WITH_SECOND_PROCESS | ||
1016 | - /* for pedestrian safety det. 行人安全分析算法模块 */ | ||
1017 | - // algorthim_pedestrian_safety(vpt_interest_task_id, vpt_interest_imgs,vptResult); | ||
1018 | - | ||
1019 | - // 逆行 | ||
1020 | - algorthim_retrograde(vpt_interest_task_id, vec_vptMem, vptResult); | ||
1021 | - retrograde_snapshot(vpt_interest_task_id, deleteObjectID); | ||
1022 | - // 闯入 | ||
1023 | - algorthim_trespass(vpt_interest_task_id, vec_vptMem, vptResult, deleteObjectID); | ||
1024 | - trespass_snapshot(vpt_interest_task_id, deleteObjectID); | ||
1025 | - | ||
1026 | -// #endif | ||
1027 | -#ifdef USE_VILLAGE | ||
1028 | - // 轨迹记录 | ||
1029 | - trace_record(vpt_interest_task_id, vptResult); | ||
1030 | - // 农村违法分析的快照缓存 | ||
1031 | - m_snapshot_reprocessing->update_village_bestsnapshot(vec_vptMem, vptResult, deleteObjectID); | ||
1032 | - // 三轮车载人 | ||
1033 | - algorithm_tricycle_manned(vpt_interest_task_id, vec_vptMem, vptResult); | ||
1034 | - // 货车载人 | ||
1035 | - algorithm_truck_manned(vpt_interest_task_id, vec_vptMem, vptResult); | ||
1036 | - // 二轮车超员/未戴盔 | ||
1037 | - algorithm_motor_hs_process(vpt_interest_task_id, vec_vptMem, vptResult); | ||
1038 | - // 二轮车驾乘人员使用手机(人骑车辅助版本) | ||
1039 | - algorithm_motor_refit_phone_process(vpt_interest_task_id, vec_vptMem, vptResult); | ||
1040 | - /*// 二轮车驾乘人员使用手机 | ||
1041 | - algorithm_motor_phone_process(vpt_interest_task_id, vec_vptMem, vptResult);*/ | ||
1042 | - // 电动车改装(加雨棚) | ||
1043 | - algorithm_motor_refit_process(vpt_interest_task_id, vec_vptMem, vptResult); | ||
1044 | - // 行人/二轮车闯红灯 | ||
1045 | - algorithm_traffic_light_process(vpt_interest_task_id, vec_vptMem, vptResult); | ||
1046 | - // 与道路分割相关的算法 | ||
1047 | - algorithm_roadseg_correlation_process(vpt_interest_task_id, vec_vptMem, vptResult); | ||
1048 | - village_snapshot(vpt_interest_task_id, vec_vptMem, deleteObjectID); | ||
1049 | -#endif | ||
1050 | - | ||
1051 | - vptResult.clear(); | ||
1052 | - unUsedResult.clear(); | ||
1053 | - // deleteObjectID.clear(); | ||
1054 | - for (int i = 0; i < deleteObjectID.size(); i++) { | ||
1055 | - vector<int>().swap(deleteObjectID[i]); // free. | ||
1056 | - } | ||
1057 | - vector<vector<int>>().swap(deleteObjectID); // free. | ||
1058 | - } | ||
1059 | - | ||
1060 | - vec_vptMem.clear(); | ||
1061 | - vpt_interest_task_id.clear(); | ||
1062 | - vpt_interest_imgs.clear(); | ||
1063 | - | ||
1064 | - return 0; | ||
1065 | -} | ||
1066 | - | ||
1067 | -int CMultiSourceProcess::algorithm_vehicle_relult(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result>& vptResult, vector<vector<int>>& delete_object_id) { | ||
1068 | - | ||
1069 | - vector<multi_obj_data_t> results = m_snapshot_reprocessing->get_vehicle_snapshot(vec_devMem, vptResult, skip_frame_); | ||
1070 | - | ||
1071 | - VPCUtil* pVPCUtil = VPCUtil::getInstance(); | ||
1072 | - for (auto &result : results) { | ||
1073 | - if(result.objs.size() <= 0){ | ||
1074 | - continue; | ||
1075 | - } | ||
1076 | - auto task_id = result.task_id; | ||
1077 | - auto task_other_params = m_task_param_manager->get_task_other_param(task_id); | ||
1078 | - const auto &algor_other_params = task_other_params->find(algorithm_type_t::VEHICLE_SNAPSHOT); | ||
1079 | - if (algor_other_params == task_other_params->end()) { | ||
1080 | - LOG_ERROR("taskId {} not found algor {}", task_id.c_str(), (int)algorithm_type_t::VEHICLE_SNAPSHOT); | ||
1081 | - continue; | ||
1082 | - } | ||
1083 | - | ||
1084 | - vector<vpc_img_info> vec_obj_info_list = pVPCUtil->crop_batch(result.memPtr, result.objs); | ||
1085 | - if(vec_obj_info_list.size() != result.objs.size()){ | ||
1086 | - LOG_ERROR("vpc_crop size error !"); | ||
1087 | - VPCUtil::vpc_imgList_release(vec_obj_info_list); | ||
1088 | - continue; | ||
1089 | - } | ||
1090 | - | ||
1091 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
1092 | - | ||
1093 | - std::string cur_timestamp_ms = std::to_string(helpers::timer::get_cur_time_ms()); | ||
1094 | - const std::string fpath_origin = basic_param->result_folder + helpers::os::sep + task_id + "_" + | ||
1095 | - std::to_string(result.objs.size()) + "_" + std::to_string(result.id) + "_" + cur_timestamp_ms + ".jpg"; | ||
1096 | - | ||
1097 | - ImgSaveInfo saveInfo; | ||
1098 | - saveInfo.file_path = fpath_origin; | ||
1099 | - saveInfo.img_info = VPCUtil::vpc_devMem2vpcImg(result.memPtr); | ||
1100 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(saveInfo); | ||
1101 | - | ||
1102 | - // 保存抠图并发MQ | ||
1103 | - for(int i =0; i < result.objs.size(); i++){ | ||
1104 | - video_object_info obj = result.objs[i]; | ||
1105 | - | ||
1106 | - std::string cur_timestamp_ms = std::to_string(helpers::timer::get_cur_time_ms()); | ||
1107 | - const std::string fpath_roi = basic_param->result_folder_little + helpers::os::sep + task_id + "_" + | ||
1108 | - std::to_string(obj.object_id) + "_" + cur_timestamp_ms + ".jpg"; | ||
1109 | - | ||
1110 | - video_object_snapshot new_obj_ss_info; | ||
1111 | - new_obj_ss_info.analysisRes = nullptr; | ||
1112 | - new_obj_ss_info.object_id = obj.object_id; | ||
1113 | - new_obj_ss_info.obj_info.set_data(obj.index, obj.confidence, obj.left, obj.top, obj.right, obj.bottom); | ||
1114 | - strcpy(new_obj_ss_info.task_id, task_id.c_str()); | ||
1115 | - strcpy(new_obj_ss_info.video_image_path, fpath_origin.c_str()); | ||
1116 | - strcpy(new_obj_ss_info.snapshot_image_path, fpath_roi.c_str()); | ||
1117 | - new_obj_ss_info.nFinished = 0; | ||
1118 | - string json_str = helpers::gen_json::gen_multi_obj_json(algorithm_type_t::VEHICLE_SNAPSHOT, new_obj_ss_info); | ||
1119 | - | ||
1120 | - ImgSaveInfo save_info; | ||
1121 | - save_info.file_path = fpath_roi; | ||
1122 | - save_info.img_info = vec_obj_info_list[i]; | ||
1123 | - save_info.json_str = json_str; | ||
1124 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(save_info); | ||
1125 | - | ||
1126 | - OBJ_KEY obj_key{task_id, obj.object_id}; | ||
1127 | - // 保存有轨迹的object记录,轨迹结束时需要发消息 | ||
1128 | - std::lock_guard<std::mutex> l(m_total_mutex); | ||
1129 | - m_total_snapshot_info_multi_object.insert(obj_key); | ||
1130 | - } | ||
1131 | - | ||
1132 | - vec_obj_info_list.clear(); | ||
1133 | - } | ||
1134 | - | ||
1135 | - return 0; | ||
1136 | -} | ||
1137 | - | ||
1138 | -void CMultiSourceProcess::send_locus_finished_msg(vector<string>& vpt_interest_task_id, vector<vector<int>> deleteObjectID){ | ||
1139 | - auto task_iter = vpt_interest_task_id.begin(); | ||
1140 | - | ||
1141 | - for (int i = 0; i < deleteObjectID.size(); i++, ++task_iter) // loop taskId. | ||
1142 | - { | ||
1143 | - string task_id = *task_iter; | ||
1144 | - for (int &j : deleteObjectID[i]) // loop algor type. | ||
1145 | - { | ||
1146 | - OBJ_KEY obj_key = {task_id, j}; | ||
1147 | - | ||
1148 | - auto task_param_ptr = m_task_param_manager->get_task_algor_param(task_id); | ||
1149 | - | ||
1150 | - // 该路任务开启了抓拍功能 开始抓拍保存;若未开启抓拍,清空显存资源 | ||
1151 | - if (task_param_ptr->vehicle_algors.find(algorithm_type_t::VEHICLE_SNAPSHOT) != task_param_ptr->vehicle_algors.end()) { | ||
1152 | - std::lock_guard<std::mutex> l(m_total_mutex); | ||
1153 | - if (m_total_snapshot_info_multi_object.find(obj_key) != m_total_snapshot_info_multi_object.end()) { | ||
1154 | - video_object_snapshot new_obj_ss_info; | ||
1155 | - new_obj_ss_info.object_id = j; | ||
1156 | - new_obj_ss_info.nFinished = 1; | ||
1157 | - strcpy(new_obj_ss_info.task_id, task_id.c_str()); | ||
1158 | - string json_str = helpers::gen_json::gen_multi_obj_json(algorithm_type_t::VEHICLE_SNAPSHOT, new_obj_ss_info); | ||
1159 | - // 通知结束的轨迹 | ||
1160 | - ImgSaveInfo save_info; | ||
1161 | - save_info.json_str = json_str; | ||
1162 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(save_info); | ||
1163 | - | ||
1164 | - m_total_snapshot_info_multi_object.erase(obj_key); | ||
1165 | - } | ||
1166 | - } | ||
1167 | - } | ||
1168 | - } | ||
1169 | -} | ||
1170 | - | ||
1171 | -// for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径) | ||
1172 | -void CMultiSourceProcess::vehicle_snapshot(vector<string>& vpt_interest_task_id, vector<vector<int>> deleteObjectID) { | ||
1173 | - auto task_iter = vpt_interest_task_id.begin(); | ||
1174 | - | ||
1175 | - for (int i = 0; i < deleteObjectID.size(); i++, ++task_iter) // loop taskId. | ||
1176 | - { | ||
1177 | - for (int &j : deleteObjectID[i]) // loop algor type. | ||
1178 | - { | ||
1179 | - OBJ_KEY obj_key = {*task_iter, j}; | ||
1180 | - // 该路任务开启了抓拍功能 开始抓拍保存;若未开启抓拍,清空显存资源 | ||
1181 | - vehicle_locus_finished(obj_key); | ||
1182 | - } | ||
1183 | - } | ||
1184 | -} | ||
1185 | - | ||
1186 | -void CMultiSourceProcess::vehicle_locus_finished(const OBJ_KEY obj_key) { | ||
1187 | - | ||
1188 | - auto task_param_ptr = m_task_param_manager->get_task_algor_param(obj_key.video_id); | ||
1189 | - if (task_param_ptr == nullptr){ | ||
1190 | - return; | ||
1191 | - } | ||
1192 | - | ||
1193 | - // 该路任务开启了抓拍功能 开始抓拍保存;若未开启抓拍,清空显存资源 | ||
1194 | - if ((task_param_ptr->human_algors.find(algorithm_type_t::HUMAN_SNAPSHOT) == task_param_ptr->human_algors.end() && | ||
1195 | - task_param_ptr->vehicle_algors.find(algorithm_type_t::VEHICLE_SNAPSHOT) != task_param_ptr->vehicle_algors.end() && | ||
1196 | - task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT) != task_param_ptr->nonmotor_vehicle_algors.end())) { | ||
1197 | - return; | ||
1198 | - } | ||
1199 | - | ||
1200 | - map<OBJ_KEY, OBJ_VALUE> _total_snapshot_info = m_snapshot_reprocessing->get_total_snapshot_info(); | ||
1201 | - if(_total_snapshot_info.size() <= 0){ | ||
1202 | - return; | ||
1203 | - } | ||
1204 | - | ||
1205 | - LOG_DEBUG("_total_snapshot_info size: {}", _total_snapshot_info.size()); | ||
1206 | - | ||
1207 | - auto it = _total_snapshot_info.find(obj_key); | ||
1208 | - if (it == _total_snapshot_info.end()) { | ||
1209 | - return; | ||
1210 | - } | ||
1211 | - | ||
1212 | - const OBJ_VALUE obj_value = it->second; | ||
1213 | - | ||
1214 | - auto task_other_param_map = m_task_param_manager->get_task_other_params(); | ||
1215 | - auto it_other_param = task_other_param_map.find(obj_key.video_id); | ||
1216 | - if(it_other_param == task_other_param_map.end()){ | ||
1217 | - return; | ||
1218 | - } | ||
1219 | - auto task_other_param = it_other_param->second; | ||
1220 | - | ||
1221 | - LOG_DEBUG("algor_type"); | ||
1222 | - auto algor_type = index_to_algo_type[obj_value.index.index]; | ||
1223 | - | ||
1224 | - LOG_DEBUG("task_other_param"); | ||
1225 | - auto it_algor_type = task_other_param.find(algor_type); | ||
1226 | - if(it_algor_type == task_other_param.end()) { | ||
1227 | - return; | ||
1228 | - } | ||
1229 | - | ||
1230 | - LOG_DEBUG("algor_param"); | ||
1231 | - auto algor_param = (algor_config_param_snapshot *)it_algor_type->second->algor_param; | ||
1232 | - if(algor_param == nullptr) { | ||
1233 | - return; | ||
1234 | - } | ||
1235 | - | ||
1236 | - if (obj_value.confidence <= algor_param->threshold) { | ||
1237 | - LOG_DEBUG("Snapshot conf filter ({} vs {})", obj_value.confidence, algor_param->threshold); | ||
1238 | - // 删除记录,同时释放显存 | ||
1239 | - m_snapshot_reprocessing->release_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, true); | ||
1240 | - return; | ||
1241 | - } | ||
1242 | - | ||
1243 | - LOG_DEBUG("cur_param"); | ||
1244 | - const algor_basic_config_param_t *cur_param = it_algor_type->second->basic_param; | ||
1245 | - // const algor_basic_config_param_t *cur_param = task_other_param[algor_type]->basic_param; | ||
1246 | - if(cur_param == nullptr) { | ||
1247 | - return; | ||
1248 | - } | ||
1249 | - | ||
1250 | - // 原图 | ||
1251 | - LOG_DEBUG("原图"); | ||
1252 | - std::string cur_timestamp_ms = std::to_string(helpers::timer::get_cur_time_ms()); | ||
1253 | - std::string fpath_origin = std::string(cur_param->result_folder) + helpers::os::sep + obj_key.video_id + "_" + | ||
1254 | - std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".jpg"; | ||
1255 | - | ||
1256 | - ImgSaveInfo origin_save_info; | ||
1257 | - origin_save_info.file_path = fpath_origin; | ||
1258 | - origin_save_info.img_info = obj_value.snapShot; | ||
1259 | - origin_save_info.obj_rect = obj_value.obj_pos; | ||
1260 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(origin_save_info); | ||
1261 | - | ||
1262 | - { | ||
1263 | - LOG_DEBUG("抠图"); | ||
1264 | - // 抠图 | ||
1265 | - string json_str = ""; | ||
1266 | - string object_file_name = std::string(cur_param->result_folder_little) + helpers::os::sep + obj_key.video_id + "_" + | ||
1267 | - std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".jpg"; | ||
1268 | - | ||
1269 | -#ifdef POST_USE_RABBITMQ | ||
1270 | - video_object_snapshot new_obj_ss_info; | ||
1271 | - new_obj_ss_info.analysisRes = nullptr; | ||
1272 | - new_obj_ss_info.object_id = obj_key.obj_id; | ||
1273 | - new_obj_ss_info.obj_info.set_data(obj_value.index.index, obj_value.confidence, obj_value.obj_pos.left_, | ||
1274 | - obj_value.obj_pos.top_, obj_value.obj_pos.left_ + obj_value.obj_pos.width_, | ||
1275 | - obj_value.obj_pos.top_ + obj_value.obj_pos.height_); | ||
1276 | - strcpy(new_obj_ss_info.task_id, obj_key.video_id.c_str()); | ||
1277 | - strcpy(new_obj_ss_info.video_image_path, fpath_origin.c_str()); | ||
1278 | - strcpy(new_obj_ss_info.snapshot_image_path, object_file_name.c_str()); | ||
1279 | - json_str = helpers::gen_json::gen_snapshot_json(algor_type, new_obj_ss_info); | ||
1280 | -#endif | ||
1281 | - | ||
1282 | - ImgSaveInfo obj_save_info; | ||
1283 | - obj_save_info.file_path = object_file_name; | ||
1284 | - obj_save_info.img_info = obj_value.snapShotLittle; | ||
1285 | - obj_save_info.json_str = json_str; | ||
1286 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(obj_save_info); | ||
1287 | - } | ||
1288 | - | ||
1289 | - LOG_DEBUG("仅删除记录,显存会在保存线程中删除"); | ||
1290 | - // 仅删除记录,显存会在保存线程中删除 | ||
1291 | - m_snapshot_reprocessing->release_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, false); | ||
1292 | - | ||
1293 | -} | ||
1294 | - | ||
1295 | -void CMultiSourceProcess::timing_snapshot_thread(){ | ||
1296 | - LOG_INFO("timing_snapshot_thread start."); | ||
1297 | - | ||
1298 | - JpegUtil jpegUtil; | ||
1299 | - jpegUtil.jpeg_init(m_devId); | ||
1300 | - | ||
1301 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
1302 | - while(!m_bfinish){ | ||
1303 | - vector<DeviceMemory*> vec_devMem = pDecManager->timing_snapshot_all(); | ||
1304 | - for (auto devMem : vec_devMem) { | ||
1305 | - auto task_id = devMem->getId(); | ||
1306 | - auto task_other_params = m_task_param_manager->get_task_other_param(task_id); | ||
1307 | - if (task_other_params == nullptr) | ||
1308 | - continue; | ||
1309 | - const auto &algor_other_params = task_other_params->find(algorithm_type_t::VIDEO_TIMING_SNAPSHOT); | ||
1310 | - if(algor_other_params != task_other_params->end()){ | ||
1311 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
1312 | - std::string cur_timestamp_ms = std::to_string(devMem->getTimesstamp()); | ||
1313 | - const std::string fpath_ori = basic_param->result_folder + helpers::os::sep + task_id + "_" + cur_timestamp_ms + ".jpg"; | ||
1314 | - | ||
1315 | - // LOG_DEBUG("snapshot save path: {}", fpath_ori.c_str()); | ||
1316 | - | ||
1317 | - acldvppPicDesc *vpcDesc= acldvppCreatePicDesc(); | ||
1318 | - acldvppSetPicDescData(vpcDesc, devMem->getMem()); | ||
1319 | - acldvppSetPicDescFormat(vpcDesc, PIXEL_FORMAT_YUV_SEMIPLANAR_420); | ||
1320 | - acldvppSetPicDescWidth(vpcDesc, devMem->getWidth()); | ||
1321 | - acldvppSetPicDescHeight(vpcDesc, devMem->getHeight()); | ||
1322 | - acldvppSetPicDescWidthStride(vpcDesc, devMem->getWidthStride()); | ||
1323 | - acldvppSetPicDescHeightStride(vpcDesc, devMem->getHeightStride()); | ||
1324 | - acldvppSetPicDescSize(vpcDesc, devMem->getSize()); | ||
1325 | - | ||
1326 | - jpegUtil.jpeg_encode(vpcDesc, fpath_ori); | ||
1327 | - | ||
1328 | - acldvppDestroyPicDesc(vpcDesc); | ||
1329 | - vpcDesc = nullptr; | ||
1330 | - | ||
1331 | - #ifdef POST_USE_RABBITMQ | ||
1332 | - auto json_str = helpers::gen_json::gen_vtsnapshot_json(task_id, fpath_ori); | ||
1333 | - mq_manager_->publish(mq_type_t::TIMING_SCREENSHORT_TASK_MQ, json_str.c_str(), true); | ||
1334 | - #endif | ||
1335 | - } | ||
1336 | - } | ||
1337 | - | ||
1338 | - for(auto devMem : vec_devMem){ | ||
1339 | - delete devMem; | ||
1340 | - devMem = nullptr; | ||
1341 | - } | ||
1342 | - vec_devMem.clear(); | ||
1343 | - | ||
1344 | - std::this_thread::sleep_for(std::chrono::milliseconds(600)); | ||
1345 | - } | ||
1346 | - | ||
1347 | - jpegUtil.jpeg_release(); | ||
1348 | - | ||
1349 | - LOG_INFO("timing_snapshot_thread end."); | ||
1350 | -} | ||
1351 | - | ||
1352 | -// 逆行 | ||
1353 | -void CMultiSourceProcess::algorthim_retrograde(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1354 | - vector<onelevel_det_result>& vptResult){ | ||
1355 | - vector<string> interest_task_id; | ||
1356 | - vector<onelevel_det_result> interest_vpt_result; | ||
1357 | - vector<DeviceMemory*> interest_imgs; | ||
1358 | - | ||
1359 | - int _idx = 0; | ||
1360 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1361 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1362 | - { | ||
1363 | - auto task_id = *_task_id_iter; | ||
1364 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1365 | - | ||
1366 | - if (algor_map->find(algorithm_type_t::PEDESTRIAN_RETROGRADE) != algor_map->end() || | ||
1367 | - algor_map->find(algorithm_type_t::VEHICLE_RETROGRADE) != algor_map->end()) { | ||
1368 | - interest_task_id.emplace_back(task_id); | ||
1369 | - interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1370 | - interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1371 | - } | ||
1372 | - } | ||
1373 | - | ||
1374 | - // LOG_DEBUG("retrograde interest_vpt_result size: {}", interest_vpt_result.size()); | ||
1375 | - | ||
1376 | - if (!interest_imgs.empty()){ | ||
1377 | - pedestrian_vehicle_retrograde_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); | ||
1378 | - } | ||
1379 | -} | ||
1380 | - | ||
1381 | -// 闯入 | ||
1382 | -void CMultiSourceProcess::algorthim_trespass(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1383 | - vector<onelevel_det_result>& vptResult ,vector<vector<int>>& deleteObjectID){ | ||
1384 | - | ||
1385 | - vector<string> trespass_interest_task_id; | ||
1386 | - vector<onelevel_det_result> trespass_interest_vpt_result; | ||
1387 | - vector<vector<int>> trespass_interest_deleteobjs; | ||
1388 | - vector<DeviceMemory*> trespass_interest_imgs; | ||
1389 | - | ||
1390 | - int _idx = 0; | ||
1391 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1392 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1393 | - { | ||
1394 | - auto task_id = *_task_id_iter; | ||
1395 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1396 | - | ||
1397 | - if (algor_map->find(algorithm_type_t::PEDESTRIAN_TRESPASS) != algor_map->end() || | ||
1398 | - algor_map->find(algorithm_type_t::VEHICLE_TRESPASS) != algor_map->end()) { | ||
1399 | - trespass_interest_task_id.emplace_back(task_id); | ||
1400 | - trespass_interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1401 | - trespass_interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1402 | - trespass_interest_deleteobjs.emplace_back(deleteObjectID[_idx]); | ||
1403 | - } | ||
1404 | - } | ||
1405 | - | ||
1406 | - // LOG_DEBUG("trespass interest_vpt_result size: {}", trespass_interest_vpt_result.size()); | ||
1407 | - | ||
1408 | - if (!trespass_interest_imgs.empty()) { | ||
1409 | - pedestrian_vehicle_trespass_.update_mstreams( trespass_interest_task_id, trespass_interest_imgs, | ||
1410 | - trespass_interest_vpt_result, trespass_interest_deleteobjs); | ||
1411 | - } | ||
1412 | -} | ||
1413 | - | ||
1414 | -// 轨迹记录 | ||
1415 | -void CMultiSourceProcess::trace_record(vector<string>& vpt_interest_task_id, vector<onelevel_det_result>& vptResult) { | ||
1416 | - int bidx = 0; | ||
1417 | - for (auto iter = vpt_interest_task_id.begin(); iter != vpt_interest_task_id.end(); ++ iter, ++ bidx) { | ||
1418 | - auto task_id = *iter; | ||
1419 | - for (int c = 0; c < vptResult[bidx].obj_count; c++) { | ||
1420 | - //计算检测框坐标中心点 | ||
1421 | - sy_point center_point; | ||
1422 | - center_point.x_ = vptResult[bidx].obj[c].left + (vptResult[bidx].obj[c].right - vptResult[bidx].obj[c].left) * 0.5; | ||
1423 | - // center_point.y_ = vptResult[bidx].obj[c].top + (vptResult[bidx].obj[c].bottom - vptResult[bidx].obj[c].top) * 0.85; | ||
1424 | - center_point.y_ = vptResult[bidx].obj[c].bottom; | ||
1425 | - | ||
1426 | - OBJ_KEY new_obj = { task_id, vptResult[bidx].obj[c].id }; | ||
1427 | - m_TotalObjMtx.lock(); | ||
1428 | - m_total_obj_info[new_obj].index = vptResult[bidx].obj[c].index; | ||
1429 | - m_total_obj_info[new_obj].center_points.push_back(center_point); | ||
1430 | - m_TotalObjMtx.unlock(); | ||
1431 | - | ||
1432 | - } | ||
1433 | - } | ||
1434 | -} | ||
1435 | - | ||
1436 | -// 三轮车载人 | ||
1437 | -void CMultiSourceProcess::algorithm_tricycle_manned(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1438 | - vector<onelevel_det_result>& vptResult) { | ||
1439 | - | ||
1440 | - vector<string> interest_task_id; | ||
1441 | - vector<onelevel_det_result> interest_vpt_result; | ||
1442 | - vector<DeviceMemory*> interest_imgs; | ||
1443 | - | ||
1444 | - int _idx = 0; | ||
1445 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1446 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1447 | - { | ||
1448 | - auto task_id = *_task_id_iter; | ||
1449 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1450 | - | ||
1451 | - if (algor_map->find(algorithm_type_t::TRICYCLE_MANNED) != algor_map->end()) { | ||
1452 | - interest_task_id.emplace_back(task_id); | ||
1453 | - interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1454 | - interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1455 | - } | ||
1456 | - } | ||
1457 | - | ||
1458 | - // LOG_DEBUG("tricycle_manned interest_vpt_result size: {}", interest_vpt_result.size()); | ||
1459 | - | ||
1460 | - if (!interest_imgs.empty()){ | ||
1461 | - tricycle_manned_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); | ||
1462 | - } | ||
1463 | -} | ||
1464 | - | ||
1465 | - | ||
1466 | -// 货车载人 | ||
1467 | -void CMultiSourceProcess::algorithm_truck_manned(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1468 | - vector<onelevel_det_result>& vptResult) { | ||
1469 | - | ||
1470 | - vector<string> interest_task_id; | ||
1471 | - vector<onelevel_det_result> interest_vpt_result; | ||
1472 | - vector<DeviceMemory*> interest_imgs; | ||
1473 | - | ||
1474 | - int _idx = 0; | ||
1475 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1476 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1477 | - { | ||
1478 | - auto task_id = *_task_id_iter; | ||
1479 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1480 | - | ||
1481 | - if (algor_map->find(algorithm_type_t::TRUCK_MANNED) != algor_map->end()) { | ||
1482 | - interest_task_id.emplace_back(task_id); | ||
1483 | - interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1484 | - interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1485 | - } | ||
1486 | - } | ||
1487 | - | ||
1488 | - // LOG_DEBUG("truck_manned interest_vpt_result size: {}", interest_vpt_result.size()); | ||
1489 | - | ||
1490 | - if (!interest_imgs.empty()){ | ||
1491 | - m_TotalObjMtx.lock(); | ||
1492 | - truck_manned_.update_mstreams(interest_task_id, interest_imgs, m_total_obj_info, interest_vpt_result); | ||
1493 | - m_TotalObjMtx.unlock(); | ||
1494 | - } | ||
1495 | -} | ||
1496 | - | ||
1497 | - | ||
1498 | -// 二轮车超员/未戴盔 | ||
1499 | -void CMultiSourceProcess::algorithm_motor_hs_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1500 | - vector<onelevel_det_result>& vptResult) { | ||
1501 | - | ||
1502 | - vector<string> interest_task_id; | ||
1503 | - vector<onelevel_det_result> interest_vpt_result; | ||
1504 | - vector<DeviceMemory*> interest_imgs; | ||
1505 | - | ||
1506 | - int _idx = 0; | ||
1507 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1508 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1509 | - { | ||
1510 | - auto task_id = *_task_id_iter; | ||
1511 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1512 | - | ||
1513 | - if (algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET) != algor_map->end() || | ||
1514 | - algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN) != algor_map->end()) { | ||
1515 | - interest_task_id.emplace_back(task_id); | ||
1516 | - interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1517 | - interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1518 | - } | ||
1519 | - } | ||
1520 | - | ||
1521 | - // LOG_DEBUG("motor_hsprocess interest_vpt_result size: {}", interest_vpt_result.size()); | ||
1522 | - | ||
1523 | - if (!interest_imgs.empty()){ | ||
1524 | - motor_hsprocess_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); | ||
1525 | - } | ||
1526 | -} | ||
1527 | - | ||
1528 | -// 二轮车驾乘人员使用手机(人骑车辅助版) | ||
1529 | -void CMultiSourceProcess::algorithm_motor_refit_phone_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1530 | - vector<onelevel_det_result>& vptResult) { | ||
1531 | - | ||
1532 | - vector<string> interest_task_id; | ||
1533 | - vector<onelevel_det_result> interest_vpt_result; | ||
1534 | - vector<DeviceMemory*> interest_imgs; | ||
1535 | - | ||
1536 | - int _idx = 0; | ||
1537 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1538 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1539 | - { | ||
1540 | - auto task_id = *_task_id_iter; | ||
1541 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1542 | - | ||
1543 | - // if (algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != algor_map->end() || | ||
1544 | - // algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) != algor_map->end()) { | ||
1545 | - if (algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != algor_map->end()) { | ||
1546 | - interest_task_id.emplace_back(task_id); | ||
1547 | - interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1548 | - interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1549 | - } | ||
1550 | - } | ||
1551 | - | ||
1552 | - if (!interest_imgs.empty()){ | ||
1553 | - motor_refit_phoneprocess_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); | ||
1554 | - } | ||
1555 | -} | ||
1556 | -/*// 二轮车驾乘人员使用手机 | ||
1557 | -void CMultiSourceProcess::algorithm_motor_phone_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1558 | - vector<onelevel_det_result>& vptResult) { | ||
1559 | - | ||
1560 | - vector<string> interest_task_id; | ||
1561 | - vector<onelevel_det_result> interest_vpt_result; | ||
1562 | - vector<DeviceMemory*> interest_imgs; | ||
1563 | - | ||
1564 | - int _idx = 0; | ||
1565 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1566 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1567 | - { | ||
1568 | - auto task_id = *_task_id_iter; | ||
1569 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1570 | - | ||
1571 | - if (algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != algor_map->end()) { | ||
1572 | - interest_task_id.emplace_back(task_id); | ||
1573 | - interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1574 | - interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1575 | - } | ||
1576 | - } | ||
1577 | - | ||
1578 | - if (!interest_imgs.empty()){ | ||
1579 | - motor_phoneprocess_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); | ||
1580 | - } | ||
1581 | -}*/ | ||
1582 | - | ||
1583 | -// 电动车改装(加雨棚) | ||
1584 | -void CMultiSourceProcess::algorithm_motor_refit_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1585 | - vector<onelevel_det_result>& vptResult) { | ||
1586 | - | ||
1587 | - vector<string> interest_task_id; | ||
1588 | - vector<onelevel_det_result> interest_vpt_result; | ||
1589 | - vector<DeviceMemory*> interest_imgs; | ||
1590 | - | ||
1591 | - int _idx = 0; | ||
1592 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1593 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1594 | - { | ||
1595 | - auto task_id = *_task_id_iter; | ||
1596 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1597 | - | ||
1598 | - if (algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) != algor_map->end()) { | ||
1599 | - interest_task_id.emplace_back(task_id); | ||
1600 | - interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1601 | - interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1602 | - } | ||
1603 | - } | ||
1604 | - | ||
1605 | - if (!interest_imgs.empty()){ | ||
1606 | - motor_refitprocess_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); | ||
1607 | - } | ||
1608 | -} | ||
1609 | - | ||
1610 | - | ||
1611 | -// 行人/二轮车闯红灯 | ||
1612 | -void CMultiSourceProcess::algorithm_traffic_light_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1613 | - vector<onelevel_det_result>& vptResult) { | ||
1614 | - | ||
1615 | - vector<string> interest_task_id; | ||
1616 | - vector<onelevel_det_result> interest_vpt_result; | ||
1617 | - vector<DeviceMemory*> interest_imgs; | ||
1618 | - vector<sy_img> sy_interest_imgs; | ||
1619 | - vector<vector<vector<int>>> interest_traffic_region; | ||
1620 | - vector<vector<int>> interest_labels; | ||
1621 | - | ||
1622 | - int _idx = 0; | ||
1623 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1624 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1625 | - { | ||
1626 | - auto task_id = *_task_id_iter; | ||
1627 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1628 | - | ||
1629 | - if (algor_map->find(algorithm_type_t::PERSON_RUNNING_REDLIGHTS) != algor_map->end() || | ||
1630 | - algor_map->find(algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS) != algor_map->end()) { | ||
1631 | - | ||
1632 | - m_RoadSegTaskMtx.lock(); | ||
1633 | - if (!m_RoadSegTaskMap[task_id].isseg) continue; | ||
1634 | - else { | ||
1635 | - interest_traffic_region.push_back(m_RoadSegTaskMap[task_id].traffic_region); | ||
1636 | - interest_labels.push_back(m_RoadSegTaskMap[task_id].labels); | ||
1637 | - } | ||
1638 | - m_RoadSegTaskMtx.unlock(); | ||
1639 | - | ||
1640 | - DeviceMemory* mem = vpt_interest_imgs[_idx]; | ||
1641 | - sy_img img; | ||
1642 | - img.w_ = mem->getWidth(); img.h_ = mem->getHeight(); | ||
1643 | - img.c_ = mem->getChannel(); img.data_ = mem->getMem(); | ||
1644 | - sy_interest_imgs.push_back(img); | ||
1645 | - | ||
1646 | - interest_task_id.emplace_back(task_id); | ||
1647 | - interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1648 | - interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1649 | - } | ||
1650 | - } | ||
1651 | - | ||
1652 | - if (!interest_imgs.empty()){ | ||
1653 | - m_TotalObjMtx.lock(); | ||
1654 | - traffic_lightprocess_.update_mstreams(interest_task_id, sy_interest_imgs, interest_imgs, interest_traffic_region, interest_labels, m_total_obj_info, interest_vpt_result); | ||
1655 | - m_TotalObjMtx.unlock(); | ||
1656 | - } | ||
1657 | -} | ||
1658 | - | ||
1659 | - | ||
1660 | -// 与道路分割相关的算法 | ||
1661 | -void CMultiSourceProcess::algorithm_roadseg_correlation_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | ||
1662 | - vector<onelevel_det_result>& vptResult) { | ||
1663 | - | ||
1664 | - vector<string> interest_task_id; | ||
1665 | - vector<onelevel_det_result> interest_vpt_result; | ||
1666 | - vector<DeviceMemory*> interest_imgs; | ||
1667 | - vector<sy_img> sy_interest_imgs; | ||
1668 | - vector<vector<vector<int>>> interest_traffic_region, interest_fence_region; | ||
1669 | - vector<vector<int>> interest_labels, interest_fence_labels; | ||
1670 | - | ||
1671 | - int _idx = 0; | ||
1672 | - for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | ||
1673 | - ++_task_id_iter, ++_idx) // loop task_id; | ||
1674 | - { | ||
1675 | - auto task_id = *_task_id_iter; | ||
1676 | - auto algor_map = m_task_param_manager->get_task_other_param(task_id); | ||
1677 | - | ||
1678 | - if (algor_map->find(algorithm_type_t::PERSON_IN_VEHICLELANE) != algor_map->end() || | ||
1679 | - algor_map->find(algorithm_type_t::NONMOTOR_IN_VEHICLELANE) != algor_map->end() || | ||
1680 | - algor_map->find(algorithm_type_t::NONMOTOR_CEOSSPARKLINE) != algor_map->end() || | ||
1681 | - algor_map->find(algorithm_type_t::PERSON_CROSS) != algor_map->end() || | ||
1682 | - algor_map->find(algorithm_type_t::NONMOTOR_WRONGDIRECTION) != algor_map->end() || | ||
1683 | - algor_map->find(algorithm_type_t::VEHICLE_WRONGDIRECTION) != algor_map->end() || | ||
1684 | - algor_map->find(algorithm_type_t::VEHICLE_NOTGIVEWAY) != algor_map->end() || | ||
1685 | - algor_map->find(algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) != algor_map->end() || | ||
1686 | - algor_map->find(algorithm_type_t::VEHICLE_NOTDECELERATION) != algor_map->end() | ||
1687 | - ) { | ||
1688 | - | ||
1689 | - m_RoadSegTaskMtx.lock(); | ||
1690 | - if (!m_RoadSegTaskMap[task_id].isseg) continue; | ||
1691 | - else { | ||
1692 | - interest_traffic_region.push_back(m_RoadSegTaskMap[task_id].traffic_region); | ||
1693 | - interest_labels.push_back(m_RoadSegTaskMap[task_id].labels); | ||
1694 | - interest_fence_region.push_back(m_RoadSegTaskMap[task_id].fence_region); | ||
1695 | - interest_fence_labels.push_back(m_RoadSegTaskMap[task_id].fence_labels); | ||
1696 | - } | ||
1697 | - m_RoadSegTaskMtx.unlock(); | ||
1698 | - | ||
1699 | - DeviceMemory* mem = vpt_interest_imgs[_idx]; | ||
1700 | - sy_img img; | ||
1701 | - img.w_ = mem->getWidth(); img.h_ = mem->getHeight(); | ||
1702 | - img.c_ = mem->getChannel(); img.data_ = mem->getMem(); | ||
1703 | - sy_interest_imgs.push_back(img); | ||
1704 | - | ||
1705 | - interest_task_id.emplace_back(task_id); | ||
1706 | - interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | ||
1707 | - interest_vpt_result.emplace_back(vptResult[_idx]); | ||
1708 | - } | ||
1709 | - } | ||
1710 | - | ||
1711 | - if (!interest_imgs.empty()){ | ||
1712 | - m_TotalObjMtx.lock(); | ||
1713 | - roadseg_corrprocess_.update_mstreams(interest_task_id, sy_interest_imgs, interest_imgs, interest_traffic_region, interest_labels, interest_fence_region, interest_fence_labels, m_total_obj_info, interest_vpt_result); | ||
1714 | - m_TotalObjMtx.unlock(); | ||
1715 | - } | ||
1716 | -} | ||
1717 | - | ||
1718 | -// for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径) | ||
1719 | -void CMultiSourceProcess::village_snapshot(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vec_vptMem, vector<vector<int>> deleteObjectID) { | ||
1720 | - auto task_iter = vpt_interest_task_id.begin(); | ||
1721 | - for (int i = 0; i < deleteObjectID.size(); i++, ++task_iter) // loop taskId. | ||
1722 | - { | ||
1723 | - auto task_id = *task_iter; | ||
1724 | - for (int &j : deleteObjectID[i]) // loop algor type. | ||
1725 | - { | ||
1726 | - OBJ_KEY obj_key = {*task_iter, j}; | ||
1727 | - auto task_param_ptr = m_task_param_manager->get_task_algor_param(obj_key.video_id); | ||
1728 | - auto algor_config_param = m_task_param_manager->get_task_algor_params(); | ||
1729 | - auto algor_param = m_task_param_manager->get_task_other_params(); | ||
1730 | - if (!(algor_config_param.count(task_id) && algor_param.count(task_id))) continue; | ||
1731 | - bool village_alarm = false; | ||
1732 | - std::string video_folder = "", result_folder = "", result_folder_little = ""; //要求各事件使用同一个视频保存地址,否则会被最后一个事件的地址覆盖 | ||
1733 | - auto task_other_params = m_task_param_manager->get_task_other_param(task_id); | ||
1734 | - std::vector<int> algorithm_types; | ||
1735 | - bool save_single_algor_pic = false; // 是否保存单算法的报警图片(若设置为true需先去掉算法内部注释!!!) | ||
1736 | - | ||
1737 | - if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::TRICYCLE_MANNED) != task_param_ptr->nonmotor_vehicle_algors.end()) { | ||
1738 | - const auto &algor_other_params = task_other_params->find(algorithm_type_t::TRICYCLE_MANNED); | ||
1739 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
1740 | - | ||
1741 | - auto result = tricycle_manned_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::TRICYCLE_MANNED}); | ||
1742 | - if (result.get()) { | ||
1743 | - village_alarm = true; | ||
1744 | - algorithm_types.push_back((int)algorithm_type_t::TRICYCLE_MANNED); | ||
1745 | - video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; result_folder_little = basic_param->result_folder_little; | ||
1746 | - // 原图及抠图 | ||
1747 | - vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; | ||
1748 | - vpc_img_info roi_img; roi_img.pic_desc = result->roi_img_desc; roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; | ||
1749 | - | ||
1750 | - if (save_single_algor_pic) { | ||
1751 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRICYCLE_MANNED); | ||
1752 | - save_snapshot_process(obj_key, algorithm_type_t::TRICYCLE_MANNED, src_img, roi_img, 0, json_str); | ||
1753 | - } else { | ||
1754 | - VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); | ||
1755 | - } | ||
1756 | - | ||
1757 | - } | ||
1758 | - } | ||
1759 | - | ||
1760 | - if (task_param_ptr->vehicle_algors.find(algorithm_type_t::TRUCK_MANNED) != task_param_ptr->vehicle_algors.end()) { | ||
1761 | - const auto &algor_other_params = task_other_params->find(algorithm_type_t::TRUCK_MANNED); | ||
1762 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
1763 | - | ||
1764 | - auto result = truck_manned_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::TRUCK_MANNED}); | ||
1765 | - if (result.get()) { | ||
1766 | - village_alarm = true; | ||
1767 | - algorithm_types.push_back((int)algorithm_type_t::TRUCK_MANNED); | ||
1768 | - video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; result_folder_little = basic_param->result_folder_little; | ||
1769 | - // 原图及抠图 | ||
1770 | - vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; | ||
1771 | - vpc_img_info roi_img; roi_img.pic_desc = result->roi_img_desc; roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; | ||
1772 | - | ||
1773 | - if (save_single_algor_pic) { | ||
1774 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRUCK_MANNED); | ||
1775 | - save_snapshot_process(obj_key, algorithm_type_t::TRUCK_MANNED, src_img, roi_img, 0, json_str); | ||
1776 | - } else { | ||
1777 | - VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); | ||
1778 | - } | ||
1779 | - | ||
1780 | - } | ||
1781 | - } | ||
1782 | - | ||
1783 | - vector<algo_type> motorhs_algor = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN}; | ||
1784 | - for (size_t idx = 0; idx < motorhs_algor.size(); ++idx) { | ||
1785 | - if (algor_param[task_id].count(motorhs_algor.at(idx))) { | ||
1786 | - const auto &algor_other_params = task_other_params->find(motorhs_algor.at(idx)); | ||
1787 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
1788 | - | ||
1789 | - auto result = motor_hsprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, motorhs_algor.at(idx)}); | ||
1790 | - if (result.get()) { | ||
1791 | - village_alarm = true; | ||
1792 | - algorithm_types.push_back((int)motorhs_algor.at(idx)); | ||
1793 | - video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; result_folder_little = basic_param->result_folder_little; | ||
1794 | - // 原图及抠图 | ||
1795 | - vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; | ||
1796 | - vpc_img_info roi_img; roi_img.pic_desc = result->roi_img_desc; roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; | ||
1797 | - | ||
1798 | - if (save_single_algor_pic) { | ||
1799 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, motorhs_algor.at(idx)); | ||
1800 | - save_snapshot_process(obj_key, motorhs_algor.at(idx), src_img, roi_img, 0, json_str); | ||
1801 | - } else { | ||
1802 | - VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); | ||
1803 | - } | ||
1804 | - | ||
1805 | - } | ||
1806 | - } | ||
1807 | - } | ||
1808 | - | ||
1809 | - if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != task_param_ptr->nonmotor_vehicle_algors.end()) { | ||
1810 | - const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE); | ||
1811 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
1812 | - | ||
1813 | - // auto result = motor_phoneprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE}); | ||
1814 | - auto result = motor_refit_phoneprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE}); | ||
1815 | - if (result.get()) { | ||
1816 | - village_alarm = true; | ||
1817 | - algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE); | ||
1818 | - video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; result_folder_little = basic_param->result_folder_little; | ||
1819 | - // 原图及抠图 | ||
1820 | - vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; | ||
1821 | - vpc_img_info roi_img; roi_img.pic_desc = result->roi_img_desc; roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; | ||
1822 | - | ||
1823 | - if (save_single_algor_pic) { | ||
1824 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE); | ||
1825 | - save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE, src_img, roi_img, 0, json_str); | ||
1826 | - } else { | ||
1827 | - VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); | ||
1828 | - } | ||
1829 | - | ||
1830 | - } | ||
1831 | - } | ||
1832 | - | ||
1833 | - if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) != task_param_ptr->nonmotor_vehicle_algors.end()) { | ||
1834 | - const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT); | ||
1835 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
1836 | - | ||
1837 | - auto result = motor_refitprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_VEHICLE_REFIT}); | ||
1838 | - // auto result = motor_refit_phoneprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_VEHICLE_REFIT}); | ||
1839 | - if (result.get()) { | ||
1840 | - village_alarm = true; | ||
1841 | - algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_VEHICLE_REFIT); | ||
1842 | - video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; result_folder_little = basic_param->result_folder_little; | ||
1843 | - // 原图及抠图 | ||
1844 | - vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; | ||
1845 | - vpc_img_info roi_img; roi_img.pic_desc = result->roi_img_desc; roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; | ||
1846 | - | ||
1847 | - if (save_single_algor_pic) { | ||
1848 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_REFIT); | ||
1849 | - save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_REFIT, src_img, roi_img, 0, json_str); | ||
1850 | - } else { | ||
1851 | - VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); | ||
1852 | - } | ||
1853 | - | ||
1854 | - } | ||
1855 | - } | ||
1856 | - | ||
1857 | - vector<algo_type> trafficlight_algor = {algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS}; | ||
1858 | - for (size_t idx = 0; idx < trafficlight_algor.size(); ++idx) { | ||
1859 | - if (algor_param[task_id].count(trafficlight_algor.at(idx))) { | ||
1860 | - const auto &algor_other_params = task_other_params->find(trafficlight_algor.at(idx)); | ||
1861 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
1862 | - | ||
1863 | - auto result = traffic_lightprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, trafficlight_algor.at(idx)}); | ||
1864 | - if (result.get()) { | ||
1865 | - village_alarm = true; | ||
1866 | - algorithm_types.push_back((int)trafficlight_algor.at(idx)); | ||
1867 | - video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; result_folder_little = basic_param->result_folder_little; | ||
1868 | - // 原图及抠图 | ||
1869 | - vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; | ||
1870 | - vpc_img_info roi_img; roi_img.pic_desc = result->roi_img_desc; roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; | ||
1871 | - | ||
1872 | - if (save_single_algor_pic) { | ||
1873 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, trafficlight_algor.at(idx)); | ||
1874 | - save_snapshot_process(obj_key, trafficlight_algor.at(idx), src_img, roi_img, 0, json_str); | ||
1875 | - } else { | ||
1876 | - VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); | ||
1877 | - } | ||
1878 | - | ||
1879 | - } | ||
1880 | - } | ||
1881 | - } | ||
1882 | - | ||
1883 | - vector<algo_type> roadseg_algor = {algorithm_type_t::PERSON_IN_VEHICLELANE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_IN_VEHICLELANE, algorithm_type_t::NONMOTOR_CEOSSPARKLINE, | ||
1884 | - algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY, algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND, algorithm_type_t::VEHICLE_NOTDECELERATION }; | ||
1885 | - for (size_t idx = 0; idx < roadseg_algor.size(); ++idx) { | ||
1886 | - if (algor_param[task_id].count(roadseg_algor.at(idx))) { | ||
1887 | - const auto &algor_other_params = task_other_params->find(roadseg_algor.at(idx)); | ||
1888 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
1889 | - | ||
1890 | - auto result = roadseg_corrprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, roadseg_algor.at(idx)}); | ||
1891 | - if (result.get()) { | ||
1892 | - village_alarm = true; | ||
1893 | - algorithm_types.push_back((int)roadseg_algor.at(idx)); | ||
1894 | - video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; result_folder_little = basic_param->result_folder_little; | ||
1895 | - // 原图及抠图 | ||
1896 | - vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; | ||
1897 | - vpc_img_info roi_img; roi_img.pic_desc = result->roi_img_desc; roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; | ||
1898 | - | ||
1899 | - if (save_single_algor_pic) { | ||
1900 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, roadseg_algor.at(idx)); | ||
1901 | - save_snapshot_process(obj_key, roadseg_algor.at(idx), src_img, roi_img, 0, json_str); | ||
1902 | - } else { | ||
1903 | - VPCUtil::vpc_img_release(src_img); VPCUtil::vpc_img_release(roi_img); | ||
1904 | - } | ||
1905 | - | ||
1906 | - } | ||
1907 | - } | ||
1908 | - } | ||
1909 | - | ||
1910 | - m_TotalObjMtx.lock(); | ||
1911 | - if (m_total_obj_info.find(obj_key) != m_total_obj_info.end()) { | ||
1912 | - vector<sy_point>().swap(m_total_obj_info[obj_key].center_points); | ||
1913 | - m_total_obj_info.erase(obj_key); | ||
1914 | - } | ||
1915 | - m_TotalObjMtx.unlock(); | ||
1916 | - | ||
1917 | - | ||
1918 | - map<OBJ_KEY, OBJ_VALUES> _total_snapshot_info = m_snapshot_reprocessing->get_total_village_snapshot_info(); | ||
1919 | - if(_total_snapshot_info.size() <= 0){ | ||
1920 | - continue; | ||
1921 | - } | ||
1922 | - | ||
1923 | - LOG_DEBUG("_total_snapshot_info size: {}", _total_snapshot_info.size()); | ||
1924 | - auto it = _total_snapshot_info.find(obj_key); | ||
1925 | - if (it == _total_snapshot_info.end()) { | ||
1926 | - continue; | ||
1927 | - } | ||
1928 | - | ||
1929 | - | ||
1930 | - // 推送轨迹结束的目标用于数量统计 | ||
1931 | - { | ||
1932 | - const OBJ_VALUES obj_value = it->second; | ||
1933 | - std::vector<video_object_snapshot> algo_results; | ||
1934 | - std::vector<int> algorithm_types; | ||
1935 | - algorithm_types.push_back((int)algorithm_type_t::FLOW_STATISTICS); | ||
1936 | -#ifdef POST_USE_RABBITMQ | ||
1937 | - video_object_snapshot new_obj_ss_info; | ||
1938 | - new_obj_ss_info.analysisRes = nullptr; | ||
1939 | - new_obj_ss_info.object_id = obj_key.obj_id; | ||
1940 | - new_obj_ss_info.obj_info.set_data(obj_value.snapShots[1].index.index, obj_value.snapShots[1].confidence, 0, 0, 0, 0); | ||
1941 | - strcpy(new_obj_ss_info.task_id, obj_key.video_id.c_str()); | ||
1942 | - strcpy(new_obj_ss_info.video_image_path, ""); | ||
1943 | - strcpy(new_obj_ss_info.snapshot_image_path, ""); | ||
1944 | - algo_results.push_back(new_obj_ss_info); | ||
1945 | - auto json_str = helpers::gen_json::gen_village_json(task_id, obj_key.obj_id, algorithm_types, algo_results, ""); | ||
1946 | - mq_manager_->publish(mq_type_t::ALARM_MQ, json_str.c_str(), true); | ||
1947 | -#endif | ||
1948 | - } | ||
1949 | - | ||
1950 | - | ||
1951 | - if (village_alarm) { | ||
1952 | - const OBJ_VALUES obj_value = it->second; | ||
1953 | - std::string cur_timestamp_ms = std::to_string(helpers::timer::get_cur_time_ms()); | ||
1954 | - // 视频 | ||
1955 | - string video_file_name = video_folder + helpers::os::sep + obj_key.video_id + "_" + | ||
1956 | - std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".mp4"; | ||
1957 | - | ||
1958 | - string json_str = ""; | ||
1959 | - std::vector<video_object_snapshot> algo_results; | ||
1960 | - for (int sp_idx = 0; sp_idx < 3; sp_idx ++) { | ||
1961 | - int num = sp_idx + 1; | ||
1962 | - // 原图 | ||
1963 | - LOG_DEBUG("原图"); | ||
1964 | - std::string fpath_origin = result_folder + helpers::os::sep + obj_key.video_id + "_" + | ||
1965 | - std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + "_picnum_" + std::to_string(num) + ".jpg"; | ||
1966 | - | ||
1967 | - ImgSaveInfo origin_save_info; | ||
1968 | - origin_save_info.file_path = fpath_origin; | ||
1969 | - origin_save_info.img_info = obj_value.snapShots[sp_idx].snapShot; | ||
1970 | - origin_save_info.obj_rect = obj_value.snapShots[sp_idx].obj_pos; | ||
1971 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(origin_save_info); | ||
1972 | - | ||
1973 | - | ||
1974 | - LOG_DEBUG("抠图"); | ||
1975 | - // 抠图 | ||
1976 | - string object_file_name = result_folder_little + helpers::os::sep + obj_key.video_id + "_" + | ||
1977 | - std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + "_picnum_" + std::to_string(num) + ".jpg"; | ||
1978 | - ImgSaveInfo obj_save_info; | ||
1979 | - obj_save_info.file_path = object_file_name; | ||
1980 | - obj_save_info.img_info = obj_value.snapShots[sp_idx].snapShotLittle; | ||
1981 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(obj_save_info); | ||
1982 | - | ||
1983 | -#ifdef POST_USE_RABBITMQ | ||
1984 | - video_object_snapshot new_obj_ss_info; | ||
1985 | - new_obj_ss_info.analysisRes = nullptr; | ||
1986 | - new_obj_ss_info.object_id = obj_key.obj_id; | ||
1987 | - new_obj_ss_info.obj_info.set_data(obj_value.snapShots[sp_idx].index.index, obj_value.snapShots[sp_idx].confidence, obj_value.snapShots[sp_idx].obj_pos.left_, | ||
1988 | - obj_value.snapShots[sp_idx].obj_pos.top_, obj_value.snapShots[sp_idx].obj_pos.left_ + obj_value.snapShots[sp_idx].obj_pos.width_, | ||
1989 | - obj_value.snapShots[sp_idx].obj_pos.top_ + obj_value.snapShots[sp_idx].obj_pos.height_); | ||
1990 | - strcpy(new_obj_ss_info.task_id, obj_key.video_id.c_str()); | ||
1991 | - strcpy(new_obj_ss_info.video_image_path, fpath_origin.c_str()); | ||
1992 | - strcpy(new_obj_ss_info.snapshot_image_path, object_file_name.c_str()); | ||
1993 | - algo_results.push_back(new_obj_ss_info); | ||
1994 | -#endif | ||
1995 | - } | ||
1996 | - | ||
1997 | -#ifdef POST_USE_RABBITMQ | ||
1998 | - json_str = helpers::gen_json::gen_village_json(task_id, obj_key.obj_id, algorithm_types, algo_results, video_file_name); | ||
1999 | -#endif | ||
2000 | - | ||
2001 | - DeviceMemory* mem = vec_vptMem[i]; | ||
2002 | - // string task_id = mem->getId(); | ||
2003 | - RecoderInfo recoderInfo; | ||
2004 | - recoderInfo.task_id = task_id; | ||
2005 | - recoderInfo.object_id = std::to_string(j); | ||
2006 | - recoderInfo.recoderPath = video_file_name; | ||
2007 | - recoderInfo.frame_nb = mem->getFrameNb(); | ||
2008 | - recoderInfo.mq_info = json_str; | ||
2009 | - | ||
2010 | - m_recoderinfo_queue_mtx.lock(); | ||
2011 | - m_recoderinfo_queue.push_back(recoderInfo); | ||
2012 | - m_recoderinfo_queue_mtx.unlock(); | ||
2013 | - | ||
2014 | - LOG_DEBUG("仅删除记录,显存会在保存线程中删除"); | ||
2015 | - // 仅删除记录,显存会在保存线程中删除 | ||
2016 | - m_snapshot_reprocessing->release_village_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, false); | ||
2017 | - } | ||
2018 | - else { | ||
2019 | - // 删除记录,同时释放显存 | ||
2020 | - m_snapshot_reprocessing->release_village_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, true); | ||
2021 | - } | ||
2022 | - | ||
2023 | - } | ||
2024 | - } | ||
2025 | - | ||
2026 | -} | ||
2027 | - | ||
2028 | - | ||
2029 | -// for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径) | ||
2030 | -void CMultiSourceProcess::retrograde_snapshot(vector<string>& vpt_interest_task_id, vector<vector<int>> deleteObjectID) { | ||
2031 | - auto task_iter = vpt_interest_task_id.begin(); | ||
2032 | - | ||
2033 | - for (int i = 0; i < deleteObjectID.size(); i++, ++task_iter) // loop taskId. | ||
2034 | - { | ||
2035 | - for (int &j : deleteObjectID[i]) // loop algor type. | ||
2036 | - { | ||
2037 | - OBJ_KEY obj_key = {*task_iter, j}; | ||
2038 | - auto task_param_ptr = m_task_param_manager->get_task_algor_param(obj_key.video_id); | ||
2039 | - | ||
2040 | - /* 开启行人&机动车逆行算法模块,获取该目标的算法分析结果 返回结果+快照 最后释放资源 */ | ||
2041 | - if (task_param_ptr->human_algors.find(algorithm_type_t::PEDESTRIAN_RETROGRADE) != task_param_ptr->human_algors.end()){ | ||
2042 | - retrograde_trespass_alarm(obj_key, algorithm_type_t::PEDESTRIAN_RETROGRADE); | ||
2043 | - } | ||
2044 | - | ||
2045 | - if (task_param_ptr->vehicle_algors.find(algorithm_type_t::VEHICLE_RETROGRADE) != task_param_ptr->vehicle_algors.end()){ | ||
2046 | - retrograde_trespass_alarm(obj_key, algorithm_type_t::VEHICLE_RETROGRADE); | ||
2047 | - } | ||
2048 | - } | ||
2049 | - } | ||
2050 | -} | ||
2051 | - | ||
2052 | -// for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径) | ||
2053 | -void CMultiSourceProcess::trespass_snapshot(vector<string>& vpt_interest_task_id, vector<vector<int>> deleteObjectID) { | ||
2054 | - auto task_iter = vpt_interest_task_id.begin(); | ||
2055 | - | ||
2056 | - for (int i = 0; i < deleteObjectID.size(); i++, ++task_iter) // loop taskId. | ||
2057 | - { | ||
2058 | - for (int &j : deleteObjectID[i]) // loop algor type. | ||
2059 | - { | ||
2060 | - OBJ_KEY obj_key = {*task_iter, j}; | ||
2061 | - auto task_param_ptr = m_task_param_manager->get_task_algor_param(obj_key.video_id); | ||
2062 | - | ||
2063 | - if (task_param_ptr->human_algors.find(algorithm_type_t::PEDESTRIAN_TRESPASS) != task_param_ptr->human_algors.end()){ | ||
2064 | - retrograde_trespass_alarm(obj_key, algorithm_type_t::PEDESTRIAN_TRESPASS); | ||
2065 | - } | ||
2066 | - | ||
2067 | - if (task_param_ptr->vehicle_algors.find(algorithm_type_t::VEHICLE_TRESPASS) != task_param_ptr->vehicle_algors.end()){ | ||
2068 | - retrograde_trespass_alarm(obj_key, algorithm_type_t::VEHICLE_TRESPASS); | ||
2069 | - } | ||
2070 | - } | ||
2071 | - } | ||
2072 | -} | ||
2073 | - | ||
2074 | - | ||
2075 | -void CMultiSourceProcess::retrograde_trespass_alarm(const OBJ_KEY &obj_key, const algorithm_type_t &algor_type) { | ||
2076 | - | ||
2077 | - vector<ai_engine_module::result_data_t> results ; | ||
2078 | - if(algor_type == algorithm_type_t::PEDESTRIAN_RETROGRADE || algor_type == algorithm_type_t::VEHICLE_RETROGRADE){ | ||
2079 | - results = pedestrian_vehicle_retrograde_.get_results_by_id(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algor_type}); | ||
2080 | - } else if(algor_type == algorithm_type_t::PEDESTRIAN_TRESPASS || algor_type == algorithm_type_t::VEHICLE_TRESPASS){ | ||
2081 | - results = pedestrian_vehicle_trespass_.get_results_by_id(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algor_type}); | ||
2082 | - } else { | ||
2083 | - return ; | ||
2084 | - } | ||
2085 | - | ||
2086 | - | ||
2087 | - bool bRetroGrade = true ; | ||
2088 | - for (unsigned idx = 0; idx < results.size(); ++idx) { | ||
2089 | - auto &result = results[idx]; | ||
2090 | - | ||
2091 | - vpc_img_info src_img; | ||
2092 | - src_img.pic_desc = result.origin_img_desc; | ||
2093 | - src_img.task_id = obj_key.video_id; | ||
2094 | - | ||
2095 | - vpc_img_info roi_img; | ||
2096 | - roi_img.pic_desc = result.roi_img_desc; | ||
2097 | - roi_img.task_id = obj_key.video_id; | ||
2098 | - roi_img.object_id = obj_key.obj_id; | ||
2099 | - | ||
2100 | - if(bRetroGrade){ | ||
2101 | - auto &&json_str = helpers::gen_json::gen_retrograde_json(obj_key.video_id, obj_key.obj_id, result.box, algor_type); | ||
2102 | - save_snapshot_process(obj_key, algor_type, src_img, roi_img, idx, json_str); | ||
2103 | - } else { | ||
2104 | - VPCUtil::vpc_img_release(src_img); | ||
2105 | - VPCUtil::vpc_img_release(roi_img); | ||
2106 | - } | ||
2107 | - | ||
2108 | - if (bRetroGrade == true) { | ||
2109 | - bRetroGrade = false; | ||
2110 | - } | ||
2111 | - } | ||
2112 | -} | ||
2113 | - | ||
2114 | -bool CMultiSourceProcess::save_snapshot_process(const OBJ_KEY &obj_key, const algorithm_type_t &algorithm_type, vpc_img_info src_img, vpc_img_info roi_img, | ||
2115 | - const long long id,const std::string &json_str) { | ||
2116 | - auto task_other_params = m_task_param_manager->get_task_other_param(obj_key.video_id); | ||
2117 | - const auto &algor_other_params = task_other_params->find(algorithm_type); | ||
2118 | - if (algor_other_params == task_other_params->end()) { | ||
2119 | - LOG_ERROR("task_id {} not found {} error", obj_key.video_id, int(algorithm_type)); | ||
2120 | - return false; | ||
2121 | - } | ||
2122 | - | ||
2123 | - const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | ||
2124 | - | ||
2125 | - std::string cur_time1 = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>()); | ||
2126 | - const std::string fpath_origin = basic_param->result_folder + helpers::os::sep + obj_key.video_id + "_" + | ||
2127 | - std::to_string(obj_key.obj_id) + "_" + std::to_string(id) + "_" + cur_time1 + ".jpg"; | ||
2128 | - | ||
2129 | - ImgSaveInfo obj_save_info; | ||
2130 | - obj_save_info.file_path = fpath_origin; | ||
2131 | - obj_save_info.img_info = src_img; | ||
2132 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(obj_save_info); | ||
2133 | - | ||
2134 | - { | ||
2135 | - // 抠图保存 | ||
2136 | - std::string cur_time2 = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>()); | ||
2137 | - const std::string fpath_roi = basic_param->result_folder_little + helpers::os::sep + obj_key.video_id + "_" + | ||
2138 | - std::to_string(obj_key.obj_id) + "_" + std::to_string(id) + "_" + cur_time2 + ".jpg"; | ||
2139 | - | ||
2140 | - // 调用快照保存后处理模块 将快照保存 | ||
2141 | - ImgSaveInfo obj_save_info; | ||
2142 | - obj_save_info.file_path = fpath_roi; | ||
2143 | - obj_save_info.img_info = roi_img; | ||
2144 | - obj_save_info.json_str = json_str; | ||
2145 | - | ||
2146 | -#ifdef POST_USE_RABBITMQ | ||
2147 | - if(json_str.length() > 0) { | ||
2148 | - auto json_str_tmp = helpers::string::replace_all(json_str, helpers::gen_json::ORI_IMAGE_PATH_PLACEHOLDER, fpath_origin); | ||
2149 | - obj_save_info.json_str = helpers::string::replace_all(json_str_tmp, helpers::gen_json::ROI_IMAGE_PATH_PLACEHOLDER, fpath_roi); | ||
2150 | - } | ||
2151 | -#endif | ||
2152 | - | ||
2153 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(obj_save_info); | ||
2154 | - } | ||
2155 | - | ||
2156 | - return true; | ||
2157 | -} | ||
2158 | - | ||
2159 | -// 人脸检测抓拍算法模块 | ||
2160 | -void CMultiSourceProcess::algorthim_face_detect(vector<DeviceMemory*> vec_gpuMem) { | ||
2161 | - | ||
2162 | - vector<string> interest_task_list; | ||
2163 | - vector<sy_img> interest_imgs; | ||
2164 | - vector<DeviceMemory*> vec_vptMem; | ||
2165 | - for (int i = 0; i < vec_gpuMem.size(); i++) { | ||
2166 | - DeviceMemory* mem = vec_gpuMem[i]; | ||
2167 | - if (!task_has_face_algor(mem->getId())){ | ||
2168 | - continue; | ||
2169 | - } | ||
2170 | - | ||
2171 | - sy_img img; | ||
2172 | - img.w_ = mem->getWidth(); | ||
2173 | - img.h_ = mem->getHeight(); | ||
2174 | - img.c_ = mem->getChannel(); | ||
2175 | - img.data_ = mem->getMem(); | ||
2176 | - interest_imgs.push_back(img); | ||
2177 | - interest_task_list.push_back(mem->getId()); | ||
2178 | - vec_vptMem.push_back(mem); | ||
2179 | - } | ||
2180 | - | ||
2181 | - if (!interest_imgs.empty()) { | ||
2182 | - | ||
2183 | - unsigned image_size = interest_imgs.size(); | ||
2184 | - | ||
2185 | - // 人脸检测、跟踪 | ||
2186 | - std::vector<onelevel_det_result> facedet_result(image_size); | ||
2187 | - std::vector<std::vector<int>> face_deleteObjectID(image_size); | ||
2188 | - | ||
2189 | - int ret = m_face_det_ai_engine.ai_engine_process_batch(interest_task_list, interest_imgs.data(), facedet_result, face_deleteObjectID); | ||
2190 | - if(ret <= 0){ | ||
2191 | - LOG_ERROR("face detect error!!!"); | ||
2192 | - return; | ||
2193 | - } | ||
2194 | - | ||
2195 | - // 跟踪结果送入快照更新 | ||
2196 | - m_snapshot_reprocessing->update_face_bestsnapshot(vec_vptMem, facedet_result, face_deleteObjectID); | ||
2197 | - | ||
2198 | - // 保存已结束轨迹的目标 | ||
2199 | - auto task_iter_face = interest_task_list.begin(); //debug by zsh | ||
2200 | - for (int i = 0; i < face_deleteObjectID.size(); i++) { | ||
2201 | - for (int j = 0; j < face_deleteObjectID[i].size(); ++j) { | ||
2202 | - OBJ_KEY deleteObj = {*task_iter_face, face_deleteObjectID[i][j]}; | ||
2203 | - LOG_TRACE("{}: {}",*task_iter_face,face_deleteObjectID[i][j]); | ||
2204 | - face_locus_finished(deleteObj); | ||
2205 | - } | ||
2206 | - ++task_iter_face; | ||
2207 | - } | ||
2208 | - | ||
2209 | - for (int i = 0; i < face_deleteObjectID.size(); ++i){ | ||
2210 | - std::vector<int>().swap(face_deleteObjectID[i]); | ||
2211 | - } | ||
2212 | - std::vector<std::vector<int>>().swap(face_deleteObjectID); | ||
2213 | - std::vector<onelevel_det_result>().swap(facedet_result); | ||
2214 | - } | ||
2215 | -} | ||
2216 | - | ||
2217 | -void CMultiSourceProcess::face_locus_finished(const OBJ_KEY obj_key) { | ||
2218 | - map<OBJ_KEY, OBJ_VALUE> _total_face_snapshot_info = m_snapshot_reprocessing->get_total_face_snapshot_info(); | ||
2219 | - | ||
2220 | - auto it = _total_face_snapshot_info.find(obj_key); | ||
2221 | - if ( it == _total_face_snapshot_info.end()) { | ||
2222 | - return; | ||
2223 | - } | ||
2224 | - | ||
2225 | - LOG_DEBUG("face reprocessing {}:{}.", obj_key.video_id, obj_key.obj_id); | ||
2226 | - | ||
2227 | - auto task_other_params = m_task_param_manager->get_task_other_params(); | ||
2228 | - | ||
2229 | - const algor_basic_config_param_t *cur_param = | ||
2230 | - ((algor_init_config_param_t *)(task_other_params[obj_key.video_id][algorithm_type_t::FACE_SNAPSHOT]))->basic_param; | ||
2231 | - | ||
2232 | - OBJ_VALUE obj_value = it->second; | ||
2233 | - | ||
2234 | - std::string cur_time1 = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>()); | ||
2235 | - | ||
2236 | - // 原图 | ||
2237 | - string fpath_src = std::string(cur_param->result_folder) + helpers::os::sep + obj_key.video_id + "_" + | ||
2238 | - std::to_string(obj_key.obj_id) + "_" + cur_time1 + ".jpg"; | ||
2239 | - | ||
2240 | - ImgSaveInfo origin_save_info; | ||
2241 | - origin_save_info.file_path = fpath_src; | ||
2242 | - origin_save_info.img_info = obj_value.snapShot; | ||
2243 | - origin_save_info.obj_rect = obj_value.obj_pos; | ||
2244 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(origin_save_info); | ||
2245 | - | ||
2246 | - // 抠图 | ||
2247 | - string json_str = ""; | ||
2248 | - std::string cur_time2 = std::to_string(helpers::timer::get_timestamp<std::chrono::milliseconds>()); | ||
2249 | - string fpath_snapShotLittle = std::string(cur_param->result_folder_little) + helpers::os::sep + obj_key.video_id + "_" + | ||
2250 | - std::to_string(obj_key.obj_id) + "_" + cur_time2 + ".jpg"; | ||
2251 | - | ||
2252 | -#ifdef POST_USE_RABBITMQ | ||
2253 | - json_str = helpers::gen_json::gen_face_detection_json( obj_key.video_id, obj_key.obj_id, fpath_snapShotLittle, fpath_src, | ||
2254 | - obj_value.position, obj_value.confidence, obj_value.landmark_point, 25); | ||
2255 | -#endif | ||
2256 | - | ||
2257 | - ImgSaveInfo roi_save_info; | ||
2258 | - roi_save_info.file_path = fpath_snapShotLittle; | ||
2259 | - roi_save_info.img_info = obj_value.snapShotLittle; | ||
2260 | - roi_save_info.json_str = json_str; | ||
2261 | - m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(roi_save_info); | ||
2262 | - | ||
2263 | - // 删除结束轨迹的数据 | ||
2264 | - m_snapshot_reprocessing->release_finished_face_locus_snapshot(obj_key.video_id, obj_key.obj_id, false); | ||
2265 | -} | ||
2266 | - | ||
2267 | -int CMultiSourceProcess::recode_thread() { | ||
2268 | - LOG_INFO("recode_thread start..."); | ||
2269 | - | ||
2270 | - while(true) { | ||
2271 | - | ||
2272 | - if(m_bfinish){ | ||
2273 | - break; | ||
2274 | - } | ||
2275 | - | ||
2276 | - m_recoderinfo_queue_mtx.lock(); | ||
2277 | - if(m_recoderinfo_queue.size() <= 0) { | ||
2278 | - m_recoderinfo_queue_mtx.unlock(); | ||
2279 | - std::this_thread::sleep_for(std::chrono::milliseconds(5)); | ||
2280 | - continue; | ||
2281 | - } | ||
2282 | - | ||
2283 | - RecoderInfo info = m_recoderinfo_queue.front(); | ||
2284 | - m_recoderinfo_queue.pop_front(); | ||
2285 | - m_recoderinfo_queue_mtx.unlock(); | ||
2286 | - | ||
2287 | - DecoderManager* pDecManager = DecoderManager::getInstance(); | ||
2288 | - pDecManager->doRecode(info); | ||
2289 | - } | ||
2290 | - | ||
2291 | - LOG_INFO("recode_thread end."); | ||
2292 | -} | ||
2293 | - | ||
2294 | -bool CMultiSourceProcess::CheckTime() { | ||
2295 | - struct tm* info; | ||
2296 | - int nYear, nMonth, nDay; | ||
2297 | - time_t raw; | ||
2298 | - time(&raw); | ||
2299 | - info = localtime(&raw); | ||
2300 | - nYear = info->tm_year + 1900; | ||
2301 | - nMonth = info->tm_mon + 1; | ||
2302 | - nDay = info->tm_mday; | ||
2303 | - if ((nYear == 2023 && nMonth <= 12) || (nYear == 2024 && nMonth <= 2)) | ||
2304 | - { | ||
2305 | - return true; | ||
2306 | - } | ||
2307 | - else | ||
2308 | - { | ||
2309 | - return false; | ||
2310 | - } | ||
2311 | -} | ||
2312 | \ No newline at end of file | 0 | \ No newline at end of file |
src/demo/demo.cpp
@@ -1122,61 +1122,42 @@ void test_gpu(int gpuID){ | @@ -1122,61 +1122,42 @@ void test_gpu(int gpuID){ | ||
1122 | std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY, | 1122 | std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY, |
1123 | algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND}; | 1123 | algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND}; |
1124 | 1124 | ||
1125 | -/* | 1125 | + |
1126 | int repeat_num = 1000; | 1126 | int repeat_num = 1000; |
1127 | + createTask(handle, algor_vec2, 0, false); | ||
1128 | + createTask(handle, algor_vec2, 2, false); | ||
1127 | while(repeat_num--) { | 1129 | while(repeat_num--) { |
1128 | - printf("============================:%d\n",repeat_num); | ||
1129 | - string task_id = createTask(handle, algor_vec, 3 + gpuID * 10); | ||
1130 | - string task_id1 = createTask(handle, algor_vec2, 5); | ||
1131 | - string task_id2 = createTask(handle, algor_vec2, 6); | ||
1132 | -*/ | ||
1133 | - | ||
1134 | - // string task_id = createTask(handle, algor_vec, 3 + gpuID * 10); | ||
1135 | - // string task_id1 = createTask(handle, algor_vec2, 5); | ||
1136 | - // createTask(handle, algor_vec, 18, false); | ||
1137 | - // createTask(handle, algor_vec, 20, false); | ||
1138 | - // createTask(handle, algor_vec, 20, false); | ||
1139 | - // createTask(handle, algor_vec, 20, false); | ||
1140 | - // createTask(handle, algor_vec, 20, false); | ||
1141 | - createTask(handle, algor_vec, 0); | ||
1142 | - // createTask(handle, algor_vec, 1); | ||
1143 | - // createTask(handle, algor_vec, 2); | ||
1144 | - // createTask(handle, algor_vec, 3); | ||
1145 | -/* | ||
1146 | - | ||
1147 | - createTask(handle, algor_vec, 0, false); | ||
1148 | - createTask(handle, algor_vec, 0, false); | ||
1149 | - createTask(handle, algor_vec, 0, false); | ||
1150 | - createTask(handle, algor_vec, 0, false); | ||
1151 | - createTask(handle, algor_vec, 0, false); | ||
1152 | - createTask(handle, algor_vec, 0, false); | ||
1153 | - createTask(handle, algor_vec, 2, false); | ||
1154 | - createTask(handle, algor_vec, 2, false); | ||
1155 | - createTask(handle, algor_vec, 2, false); | ||
1156 | - createTask(handle, algor_vec, 2, false); | ||
1157 | - createTask(handle, algor_vec, 2, false); | ||
1158 | - createTask(handle, algor_vec, 2, false); | ||
1159 | - | ||
1160 | -/* | 1130 | + printf("============================:%d\n",repeat_num); |
1131 | + vector<string> task_ids; | ||
1132 | + for (int i = 4; i < 10; i ++) { | ||
1133 | + string task_id = createTask(handle, algor_vec2, i, false); | ||
1134 | + task_ids.push_back(task_id); | ||
1135 | + } | ||
1136 | + | ||
1161 | // test_snapshot(handle); | 1137 | // test_snapshot(handle); |
1162 | sleep(60); //60s | 1138 | sleep(60); //60s |
1163 | - finish_task(handle, (char*)task_id2.data(), 0); | ||
1164 | - finish_task(handle, (char*)task_id1.data(), 0); | ||
1165 | - }*/ | 1139 | + close_all_task(handle); |
1140 | + for (auto& task_id : task_ids) { | ||
1141 | + finish_task(handle, (char*)task_id.data(), 0); | ||
1142 | + sleep(5); | ||
1143 | + } | ||
1166 | 1144 | ||
1145 | + } | ||
1146 | + | ||
1147 | + /* | ||
1167 | char ch = 'a'; | 1148 | char ch = 'a'; |
1168 | while (ch != 'q') { | 1149 | while (ch != 'q') { |
1169 | ch = getchar(); | 1150 | ch = getchar(); |
1170 | switch (ch) | 1151 | switch (ch) |
1171 | { | 1152 | { |
1172 | case 'a': | 1153 | case 'a': |
1173 | - createTask(handle, algor_vec3, 4, false); | ||
1174 | - createTask(handle, algor_vec3, 5, false); | ||
1175 | - createTask(handle, algor_vec3, 6, false); | ||
1176 | - createTask(handle, algor_vec3, 7, false); | ||
1177 | - createTask(handle, algor_vec3, 8, false); | ||
1178 | - createTask(handle, algor_vec3, 9, false); | ||
1179 | - createTask(handle, algor_vec3, 10, false); | 1154 | + createTask(handle, algor_vec2, 4, false); |
1155 | + createTask(handle, algor_vec2, 5, false); | ||
1156 | + createTask(handle, algor_vec2, 6, false); | ||
1157 | + createTask(handle, algor_vec2, 7, false); | ||
1158 | + createTask(handle, algor_vec2, 8, false); | ||
1159 | + createTask(handle, algor_vec2, 9, false); | ||
1160 | + createTask(handle, algor_vec2, 10, false); | ||
1180 | // createTask(handle, algor_vec2, 11, false); | 1161 | // createTask(handle, algor_vec2, 11, false); |
1181 | // createTask(handle, algor_vec2, 12, false); | 1162 | // createTask(handle, algor_vec2, 12, false); |
1182 | // createTask(handle, algor_vec2, 13, false); | 1163 | // createTask(handle, algor_vec2, 13, false); |
@@ -1193,7 +1174,7 @@ void test_gpu(int gpuID){ | @@ -1193,7 +1174,7 @@ void test_gpu(int gpuID){ | ||
1193 | break; | 1174 | break; |
1194 | } | 1175 | } |
1195 | 1176 | ||
1196 | - } | 1177 | + }*/ |
1197 | 1178 | ||
1198 | // finish_task(handle, (char*)task_id.data(), 0); | 1179 | // finish_task(handle, (char*)task_id.data(), 0); |
1199 | 1180 |