diff --git a/.gitignore b/.gitignore index e994d4d..6a0040d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bin/logs/* bin/res/* bin/vpt_proj bin/libvpt_ascend.so +data/* diff --git a/src/ai_platform/MultiSourceProcess.cpp b/src/ai_platform/MultiSourceProcess.cpp index 6b93648..1e079b1 100755 --- a/src/ai_platform/MultiSourceProcess.cpp +++ b/src/ai_platform/MultiSourceProcess.cpp @@ -736,6 +736,8 @@ int CMultiSourceProcess::algorthim_vpt(vector vec_gpuMem){ /* for pedestrian safety det. 行人安全分析算法模块 */ // algorthim_pedestrian_safety(vpt_interest_task_id, vpt_interest_imgs,vptResult); + // 农村违法分析的快照缓存 + m_snapshot_reprocessing->update_village_bestsnapshot(vec_vptMem, vptResult, deleteObjectID); // 逆行 algorthim_retrograde(vpt_interest_task_id, vec_vptMem, vptResult); retrograde_snapshot(vpt_interest_task_id, deleteObjectID); @@ -1222,12 +1224,22 @@ void CMultiSourceProcess::manned_snapshot(vector& vpt_interest_task_id, OBJ_KEY obj_key = {*task_iter, j}; auto task_param_ptr = m_task_param_manager->get_task_algor_param(obj_key.video_id); bool tricycle_manned_alarm = false, truck_manned_alarm = false, motor_overman_alarm = false, motor_nohelmet_alarm = false; + std::string video_folder = "", result_folder = "", result_folder_little = ""; //要求各事件使用同一个视频保存地址,否则会被最后一个事件的地址覆盖 + auto task_other_params = m_task_param_manager->get_task_other_param(task_id); + std::vector algorithm_types; + bool save_single_algor_pic = false; // 是否保存单算法的报警图片 if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::TRICYCLE_MANNED) != task_param_ptr->nonmotor_vehicle_algors.end()) { + const auto &algor_other_params = task_other_params->find(algorithm_type_t::TRICYCLE_MANNED); + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; + 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}); if (result.get()) { tricycle_manned_alarm = true; - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRICYCLE_MANNED); + algorithm_types.push_back((int)algorithm_type_t::TRICYCLE_MANNED); + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; + result_folder_little = basic_param->result_folder_little; + vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; @@ -1237,15 +1249,28 @@ void CMultiSourceProcess::manned_snapshot(vector& vpt_interest_task_id, roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; - save_snapshot_process(obj_key, algorithm_type_t::TRICYCLE_MANNED, src_img, roi_img, 0, json_str); + if (save_single_algor_pic) { + auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRICYCLE_MANNED); + save_snapshot_process(obj_key, algorithm_type_t::TRICYCLE_MANNED, src_img, roi_img, 0, json_str); + } else { + VPCUtil::vpc_img_release(src_img); + VPCUtil::vpc_img_release(roi_img); + } + } } if (task_param_ptr->vehicle_algors.find(algorithm_type_t::TRUCK_MANNED) != task_param_ptr->vehicle_algors.end()) { + const auto &algor_other_params = task_other_params->find(algorithm_type_t::TRUCK_MANNED); + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; + 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}); if (result.get()) { truck_manned_alarm = true; - auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRUCK_MANNED); + algorithm_types.push_back((int)algorithm_type_t::TRUCK_MANNED); + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; + result_folder_little = basic_param->result_folder_little; + vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; @@ -1255,15 +1280,28 @@ void CMultiSourceProcess::manned_snapshot(vector& vpt_interest_task_id, roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; - save_snapshot_process(obj_key, algorithm_type_t::TRUCK_MANNED, src_img, roi_img, 0, json_str); + if (save_single_algor_pic) { + auto json_str = helpers::gen_json::gen_manned_json(obj_key.video_id, obj_key.obj_id, result->box, algorithm_type_t::TRUCK_MANNED); + save_snapshot_process(obj_key, algorithm_type_t::TRUCK_MANNED, src_img, roi_img, 0, json_str); + } else { + VPCUtil::vpc_img_release(src_img); + VPCUtil::vpc_img_release(roi_img); + } + } } if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET) != task_param_ptr->nonmotor_vehicle_algors.end()) { + const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET); + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; + 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}); if (result.get()) { motor_nohelmet_alarm = true; - 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); + algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET); + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; + result_folder_little = basic_param->result_folder_little; + vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; @@ -1273,15 +1311,28 @@ void CMultiSourceProcess::manned_snapshot(vector& vpt_interest_task_id, roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; - save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, src_img, roi_img, 0, json_str); + if (save_single_algor_pic) { + 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); + save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, src_img, roi_img, 0, json_str); + } else { + VPCUtil::vpc_img_release(src_img); + VPCUtil::vpc_img_release(roi_img); + } + } } if (task_param_ptr->nonmotor_vehicle_algors.find(algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN) != task_param_ptr->nonmotor_vehicle_algors.end()) { + const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN); + const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; + 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}); if (result.get()) { motor_overman_alarm = true; - 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); + algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN); + video_folder = basic_param->video_folder; result_folder = basic_param->result_folder; + result_folder_little = basic_param->result_folder_little; + vpc_img_info src_img; src_img.pic_desc = result->origin_img_desc; src_img.task_id = obj_key.video_id; @@ -1291,24 +1342,98 @@ void CMultiSourceProcess::manned_snapshot(vector& vpt_interest_task_id, roi_img.task_id = obj_key.video_id; roi_img.object_id = obj_key.obj_id; - save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, src_img, roi_img, 0, json_str); + if (save_single_algor_pic) { + 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); + save_snapshot_process(obj_key, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, src_img, roi_img, 0, json_str); + } else { + VPCUtil::vpc_img_release(src_img); + VPCUtil::vpc_img_release(roi_img); + } + } } + + map _total_snapshot_info = m_snapshot_reprocessing->get_total_village_snapshot_info(); + if(_total_snapshot_info.size() <= 0){ + return; + } + + LOG_DEBUG("_total_snapshot_info size: {}", _total_snapshot_info.size()); + auto it = _total_snapshot_info.find(obj_key); + if (it == _total_snapshot_info.end()) { + return; + } + + if (tricycle_manned_alarm || truck_manned_alarm || motor_overman_alarm || motor_nohelmet_alarm) { + const OBJ_VALUE obj_value = it->second; + // 原图 + LOG_DEBUG("原图"); + std::string cur_timestamp_ms = std::to_string(helpers::timer::get_cur_time_ms()); + std::string fpath_origin = result_folder + helpers::os::sep + obj_key.video_id + "_" + + std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".jpg"; + + ImgSaveInfo origin_save_info; + origin_save_info.file_path = fpath_origin; + origin_save_info.img_info = obj_value.snapShot; + origin_save_info.obj_rect = obj_value.obj_pos; + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(origin_save_info); + + + LOG_DEBUG("抠图"); + // 抠图 + string object_file_name = result_folder_little + helpers::os::sep + obj_key.video_id + "_" + + std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".jpg"; + ImgSaveInfo obj_save_info; + obj_save_info.file_path = object_file_name; + obj_save_info.img_info = obj_value.snapShotLittle; + m_save_snapshot_reprocessing->reprocessing_process_wo_locus_async(obj_save_info); + + + // 视频 + string video_file_name = video_folder + helpers::os::sep + obj_key.video_id + "_" + + std::to_string(obj_key.obj_id) + "_" + cur_timestamp_ms + ".mp4"; + + + string json_str = ""; +#ifdef POST_USE_RABBITMQ + std::vector algo_results; + video_object_snapshot new_obj_ss_info; + new_obj_ss_info.analysisRes = nullptr; + new_obj_ss_info.object_id = obj_key.obj_id; + new_obj_ss_info.obj_info.set_data(obj_value.index.index, obj_value.confidence, obj_value.obj_pos.left_, + obj_value.obj_pos.top_, obj_value.obj_pos.left_ + obj_value.obj_pos.width_, + obj_value.obj_pos.top_ + obj_value.obj_pos.height_); + strcpy(new_obj_ss_info.task_id, obj_key.video_id.c_str()); + strcpy(new_obj_ss_info.video_image_path, fpath_origin.c_str()); + strcpy(new_obj_ss_info.snapshot_image_path, object_file_name.c_str()); + algo_results.push_back(new_obj_ss_info); + json_str = helpers::gen_json::gen_village_json(task_id, obj_key.obj_id, algorithm_types, algo_results, video_file_name); +#endif + DeviceMemory* mem = vec_vptMem[i]; // string task_id = mem->getId(); - // cout << "mem->getId():" << mem->getId() << " cur_task_id:" << task_id << endl; RecoderInfo recoderInfo; recoderInfo.task_id = task_id; recoderInfo.object_id = std::to_string(j); - recoderInfo.recoderPath = "./res/recode"; + recoderInfo.recoderPath = video_file_name; recoderInfo.frame_nb = mem->getFrameNb(); + recoderInfo.mq_info = json_str; m_recoderinfo_queue_mtx.lock(); m_recoderinfo_queue.push_back(recoderInfo); m_recoderinfo_queue_mtx.unlock(); + + LOG_DEBUG("仅删除记录,显存会在保存线程中删除"); + // 仅删除记录,显存会在保存线程中删除 + m_snapshot_reprocessing->release_village_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, false); + } + else { + // 删除记录,同时释放显存 + m_snapshot_reprocessing->release_village_finished_locus_snapshot(obj_key.video_id, obj_key.obj_id, true); + return; } @@ -1542,7 +1667,7 @@ void CMultiSourceProcess::face_locus_finished(const OBJ_KEY obj_key) { #ifdef POST_USE_RABBITMQ json_str = helpers::gen_json::gen_face_detection_json( obj_key.video_id, obj_key.obj_id, fpath_snapShotLittle, fpath_src, - obj_value.position, obj_value.confidence, obj_value.landmark_point, 25); + obj_value.position, obj_value.confidence, obj_value.landmark_point, 25); #endif ImgSaveInfo roi_save_info; diff --git a/src/ai_platform/header.h b/src/ai_platform/header.h index 7630b54..19a3a58 100755 --- a/src/ai_platform/header.h +++ b/src/ai_platform/header.h @@ -441,8 +441,9 @@ typedef struct algor_basic_config_param_t { sy_rect algor_valid_rect; char *result_folder_little; //目标快照抠图保存地址 char *result_folder; //目标快照大图保存地址 + char *video_folder; //目标视频保存地址 explicit algor_basic_config_param_t() - : result_folder_little(nullptr), result_folder(nullptr) {} + : result_folder_little(nullptr), result_folder(nullptr), video_folder(nullptr) {} } algor_basic_config_param_t; #endif // #ifndef __ALGOR_CONFIG_PARAM__BASIC__ diff --git a/src/ai_platform/task_param_manager.cpp b/src/ai_platform/task_param_manager.cpp index f2c40b6..d37294e 100755 --- a/src/ai_platform/task_param_manager.cpp +++ b/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) { } else dst_basic_param->result_folder = nullptr; + if (src_basic_param->video_folder) { + dst_basic_param->video_folder = new char[strlen(src_basic_param->video_folder) + 1]; + strcpy(dst_basic_param->video_folder, src_basic_param->video_folder); + CreateResultFolder(dst_basic_param->video_folder, ""); + } else + dst_basic_param->video_folder = nullptr; + dst_basic_param->algor_valid_rect.left_ = src_basic_param->algor_valid_rect.left_; dst_basic_param->algor_valid_rect.top_ = src_basic_param->algor_valid_rect.top_; 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) { delete[] cur_param->result_folder; cur_param->result_folder = nullptr; } + if (cur_param->video_folder) { + delete[] cur_param->video_folder; + cur_param->video_folder = nullptr; + } if (cur_param) { delete ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->basic_param; ((algor_init_config_param_t *)m_task_params[task_id][iter.first])->basic_param = nullptr; diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index d85afa5..f7f2292 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -81,6 +81,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty basic_params->algor_valid_rect.left_ = 0; basic_params->algor_valid_rect.width_ = 1920; basic_params->algor_valid_rect.height_ = 1080; + basic_params->video_folder = "res/video_recode"; basic_params->result_folder = "res/motor_nohelmet"; basic_params->result_folder_little = "res/motor_nohelmet_little"; } @@ -106,6 +107,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty basic_params->algor_valid_rect.left_ = 0; basic_params->algor_valid_rect.width_ = 1920; basic_params->algor_valid_rect.height_ = 1080; + basic_params->video_folder = "res/video_recode"; basic_params->result_folder = "res/motor_overman"; basic_params->result_folder_little = "res/motor_overman_little"; } @@ -131,6 +133,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty basic_params->algor_valid_rect.left_ = 0; basic_params->algor_valid_rect.width_ = 1920; basic_params->algor_valid_rect.height_ = 1080; + basic_params->video_folder = "res/video_recode"; basic_params->result_folder = "res/tricycle_manned"; basic_params->result_folder_little = "res/tricycle_manned_little"; } @@ -156,6 +159,7 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty basic_params->algor_valid_rect.left_ = 0; basic_params->algor_valid_rect.width_ = 1920; basic_params->algor_valid_rect.height_ = 1080; + basic_params->video_folder = "res/video_recode"; basic_params->result_folder = "res/truck_manned"; basic_params->result_folder_little = "res/truck_manned_little"; } diff --git a/src/helpers/gen_json.hpp b/src/helpers/gen_json.hpp index 0ed7a04..690cf43 100755 --- a/src/helpers/gen_json.hpp +++ b/src/helpers/gen_json.hpp @@ -236,16 +236,6 @@ namespace helpers return gen_generic_json(taskId, object_id, box, algor_type, image_path); } - - static std::string gen_manned_json(const std::string& taskId, int object_id, - const box_t &box, - const algorithm_type_t &algor_type, - const std::string &image_path = "") - { - return gen_generic_json(taskId, object_id, box, algor_type, image_path); - } - - static std::string gen_takeaway_member_cls_json(const std::string& taskId, int object_id, const box_t &box, const int &category, const std::string &image_path = "") @@ -340,6 +330,60 @@ namespace helpers return Json::writeString(get_builder(), root); }; + + static std::string gen_village_json(const std::string& taskId, long object_id, std::vector algorithm_types, std::vector const &algo_results, const std::string &video_path) { + Json::Value root; + root["task_id"] = taskId; + root["object_id"] = int(object_id); + root["timestamp_ms"] = std::to_string(timer::get_timestamp()); + root["video_recode_path"] = video_path; + Json::Value algorNodes; + for (auto &algorithm_type: algorithm_types) { + Json::Value algorNode; + // algorNode["algor_type"] = algorithm_type; + // algorNodes.append(algorNode); + auto algor_type = std::to_string(algorithm_type); + algorNodes.append(algor_type); + } + root["algor_types"] = algorNodes; + { + Json::Value picNode; + Json::Value dataNode; + for (int i = 0; i < algo_results.size(); i++) { + int num = i + 1; + dataNode["picnum"] = num; + dataNode["video_image_path"] = algo_results[i].video_image_path; + dataNode["snapshot_image_path"] = algo_results[i].snapshot_image_path; + Json::Value boxNode; + { + Json::Value boxNodeItem; + boxNodeItem["top"] = algo_results[i].obj_info.res_top; + boxNodeItem["left"] = algo_results[i].obj_info.res_left; + boxNodeItem["right"] = algo_results[i].obj_info.res_right; + boxNodeItem["bottom"] = algo_results[i].obj_info.res_bottom; + boxNodeItem["score"] = algo_results[i].obj_info.res_prob; + boxNodeItem["index"] = algo_results[i].obj_info.res_index; //221212byzsh + boxNode.append(boxNodeItem); + dataNode["box"] = boxNode; + } + picNode.append(dataNode); + } + + root["data"] = picNode; + } + return Json::writeString(get_builder(), root); + } + + + static std::string gen_manned_json(const std::string& taskId, int object_id, + const box_t &box, + const algorithm_type_t &algor_type, + const std::string &image_path = "") + { + return gen_generic_json(taskId, object_id, box, algor_type, image_path); + } + + } // namespace gen_json } // namespace helpers diff --git a/src/reprocessing_module/snapshot_reprocessing.cpp b/src/reprocessing_module/snapshot_reprocessing.cpp index 4d3c883..206732e 100755 --- a/src/reprocessing_module/snapshot_reprocessing.cpp +++ b/src/reprocessing_module/snapshot_reprocessing.cpp @@ -330,6 +330,174 @@ void snapshot_reprocessing::update_bestsnapshot(vector vec_devMem } } + +/* 获取农村违法分析要求的目标快照图--轨迹起始 最佳 轨迹结束 */ +void snapshot_reprocessing::update_village_bestsnapshot(vector vec_devMem, vector &ol_det_result, vector>& delete_object_id){ + map && algor_config_param = m_task_param_manager->get_task_algor_params(); + map> && algor_param = m_task_param_manager->get_task_other_params(); + + VPCUtil* pVpcUtil = VPCUtil::getInstance(); + + for (size_t i = 0; i < vec_devMem.size(); i++){ + + onelevel_det_result det_result = ol_det_result[i]; + if (0 == det_result.obj_count){ + continue; + } + + DeviceMemory* memPtr = vec_devMem[i]; + + string task_id = memPtr->getId(); + int frame_height = memPtr->getHeight(); + int frame_width = memPtr->getWidth(); + + vector vec_obj_info; + for (int c = 0; c < det_result.obj_count; c++){ + + det_objinfo obj_info = det_result.obj[c]; + OBJ_KEY new_obj = { task_id, obj_info.id }; + + int index = 0; + + /* 投票确定目标index */ + if (total_village_snapshot_info.find(new_obj) == total_village_snapshot_info.end()){ + index = obj_info.index; + } else { + index = total_village_snapshot_info[new_obj].index.index; + } + + int cur_real_width = (obj_info.right - obj_info.left); + int cur_real_height = (obj_info.bottom - obj_info.top); + int cur_real_index = obj_info.index; + + int expansion_width = cur_real_width * EXPANSION_PROPORTION; + int expansion_height = cur_real_height * EXPANSION_PROPORTION; + // DEBUG----------------------------------------------------------------- + // 0-行人 1-自行车 2-摩托车 3-三轮车 4-小型车 5-大车 6-卡车 7-拖拉机 8-中巴 + if(index ==0 || index ==1 || index ==2 || index ==3) { //行人和非机动车外扩指定像素即可 + expansion_width = 10; + expansion_height = 10; + } + + /* 若该目标第一次出现 */ + if (total_village_snapshot_info.find(new_obj) == total_village_snapshot_info.end()) + { + /* manager insert new object. */ + /* 判断目标合法 */ + // algorithm_type_t algor_type; + // if (index ==0) algor_type = algorithm_type_t::HUMAN_SNAPSHOT; + // if (index ==1 || index ==2 || index ==3) algor_type = algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT; + // if (index ==4 || index ==5 || index ==6 || index ==7 || index ==8) algor_type = algorithm_type_t::VEHICLE_SNAPSHOT; + // if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algor_type))) + // continue; + // task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type]; + // if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left, obj_info.top, obj_info.right, obj_info.bottom)){ + // continue; + // } + + if(!snapshot_legal_minarea(index, cur_real_width, cur_real_height)){ + continue; + } + + /* 存入当前抠图目标参数 flags用于判断目标从画面什么位置出现 方便之后排除出画面边缘的快照图 */ + total_village_snapshot_info[new_obj].index.count++; + total_village_snapshot_info[new_obj].index.index = cur_real_index; + total_village_snapshot_info[new_obj].confidence = obj_info.confidence; + total_village_snapshot_info[new_obj].flags[0] = obj_info.left < minDistance[0] + SCALE_OUT ? 0 : 1; //left + total_village_snapshot_info[new_obj].flags[1] = obj_info.top < minDistance[1] + SCALE_OUT ? 0 : 1; //top + total_village_snapshot_info[new_obj].flags[2] = obj_info.right > frame_width - minDistance[2] - SCALE_OUT ? 0 : 1; //right + total_village_snapshot_info[new_obj].flags[3] = obj_info.bottom > frame_height - minDistance[3] - SCALE_OUT ? 0 : 1; //bottom + + int cur_left = max(obj_info.left - 10, 0); + int cur_top = max(obj_info.top - 10, 0); + int cur_right = min(obj_info.right + 10, frame_width - 1); + int cur_bottom = min(obj_info.bottom + 10, frame_height - 1); + total_village_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 + total_village_snapshot_info[new_obj].last_area = total_village_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); + + video_object_info info; + info.left = max(obj_info.left - expansion_width, 0); + info.top = max(obj_info.top - expansion_height, 0); + info.right = min(obj_info.right + expansion_width, frame_width - 1); + info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1); + strcpy(info.task_id, task_id.c_str()); + info.object_id = obj_info.id; + info.confidence = obj_info.confidence; + info.index = index; + + vec_obj_info.push_back(info); + } else { + total_village_snapshot_info[new_obj].last_area = (obj_info.right - obj_info.left) * (obj_info.bottom - obj_info.top); + + // algorithm_type_t algor_type; + // if (index ==0) algor_type = algorithm_type_t::HUMAN_SNAPSHOT; + // if (index ==1 || index ==2 || index ==3) algor_type = algorithm_type_t::NONMOTOR_VEHICLE_SNAPSHOT; + // if (index ==4 || index ==5 || index ==6 || index ==7 || index ==8) algor_type = algorithm_type_t::VEHICLE_SNAPSHOT; + // if (!(algor_config_param.count(task_id) && algor_param.count(task_id) && algor_param[task_id].count(algor_type))) + // continue; + // task_param_manager::algo_param_type_t_* cur_task_params = algor_param[task_id][algor_type]; + // if (!snapshot_legal_inarea(cur_task_params->basic_param->algor_valid_rect,obj_info.left, obj_info.top, obj_info.right, obj_info.bottom)) + // continue; + //--------------------------------------------------------------- + if (!best_snapshot_judge_algor(new_obj, total_village_snapshot_info[new_obj], obj_info.left, obj_info.top, + cur_real_width, cur_real_height, frame_width, frame_height)) + { + continue; + } + /* 若更优于之前的快照 做快照的更新 */ + if (total_village_snapshot_info[new_obj].index.count == 0) + { + total_village_snapshot_info[new_obj].index.count++; + total_village_snapshot_info[new_obj].index.index = cur_real_index; + } + else + { + if (total_village_snapshot_info[new_obj].index.index == cur_real_index) + total_village_snapshot_info[new_obj].index.count++; + else + total_village_snapshot_info[new_obj].index.count--; + } + + int cur_left = max(obj_info.left - 10, 0); + int cur_top = max(obj_info.top - 10, 0); + int cur_right = min(obj_info.right + 10, frame_width - 1); + int cur_bottom = min(obj_info.bottom + 10, frame_height - 1); + total_village_snapshot_info[new_obj].obj_pos = { cur_left, cur_top, cur_right - cur_left, cur_bottom - cur_top }; //debug by zsh 推出的坐标外扩10像素 + total_village_snapshot_info[new_obj].last_area = total_village_snapshot_info[new_obj].max_area = (cur_right - cur_left) * (cur_bottom - cur_top); + + video_object_info info; + info.left = max(obj_info.left - expansion_width, 0); + info.top = max(obj_info.top - expansion_height, 0); + info.right = min(obj_info.right + expansion_width, frame_width - 1); + info.bottom = min(obj_info.bottom + expansion_height, frame_height - 1); + strcpy(info.task_id, task_id.c_str()); + info.object_id = obj_info.id; + info.confidence = obj_info.confidence; + info.index = index; + + vec_obj_info.push_back(info); + } + } + + vector imgList = pVpcUtil->crop_batch(memPtr, vec_obj_info); + vec_obj_info.clear(); + + for (size_t i = 0; i < imgList.size(); i++) { + vpc_img_info obj_info = imgList[i]; + OBJ_KEY objKey = { obj_info.task_id, obj_info.object_id }; + VPCUtil::vpc_img_release(total_village_snapshot_info[objKey].snapShot); + total_village_snapshot_info[objKey].snapShot = VPCUtil::vpc_devMem2vpcImg(memPtr); + VPCUtil::vpc_img_release(total_village_snapshot_info[objKey].snapShotLittle); + total_village_snapshot_info[objKey].snapShotLittle = obj_info; + } + imgList.clear(); + } +} + +map snapshot_reprocessing::get_total_village_snapshot_info(){ + return total_village_snapshot_info; +} + 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) { 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, } } + +void snapshot_reprocessing::release_village_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease) +{ + LOG_DEBUG("[info] task_id {} delete obj_id {}", taskid, obj_id); //221026 + if (obj_id != -1) + { + OBJ_KEY cur_key = { taskid , obj_id }; + auto it = total_village_snapshot_info.find(cur_key); + if (it == total_village_snapshot_info.end()){ + return; + } + + if (bRelease){ + OBJ_VALUE ss = total_village_snapshot_info[cur_key]; + + VPCUtil::vpc_img_release(ss.snapShot); + VPCUtil::vpc_img_release(ss.snapShotLittle); + } + + total_village_snapshot_info.erase(cur_key); + return; + } + + for(auto ss = total_village_snapshot_info.begin(); ss != total_village_snapshot_info.end(); ss++) + { + if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0) + { + if (bRelease){ + VPCUtil::vpc_img_release(ss->second.snapShot); + VPCUtil::vpc_img_release(ss->second.snapShotLittle); + } + total_village_snapshot_info.erase(ss); + } + } +} + + map snapshot_reprocessing::get_total_face_snapshot_info(){ return total_face_snapshot_info; } \ No newline at end of file diff --git a/src/reprocessing_module/snapshot_reprocessing.h b/src/reprocessing_module/snapshot_reprocessing.h index b36d325..a7f04f9 100755 --- a/src/reprocessing_module/snapshot_reprocessing.h +++ b/src/reprocessing_module/snapshot_reprocessing.h @@ -75,7 +75,11 @@ public: int update_face_bestsnapshot(vector vec_devMem, vector &ol_det_result, vector>& delete_object_id); map get_total_face_snapshot_info(); + void update_village_bestsnapshot(vector vec_devMem, vector &ol_det_result, vector>& delete_object_id); + map get_total_village_snapshot_info(); + void release_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease); + void release_village_finished_locus_snapshot(const string taskid, const int obj_id, bool bRelease); private: 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: private: map total_snapshot_info; map total_face_snapshot_info; + map total_village_snapshot_info; map> algor_index_table; task_param_manager *m_task_param_manager;