Commit 9b8c645d9558a9e4f16f1a218ebdaf7a29d04864
Merge branch 'dev-cmhu' into 'master'
Dev cmhu See merge request !7
Showing
8 changed files
with
418 additions
and
22 deletions
.gitignore
src/ai_platform/MultiSourceProcess.cpp
... | ... | @@ -736,6 +736,8 @@ int CMultiSourceProcess::algorthim_vpt(vector<DeviceMemory*> vec_gpuMem){ |
736 | 736 | /* for pedestrian safety det. 行人安全分析算法模块 */ |
737 | 737 | // algorthim_pedestrian_safety(vpt_interest_task_id, vpt_interest_imgs,vptResult); |
738 | 738 | |
739 | + // 农村违法分析的快照缓存 | |
740 | + m_snapshot_reprocessing->update_village_bestsnapshot(vec_vptMem, vptResult, deleteObjectID); | |
739 | 741 | // 逆行 |
740 | 742 | algorthim_retrograde(vpt_interest_task_id, vec_vptMem, vptResult); |
741 | 743 | retrograde_snapshot(vpt_interest_task_id, deleteObjectID); |
... | ... | @@ -1222,12 +1224,22 @@ void CMultiSourceProcess::manned_snapshot(vector<string>& vpt_interest_task_id, |
1222 | 1224 | OBJ_KEY obj_key = {*task_iter, j}; |
1223 | 1225 | auto task_param_ptr = m_task_param_manager->get_task_algor_param(obj_key.video_id); |
1224 | 1226 | bool tricycle_manned_alarm = false, truck_manned_alarm = false, motor_overman_alarm = false, motor_nohelmet_alarm = false; |
1227 | + std::string video_folder = "", result_folder = "", result_folder_little = ""; //要求各事件使用同一个视频保存地址,否则会被最后一个事件的地址覆盖 | |
1228 | + auto task_other_params = m_task_param_manager->get_task_other_param(task_id); | |
1229 | + std::vector<int> algorithm_types; | |
1230 | + bool save_single_algor_pic = false; // 是否保存单算法的报警图片 | |
1225 | 1231 | |
1226 | 1232 | if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::TRICYCLE_MANNED) != task_param_ptr->nonmotor_vehicle_algors.end()) { |
1233 | + const auto &algor_other_params = task_other_params->find(algorithm_type_t::TRICYCLE_MANNED); | |
1234 | + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | |
1235 | + | |
1227 | 1236 | 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}); |
1228 | 1237 | if (result.get()) { |
1229 | 1238 | tricycle_manned_alarm = true; |
1230 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRICYCLE_MANNED); | |
1239 | + algorithm_types.push_back((int)algorithm_type_t::TRICYCLE_MANNED); | |
1240 | + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; | |
1241 | + result_folder_little = basic_param->result_folder_little; | |
1242 | + | |
1231 | 1243 | vpc_img_info src_img; |
1232 | 1244 | src_img.pic_desc = result->origin_img_desc; |
1233 | 1245 | src_img.task_id = obj_key.video_id; |
... | ... | @@ -1237,15 +1249,28 @@ void CMultiSourceProcess::manned_snapshot(vector<string>& vpt_interest_task_id, |
1237 | 1249 | roi_img.task_id = obj_key.video_id; |
1238 | 1250 | roi_img.object_id = obj_key.obj_id; |
1239 | 1251 | |
1240 | - save_snapshot_process(obj_key, algorithm_type_t::TRICYCLE_MANNED, src_img, roi_img, 0, json_str); | |
1252 | + if (save_single_algor_pic) { | |
1253 | + auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRICYCLE_MANNED); | |
1254 | + save_snapshot_process(obj_key, algorithm_type_t::TRICYCLE_MANNED, src_img, roi_img, 0, json_str); | |
1255 | + } else { | |
1256 | + VPCUtil::vpc_img_release(src_img); | |
1257 | + VPCUtil::vpc_img_release(roi_img); | |
1258 | + } | |
1259 | + | |
1241 | 1260 | } |
1242 | 1261 | } |
1243 | 1262 | |
1244 | 1263 | if (task_param_ptr->vehicle_algors.find(algorithm_type_t::TRUCK_MANNED) != task_param_ptr->vehicle_algors.end()) { |
1264 | + const auto &algor_other_params = task_other_params->find(algorithm_type_t::TRUCK_MANNED); | |
1265 | + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | |
1266 | + | |
1245 | 1267 | 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}); |
1246 | 1268 | if (result.get()) { |
1247 | 1269 | truck_manned_alarm = true; |
1248 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRUCK_MANNED); | |
1270 | + algorithm_types.push_back((int)algorithm_type_t::TRUCK_MANNED); | |
1271 | + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; | |
1272 | + result_folder_little = basic_param->result_folder_little; | |
1273 | + | |
1249 | 1274 | vpc_img_info src_img; |
1250 | 1275 | src_img.pic_desc = result->origin_img_desc; |
1251 | 1276 | src_img.task_id = obj_key.video_id; |
... | ... | @@ -1255,15 +1280,28 @@ void CMultiSourceProcess::manned_snapshot(vector<string>& vpt_interest_task_id, |
1255 | 1280 | roi_img.task_id = obj_key.video_id; |
1256 | 1281 | roi_img.object_id = obj_key.obj_id; |
1257 | 1282 | |
1258 | - save_snapshot_process(obj_key, algorithm_type_t::TRUCK_MANNED, src_img, roi_img, 0, json_str); | |
1283 | + if (save_single_algor_pic) { | |
1284 | + auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRUCK_MANNED); | |
1285 | + save_snapshot_process(obj_key, algorithm_type_t::TRUCK_MANNED, src_img, roi_img, 0, json_str); | |
1286 | + } else { | |
1287 | + VPCUtil::vpc_img_release(src_img); | |
1288 | + VPCUtil::vpc_img_release(roi_img); | |
1289 | + } | |
1290 | + | |
1259 | 1291 | } |
1260 | 1292 | } |
1261 | 1293 | |
1262 | 1294 | if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET) != task_param_ptr->nonmotor_vehicle_algors.end()) { |
1295 | + const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET); | |
1296 | + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | |
1297 | + | |
1263 | 1298 | auto result = motor_hsprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET}); |
1264 | 1299 | if (result.get()) { |
1265 | 1300 | motor_nohelmet_alarm = true; |
1266 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET); | |
1301 | + algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET); | |
1302 | + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; | |
1303 | + result_folder_little = basic_param->result_folder_little; | |
1304 | + | |
1267 | 1305 | vpc_img_info src_img; |
1268 | 1306 | src_img.pic_desc = result->origin_img_desc; |
1269 | 1307 | src_img.task_id = obj_key.video_id; |
... | ... | @@ -1273,15 +1311,28 @@ void CMultiSourceProcess::manned_snapshot(vector<string>& vpt_interest_task_id, |
1273 | 1311 | roi_img.task_id = obj_key.video_id; |
1274 | 1312 | roi_img.object_id = obj_key.obj_id; |
1275 | 1313 | |
1276 | - save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, src_img, roi_img, 0, json_str); | |
1314 | + if (save_single_algor_pic) { | |
1315 | + auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET); | |
1316 | + save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, src_img, roi_img, 0, json_str); | |
1317 | + } else { | |
1318 | + VPCUtil::vpc_img_release(src_img); | |
1319 | + VPCUtil::vpc_img_release(roi_img); | |
1320 | + } | |
1321 | + | |
1277 | 1322 | } |
1278 | 1323 | } |
1279 | 1324 | |
1280 | 1325 | if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN) != task_param_ptr->nonmotor_vehicle_algors.end()) { |
1326 | + const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN); | |
1327 | + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; | |
1328 | + | |
1281 | 1329 | auto result = motor_hsprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN}); |
1282 | 1330 | if (result.get()) { |
1283 | 1331 | motor_overman_alarm = true; |
1284 | - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN); | |
1332 | + algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN); | |
1333 | + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; | |
1334 | + result_folder_little = basic_param->result_folder_little; | |
1335 | + | |
1285 | 1336 | vpc_img_info src_img; |
1286 | 1337 | src_img.pic_desc = result->origin_img_desc; |
1287 | 1338 | src_img.task_id = obj_key.video_id; |
... | ... | @@ -1291,24 +1342,98 @@ void CMultiSourceProcess::manned_snapshot(vector<string>& vpt_interest_task_id, |
1291 | 1342 | roi_img.task_id = obj_key.video_id; |
1292 | 1343 | roi_img.object_id = obj_key.obj_id; |
1293 | 1344 | |
1294 | - save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, src_img, roi_img, 0, json_str); | |
1345 | + if (save_single_algor_pic) { | |
1346 | + auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN); | |
1347 | + save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, src_img, roi_img, 0, json_str); | |
1348 | + } else { | |
1349 | + VPCUtil::vpc_img_release(src_img); | |
1350 | + VPCUtil::vpc_img_release(roi_img); | |
1351 | + } | |
1352 | + | |
1295 | 1353 | } |
1296 | 1354 | } |
1297 | 1355 | |
1356 | + | |
1357 | + map<OBJ_KEY, OBJ_VALUE> _total_snapshot_info = m_snapshot_reprocessing->get_total_village_snapshot_info(); | |
1358 | + if(_total_snapshot_info.size() <= 0){ | |
1359 | + return; | |
1360 | + } | |
1361 | + | |
1362 | + LOG_DEBUG("_total_snapshot_info size: {}", _total_snapshot_info.size()); | |
1363 | + auto it = _total_snapshot_info.find(obj_key); | |
1364 | + if (it == _total_snapshot_info.end()) { | |
1365 | + return; | |
1366 | + } | |
1367 | + | |
1368 | + | |
1298 | 1369 | if (tricycle_manned_alarm || truck_manned_alarm || motor_overman_alarm || motor_nohelmet_alarm) { |
1299 | 1370 | |
1371 | + const OBJ_VALUE obj_value = it->second; | |
1372 | + // 原图 | |
1373 | + LOG_DEBUG("原图"); | |
1374 | + std::string cur_timestamp_ms = std::to_string(helpers::timer::get_cur_time_ms()); | |
1375 | + std::string fpath_origin = result_folder + helpers::os::sep + obj_key.video_id + "_" + | |
1376 | + std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".jpg"; | |
1377 | + | |
1378 | + ImgSaveInfo origin_save_info; | |
1379 | + origin_save_info.file_path = fpath_origin; | |
1380 | + origin_save_info.img_info = obj_value.snapShot; | |
1381 | + origin_save_info.obj_rect = obj_value.obj_pos; | |
1382 | + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(origin_save_info); | |
1383 | + | |
1384 | + | |
1385 | + LOG_DEBUG("抠图"); | |
1386 | + // 抠图 | |
1387 | + string object_file_name = result_folder_little + helpers::os::sep + obj_key.video_id + "_" + | |
1388 | + std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".jpg"; | |
1389 | + ImgSaveInfo obj_save_info; | |
1390 | + obj_save_info.file_path = object_file_name; | |
1391 | + obj_save_info.img_info = obj_value.snapShotLittle; | |
1392 | + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(obj_save_info); | |
1393 | + | |
1394 | + | |
1395 | + // 视频 | |
1396 | + string video_file_name = video_folder + helpers::os::sep + obj_key.video_id + "_" + | |
1397 | + std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".mp4"; | |
1398 | + | |
1399 | + | |
1400 | + string json_str = ""; | |
1401 | +#ifdef POST_USE_RABBITMQ | |
1402 | + std::vector<video_object_snapshot> algo_results; | |
1403 | + video_object_snapshot new_obj_ss_info; | |
1404 | + new_obj_ss_info.analysisRes = nullptr; | |
1405 | + new_obj_ss_info.object_id = obj_key.obj_id; | |
1406 | + new_obj_ss_info.obj_info.set_data(obj_value.index.index, obj_value.confidence, obj_value.obj_pos.left_, | |
1407 | + obj_value.obj_pos.top_, obj_value.obj_pos.left_ + obj_value.obj_pos.width_, | |
1408 | + obj_value.obj_pos.top_ + obj_value.obj_pos.height_); | |
1409 | + strcpy(new_obj_ss_info.task_id, obj_key.video_id.c_str()); | |
1410 | + strcpy(new_obj_ss_info.video_image_path, fpath_origin.c_str()); | |
1411 | + strcpy(new_obj_ss_info.snapshot_image_path, object_file_name.c_str()); | |
1412 | + algo_results.push_back(new_obj_ss_info); | |
1413 | + json_str = helpers::gen_json::gen_village_json(task_id, obj_key.obj_id, algorithm_types, algo_results, video_file_name); | |
1414 | +#endif | |
1415 | + | |
1300 | 1416 | DeviceMemory* mem = vec_vptMem[i]; |
1301 | 1417 | // string task_id = mem->getId(); |
1302 | - // cout << "mem->getId():" << mem->getId() << " cur_task_id:" << task_id << endl; | |
1303 | 1418 | RecoderInfo recoderInfo; |
1304 | 1419 | recoderInfo.task_id = task_id; |
1305 | 1420 | recoderInfo.object_id = std::to_string(j); |
1306 | - recoderInfo.recoderPath = "./res/recode"; | |
1421 | + recoderInfo.recoderPath = video_file_name; | |
1307 | 1422 | recoderInfo.frame_nb = mem->getFrameNb(); |
1423 | + recoderInfo.mq_info = json_str; | |
1308 | 1424 | |
1309 | 1425 | m_recoderinfo_queue_mtx.lock(); |
1310 | 1426 | m_recoderinfo_queue.push_back(recoderInfo); |
1311 | 1427 | m_recoderinfo_queue_mtx.unlock(); |
1428 | + | |
1429 | + LOG_DEBUG("仅删除记录,显存会在保存线程中删除"); | |
1430 | + // 仅删除记录,显存会在保存线程中删除 | |
1431 | + m_snapshot_reprocessing->release_village_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, false); | |
1432 | + } | |
1433 | + else { | |
1434 | + // 删除记录,同时释放显存 | |
1435 | + m_snapshot_reprocessing->release_village_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, true); | |
1436 | + return; | |
1312 | 1437 | } |
1313 | 1438 | |
1314 | 1439 | |
... | ... | @@ -1542,7 +1667,7 @@ void CMultiSourceProcess::face_locus_finished(const OBJ_KEY obj_key) { |
1542 | 1667 | |
1543 | 1668 | #ifdef POST_USE_RABBITMQ |
1544 | 1669 | json_str = helpers::gen_json::gen_face_detection_json( obj_key.video_id, obj_key.obj_id, fpath_snapShotLittle, fpath_src, |
1545 | - obj_value.position, obj_value.confidence, obj_value.landmark_point, 25); | |
1670 | + obj_value.position, obj_value.confidence, obj_value.landmark_point, 25); | |
1546 | 1671 | #endif |
1547 | 1672 | |
1548 | 1673 | ImgSaveInfo roi_save_info; | ... | ... |
src/ai_platform/header.h
... | ... | @@ -441,8 +441,9 @@ typedef struct algor_basic_config_param_t { |
441 | 441 | sy_rect algor_valid_rect; |
442 | 442 | char *result_folder_little; //目标快照抠图保存地址 |
443 | 443 | char *result_folder; //目标快照大图保存地址 |
444 | + char *video_folder; //目标视频保存地址 | |
444 | 445 | explicit algor_basic_config_param_t() |
445 | - : result_folder_little(nullptr), result_folder(nullptr) {} | |
446 | + : result_folder_little(nullptr), result_folder(nullptr), video_folder(nullptr) {} | |
446 | 447 | } algor_basic_config_param_t; |
447 | 448 | #endif // #ifndef __ALGOR_CONFIG_PARAM__BASIC__ |
448 | 449 | ... | ... |
src/ai_platform/task_param_manager.cpp
... | ... | @@ -237,6 +237,13 @@ void task_param_manager::add_task_param(string task_id, task_param task_param) { |
237 | 237 | } else |
238 | 238 | dst_basic_param->result_folder = nullptr; |
239 | 239 | |
240 | + if (src_basic_param->video_folder) { | |
241 | + dst_basic_param->video_folder = new char[strlen(src_basic_param->video_folder) + 1]; | |
242 | + strcpy(dst_basic_param->video_folder, src_basic_param->video_folder); | |
243 | + CreateResultFolder(dst_basic_param->video_folder, ""); | |
244 | + } else | |
245 | + dst_basic_param->video_folder = nullptr; | |
246 | + | |
240 | 247 | dst_basic_param->algor_valid_rect.left_ = src_basic_param->algor_valid_rect.left_; |
241 | 248 | dst_basic_param->algor_valid_rect.top_ = src_basic_param->algor_valid_rect.top_; |
242 | 249 | dst_basic_param->algor_valid_rect.width_ = src_basic_param->algor_valid_rect.width_; |
... | ... | @@ -266,6 +273,10 @@ void task_param_manager::delete_task_param(string task_id) { |
266 | 273 | delete[] cur_param->result_folder; |
267 | 274 | cur_param->result_folder = nullptr; |
268 | 275 | } |
276 | + if (cur_param->video_folder) { | |
277 | + delete[] cur_param->video_folder; | |
278 | + cur_param->video_folder = nullptr; | |
279 | + } | |
269 | 280 | if (cur_param) { |
270 | 281 | delete ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->basic_param; |
271 | 282 | ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->basic_param = nullptr; | ... | ... |
src/demo/demo.cpp
... | ... | @@ -81,6 +81,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty |
81 | 81 | basic_params->algor_valid_rect.left_ = 0; |
82 | 82 | basic_params->algor_valid_rect.width_ = 1920; |
83 | 83 | basic_params->algor_valid_rect.height_ = 1080; |
84 | + basic_params->video_folder = "res/video_recode"; | |
84 | 85 | basic_params->result_folder = "res/motor_nohelmet"; |
85 | 86 | basic_params->result_folder_little = "res/motor_nohelmet_little"; |
86 | 87 | } |
... | ... | @@ -106,6 +107,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty |
106 | 107 | basic_params->algor_valid_rect.left_ = 0; |
107 | 108 | basic_params->algor_valid_rect.width_ = 1920; |
108 | 109 | basic_params->algor_valid_rect.height_ = 1080; |
110 | + basic_params->video_folder = "res/video_recode"; | |
109 | 111 | basic_params->result_folder = "res/motor_overman"; |
110 | 112 | basic_params->result_folder_little = "res/motor_overman_little"; |
111 | 113 | } |
... | ... | @@ -131,6 +133,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty |
131 | 133 | basic_params->algor_valid_rect.left_ = 0; |
132 | 134 | basic_params->algor_valid_rect.width_ = 1920; |
133 | 135 | basic_params->algor_valid_rect.height_ = 1080; |
136 | + basic_params->video_folder = "res/video_recode"; | |
134 | 137 | basic_params->result_folder = "res/tricycle_manned"; |
135 | 138 | basic_params->result_folder_little = "res/tricycle_manned_little"; |
136 | 139 | } |
... | ... | @@ -156,6 +159,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty |
156 | 159 | basic_params->algor_valid_rect.left_ = 0; |
157 | 160 | basic_params->algor_valid_rect.width_ = 1920; |
158 | 161 | basic_params->algor_valid_rect.height_ = 1080; |
162 | + basic_params->video_folder = "res/video_recode"; | |
159 | 163 | basic_params->result_folder = "res/truck_manned"; |
160 | 164 | basic_params->result_folder_little = "res/truck_manned_little"; |
161 | 165 | } | ... | ... |
src/helpers/gen_json.hpp
... | ... | @@ -236,16 +236,6 @@ namespace helpers |
236 | 236 | return gen_generic_json(taskId, object_id, box, algor_type, image_path); |
237 | 237 | } |
238 | 238 | |
239 | - | |
240 | - static std::string gen_manned_json(const std::string& taskId, int object_id, | |
241 | - const box_t &box, | |
242 | - const algorithm_type_t &algor_type, | |
243 | - const std::string &image_path = "") | |
244 | - { | |
245 | - return gen_generic_json(taskId, object_id, box, algor_type, image_path); | |
246 | - } | |
247 | - | |
248 | - | |
249 | 239 | static std::string gen_takeaway_member_cls_json(const std::string& taskId, int object_id, |
250 | 240 | const box_t &box, const int &category, |
251 | 241 | const std::string &image_path = "") |
... | ... | @@ -340,6 +330,60 @@ namespace helpers |
340 | 330 | return Json::writeString(get_builder(), root); |
341 | 331 | }; |
342 | 332 | |
333 | + | |
334 | + static std::string gen_village_json(const std::string& taskId, long object_id, std::vector<int> algorithm_types, std::vector<video_object_snapshot> const &algo_results, const std::string &video_path) { | |
335 | + Json::Value root; | |
336 | + root["task_id"] = taskId; | |
337 | + root["object_id"] = int(object_id); | |
338 | + root["timestamp_ms"] = std::to_string(timer::get_timestamp<std::chrono::milliseconds>()); | |
339 | + root["video_recode_path"] = video_path; | |
340 | + Json::Value algorNodes; | |
341 | + for (auto &algorithm_type: algorithm_types) { | |
342 | + Json::Value algorNode; | |
343 | + // algorNode["algor_type"] = algorithm_type; | |
344 | + // algorNodes.append(algorNode); | |
345 | + auto algor_type = std::to_string(algorithm_type); | |
346 | + algorNodes.append(algor_type); | |
347 | + } | |
348 | + root["algor_types"] = algorNodes; | |
349 | + { | |
350 | + Json::Value picNode; | |
351 | + Json::Value dataNode; | |
352 | + for (int i = 0; i < algo_results.size(); i++) { | |
353 | + int num = i + 1; | |
354 | + dataNode["picnum"] = num; | |
355 | + dataNode["video_image_path"] = algo_results[i].video_image_path; | |
356 | + dataNode["snapshot_image_path"] = algo_results[i].snapshot_image_path; | |
357 | + Json::Value boxNode; | |
358 | + { | |
359 | + Json::Value boxNodeItem; | |
360 | + boxNodeItem["top"] = algo_results[i].obj_info.res_top; | |
361 | + boxNodeItem["left"] = algo_results[i].obj_info.res_left; | |
362 | + boxNodeItem["right"] = algo_results[i].obj_info.res_right; | |
363 | + boxNodeItem["bottom"] = algo_results[i].obj_info.res_bottom; | |
364 | + boxNodeItem["score"] = algo_results[i].obj_info.res_prob; | |
365 | + boxNodeItem["index"] = algo_results[i].obj_info.res_index; //221212byzsh | |
366 | + boxNode.append(boxNodeItem); | |
367 | + dataNode["box"] = boxNode; | |
368 | + } | |
369 | + picNode.append(dataNode); | |
370 | + } | |
371 | + | |
372 | + root["data"] = picNode; | |
373 | + } | |
374 | + return Json::writeString(get_builder(), root); | |
375 | + } | |
376 | + | |
377 | + | |
378 | + static std::string gen_manned_json(const std::string& taskId, int object_id, | |
379 | + const box_t &box, | |
380 | + const algorithm_type_t &algor_type, | |
381 | + const std::string &image_path = "") | |
382 | + { | |
383 | + return gen_generic_json(taskId, object_id, box, algor_type, image_path); | |
384 | + } | |
385 | + | |
386 | + | |
343 | 387 | } // namespace gen_json |
344 | 388 | |
345 | 389 | } // namespace helpers | ... | ... |
src/reprocessing_module/snapshot_reprocessing.cpp
... | ... | @@ -330,6 +330,174 @@ void snapshot_reprocessing::update_bestsnapshot(vector<DeviceMemory*> vec_devMem |
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
333 | + | |
334 | +/* 获取农村违法分析要求的目标快照图--轨迹起始 最佳 轨迹结束 */ | |
335 | +void snapshot_reprocessing::update_village_bestsnapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &ol_det_result, vector<vector<int>>& delete_object_id){ | |
336 | + map<string, algor_open_config_param> && algor_config_param = m_task_param_manager->get_task_algor_params(); | |
337 | + map<string, map<algo_type, task_param_manager::algo_param_type_t_*>> && algor_param = m_task_param_manager->get_task_other_params(); | |
338 | + | |
339 | + VPCUtil* pVpcUtil = VPCUtil::getInstance(); | |
340 | + | |
341 | + for (size_t i = 0; i < vec_devMem.size(); i++){ | |
342 | + | |
343 | + onelevel_det_result det_result = ol_det_result[i]; | |
344 | + if (0 == det_result.obj_count){ | |
345 | + continue; | |
346 | + } | |
347 | + | |
348 | + DeviceMemory* memPtr = vec_devMem[i]; | |
349 | + | |
350 | + string task_id = memPtr->getId(); | |
351 | + int frame_height = memPtr->getHeight(); | |
352 | + int frame_width = memPtr->getWidth(); | |
353 | + | |
354 | + vector<video_object_info> vec_obj_info; | |
355 | + for (int c = 0; c < det_result.obj_count; c++){ | |
356 | + | |
357 | + det_objinfo obj_info = det_result.obj[c]; | |
358 | + OBJ_KEY new_obj = { task_id, obj_info.id }; | |
359 | + | |
360 | + int index = 0; | |
361 | + | |
362 | + /* 投票确定目标index */ | |
363 | + if (total_village_snapshot_info.find(new_obj) == total_village_snapshot_info.end()){ | |
364 | + index = obj_info.index; | |
365 | + } else { | |
366 | + index = total_village_snapshot_info[new_obj].index.index; | |
367 | + } | |
368 | + | |
369 | + int cur_real_width = (obj_info.right - obj_info.left); | |
370 | + int cur_real_height = (obj_info.bottom - obj_info.top); | |
371 | + int cur_real_index = obj_info.index; | |
372 | + | |
373 | + int expansion_width = cur_real_width * EXPANSION_PROPORTION; | |
374 | + int expansion_height = cur_real_height * EXPANSION_PROPORTION; | |
375 | + // DEBUG----------------------------------------------------------------- | |
376 | + // 0-行人 1-自行车 2-摩托车 3-三轮车 4-小型车 5-大车 6-卡车 7-拖拉机 8-中巴 | |
377 | + if(index ==0 || index ==1 || index ==2 || index ==3) { //行人和非机动车外扩指定像素即可 | |
378 | + expansion_width = 10; | |
379 | + expansion_height = 10; | |
380 | + } | |
381 | + | |
382 | + /* 若该目标第一次出现 */ | |
383 | + if (total_village_snapshot_info.find(new_obj) == total_village_snapshot_info.end()) | |
384 | + { | |
385 | + /* manager insert new object. */ | |
386 | + /* 判断目标合法 */ | |
387 | + // algorithm_type_t algor_type; | |
388 | + // if (index ==0) algor_type = algorithm_type_t::HUMAN_SNAPSHOT; | |
389 | + // if (index ==1 || index ==2 || index ==3) algor_type = algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT; | |
390 | + // if (index ==4 || index ==5 || index ==6 || index ==7 || index ==8) algor_type = algorithm_type_t::VEHICLE_SNAPSHOT; | |
391 | + // if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algor_type))) | |
392 | + // continue; | |
393 | + // task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type]; | |
394 | + // if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left, obj_info.top, obj_info.right, obj_info.bottom)){ | |
395 | + // continue; | |
396 | + // } | |
397 | + | |
398 | + if(!snapshot_legal_minarea(index, cur_real_width, cur_real_height)){ | |
399 | + continue; | |
400 | + } | |
401 | + | |
402 | + /* 存入当前抠图目标参数 flags用于判断目标从画面什么位置出现 方便之后排除出画面边缘的快照图 */ | |
403 | + total_village_snapshot_info[new_obj].index.count++; | |
404 | + total_village_snapshot_info[new_obj].index.index = cur_real_index; | |
405 | + total_village_snapshot_info[new_obj].confidence = obj_info.confidence; | |
406 | + total_village_snapshot_info[new_obj].flags[0] = obj_info.left < minDistance[0] + SCALE_OUT ? 0 : 1; //left | |
407 | + total_village_snapshot_info[new_obj].flags[1] = obj_info.top < minDistance[1] + SCALE_OUT ? 0 : 1; //top | |
408 | + total_village_snapshot_info[new_obj].flags[2] = obj_info.right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1; //right | |
409 | + total_village_snapshot_info[new_obj].flags[3] = obj_info.bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom | |
410 | + | |
411 | + int cur_left = max(obj_info.left - 10, 0); | |
412 | + int cur_top = max(obj_info.top - 10, 0); | |
413 | + int cur_right = min(obj_info.right + 10, frame_width - 1); | |
414 | + int cur_bottom = min(obj_info.bottom + 10, frame_height - 1); | |
415 | + total_village_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 | |
416 | + total_village_snapshot_info[new_obj].last_area = total_village_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); | |
417 | + | |
418 | + video_object_info info; | |
419 | + info.left = max(obj_info.left - expansion_width, 0); | |
420 | + info.top = max(obj_info.top - expansion_height, 0); | |
421 | + info.right = min(obj_info.right + expansion_width, frame_width - 1); | |
422 | + info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1); | |
423 | + strcpy(info.task_id, task_id.c_str()); | |
424 | + info.object_id = obj_info.id; | |
425 | + info.confidence = obj_info.confidence; | |
426 | + info.index = index; | |
427 | + | |
428 | + vec_obj_info.push_back(info); | |
429 | + } else { | |
430 | + total_village_snapshot_info[new_obj].last_area = (obj_info.right - obj_info.left) * (obj_info.bottom - obj_info.top); | |
431 | + | |
432 | + // algorithm_type_t algor_type; | |
433 | + // if (index ==0) algor_type = algorithm_type_t::HUMAN_SNAPSHOT; | |
434 | + // if (index ==1 || index ==2 || index ==3) algor_type = algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT; | |
435 | + // if (index ==4 || index ==5 || index ==6 || index ==7 || index ==8) algor_type = algorithm_type_t::VEHICLE_SNAPSHOT; | |
436 | + // if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algor_type))) | |
437 | + // continue; | |
438 | + // task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type]; | |
439 | + // if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left, obj_info.top, obj_info.right, obj_info.bottom)) | |
440 | + // continue; | |
441 | + //--------------------------------------------------------------- | |
442 | + if (!best_snapshot_judge_algor(new_obj, total_village_snapshot_info[new_obj], obj_info.left, obj_info.top, | |
443 | + cur_real_width, cur_real_height, frame_width, frame_height)) | |
444 | + { | |
445 | + continue; | |
446 | + } | |
447 | + /* 若更优于之前的快照 做快照的更新 */ | |
448 | + if (total_village_snapshot_info[new_obj].index.count == 0) | |
449 | + { | |
450 | + total_village_snapshot_info[new_obj].index.count++; | |
451 | + total_village_snapshot_info[new_obj].index.index = cur_real_index; | |
452 | + } | |
453 | + else | |
454 | + { | |
455 | + if (total_village_snapshot_info[new_obj].index.index == cur_real_index) | |
456 | + total_village_snapshot_info[new_obj].index.count++; | |
457 | + else | |
458 | + total_village_snapshot_info[new_obj].index.count--; | |
459 | + } | |
460 | + | |
461 | + int cur_left = max(obj_info.left - 10, 0); | |
462 | + int cur_top = max(obj_info.top - 10, 0); | |
463 | + int cur_right = min(obj_info.right + 10, frame_width - 1); | |
464 | + int cur_bottom = min(obj_info.bottom + 10, frame_height - 1); | |
465 | + total_village_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 | |
466 | + total_village_snapshot_info[new_obj].last_area = total_village_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); | |
467 | + | |
468 | + video_object_info info; | |
469 | + info.left = max(obj_info.left - expansion_width, 0); | |
470 | + info.top = max(obj_info.top - expansion_height, 0); | |
471 | + info.right = min(obj_info.right + expansion_width, frame_width - 1); | |
472 | + info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1); | |
473 | + strcpy(info.task_id, task_id.c_str()); | |
474 | + info.object_id = obj_info.id; | |
475 | + info.confidence = obj_info.confidence; | |
476 | + info.index = index; | |
477 | + | |
478 | + vec_obj_info.push_back(info); | |
479 | + } | |
480 | + } | |
481 | + | |
482 | + vector<vpc_img_info> imgList = pVpcUtil->crop_batch(memPtr, vec_obj_info); | |
483 | + vec_obj_info.clear(); | |
484 | + | |
485 | + for (size_t i = 0; i < imgList.size(); i++) { | |
486 | + vpc_img_info obj_info = imgList[i]; | |
487 | + OBJ_KEY objKey = { obj_info.task_id, obj_info.object_id }; | |
488 | + VPCUtil::vpc_img_release(total_village_snapshot_info[objKey].snapShot); | |
489 | + total_village_snapshot_info[objKey].snapShot = VPCUtil::vpc_devMem2vpcImg(memPtr); | |
490 | + VPCUtil::vpc_img_release(total_village_snapshot_info[objKey].snapShotLittle); | |
491 | + total_village_snapshot_info[objKey].snapShotLittle = obj_info; | |
492 | + } | |
493 | + imgList.clear(); | |
494 | + } | |
495 | +} | |
496 | + | |
497 | +map<OBJ_KEY, OBJ_VALUE> snapshot_reprocessing::get_total_village_snapshot_info(){ | |
498 | + return total_village_snapshot_info; | |
499 | +} | |
500 | + | |
333 | 501 | bool snapshot_reprocessing::best_face_snapshot_judge_algor_v2(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height, float roll, float yaw, float pitch) |
334 | 502 | { |
335 | 503 | return snapshot_legal_pos(obj_value.flags, left, top, left + width, top + height, image_width, image_height) |
... | ... | @@ -575,6 +743,43 @@ void snapshot_reprocessing::release_finished_locus_snapshot(const string taskid, |
575 | 743 | } |
576 | 744 | } |
577 | 745 | |
746 | + | |
747 | +void snapshot_reprocessing::release_village_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease) | |
748 | +{ | |
749 | + LOG_DEBUG("[info] task_id {} delete obj_id {}", taskid, obj_id); //221026 | |
750 | + if (obj_id != -1) | |
751 | + { | |
752 | + OBJ_KEY cur_key = { taskid , obj_id }; | |
753 | + auto it = total_village_snapshot_info.find(cur_key); | |
754 | + if (it == total_village_snapshot_info.end()){ | |
755 | + return; | |
756 | + } | |
757 | + | |
758 | + if (bRelease){ | |
759 | + OBJ_VALUE ss = total_village_snapshot_info[cur_key]; | |
760 | + | |
761 | + VPCUtil::vpc_img_release(ss.snapShot); | |
762 | + VPCUtil::vpc_img_release(ss.snapShotLittle); | |
763 | + } | |
764 | + | |
765 | + total_village_snapshot_info.erase(cur_key); | |
766 | + return; | |
767 | + } | |
768 | + | |
769 | + for(auto ss = total_village_snapshot_info.begin(); ss != total_village_snapshot_info.end(); ss++) | |
770 | + { | |
771 | + if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0) | |
772 | + { | |
773 | + if (bRelease){ | |
774 | + VPCUtil::vpc_img_release(ss->second.snapShot); | |
775 | + VPCUtil::vpc_img_release(ss->second.snapShotLittle); | |
776 | + } | |
777 | + total_village_snapshot_info.erase(ss); | |
778 | + } | |
779 | + } | |
780 | +} | |
781 | + | |
782 | + | |
578 | 783 | map<OBJ_KEY, OBJ_VALUE> snapshot_reprocessing::get_total_face_snapshot_info(){ |
579 | 784 | return total_face_snapshot_info; |
580 | 785 | } |
581 | 786 | \ No newline at end of file | ... | ... |
src/reprocessing_module/snapshot_reprocessing.h
... | ... | @@ -75,7 +75,11 @@ public: |
75 | 75 | int update_face_bestsnapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &ol_det_result, vector<vector<int>>& delete_object_id); |
76 | 76 | map<OBJ_KEY, OBJ_VALUE> get_total_face_snapshot_info(); |
77 | 77 | |
78 | + void update_village_bestsnapshot(vector<DeviceMemory*> vec_devMem, vector<onelevel_det_result> &ol_det_result, vector<vector<int>>& delete_object_id); | |
79 | + map<OBJ_KEY, OBJ_VALUE> get_total_village_snapshot_info(); | |
80 | + | |
78 | 81 | void release_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease); |
82 | + void release_village_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease); | |
79 | 83 | |
80 | 84 | private: |
81 | 85 | bool best_snapshot_judge_algor(const OBJ_KEY& obj_key, const OBJ_VALUE& obj_value, int left, int top, int width, int height, int image_width, int image_height); |
... | ... | @@ -84,6 +88,7 @@ private: |
84 | 88 | private: |
85 | 89 | map<OBJ_KEY, OBJ_VALUE> total_snapshot_info; |
86 | 90 | map<OBJ_KEY, OBJ_VALUE> total_face_snapshot_info; |
91 | + map<OBJ_KEY, OBJ_VALUE> total_village_snapshot_info; | |
87 | 92 | |
88 | 93 | map<string, set<int>> algor_index_table; |
89 | 94 | task_param_manager *m_task_param_manager; | ... | ... |