diff --git a/bin/libmotor_rainshed_vdec.so b/bin/libmotor_rainshed_vdec.so new file mode 100755 index 0000000..3cabea3 --- /dev/null +++ b/bin/libmotor_rainshed_vdec.so diff --git a/bin/models/village/motor_rainshed_310p.om b/bin/models/village/motor_rainshed_310p.om new file mode 100644 index 0000000..0037882 --- /dev/null +++ b/bin/models/village/motor_rainshed_310p.om diff --git a/src/Makefile b/src/Makefile index f1ed569..d8e3733 100755 --- a/src/Makefile +++ b/src/Makefile @@ -38,7 +38,7 @@ lib=-lacl_dvpp -lascendcl -lacl_dvpp_mpi -lruntime -lascendalog -lc_sec -lmsprof -lplatform -lgraph_base -lqos_manager LIBS= -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ - -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lphone_motor_det -lhcp_vdec -lhs_motor_process\ + -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lphone_motor_det -lhcp_vdec -lmotor_rainshed_vdec -lhs_motor_process\ -L $(OPENCV_ROOT)/lib -lopencv_world\ -L $(JSON_ROOT)/lib -ljsoncpp \ -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ diff --git a/src/ai_engine_module/motocycle_refit_phone_process.cpp b/src/ai_engine_module/motocycle_refit_phone_process.cpp index 8806d64..481a803 100644 --- a/src/ai_engine_module/motocycle_refit_phone_process.cpp +++ b/src/ai_engine_module/motocycle_refit_phone_process.cpp @@ -12,7 +12,7 @@ namespace ai_engine_module { static std::set algor_type_list_ = { algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE, - algorithm_type_t::NONMOTOR_VEHICLE_REFIT, + // algorithm_type_t::NONMOTOR_VEHICLE_REFIT, }; inline bool is_valid_label(const label_t &label) { @@ -334,8 +334,8 @@ namespace ai_engine_module auto& e = id_to_mn_[obj_key]; ++e.m_frame; - if (algor_type == algorithm_type_t::NONMOTOR_VEHICLE_REFIT && refit_pred.res_index != 1) - continue; + // if (algor_type == algorithm_type_t::NONMOTOR_VEHICLE_REFIT && refit_pred.res_index != 1) + // continue; // 数量小于设定阈值不报警 if (algor_type == algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) { diff --git a/src/ai_engine_module/motocycle_refit_process.cpp b/src/ai_engine_module/motocycle_refit_process.cpp index bd08931..440b706 100644 --- a/src/ai_engine_module/motocycle_refit_process.cpp +++ b/src/ai_engine_module/motocycle_refit_process.cpp @@ -71,7 +71,8 @@ namespace ai_engine_module MotorRefitProcess::~MotorRefitProcess() { if (tools_) { - hcp_release(&tools_); + // hcp_release(&tools_); + mrc_release(&tools_); tools_ = nullptr; } if (m_algorthim_ctx) { @@ -83,10 +84,13 @@ namespace ai_engine_module { init_ = false; - string model_path = models_dir + "/models/village/hcp211008_310p.om" ; - LOG_INFO("hcp 版本:{} 模型路径:{}", hcp_get_version(), model_path); + // string model_path = models_dir + "/models/village/hcp211008_310p.om" ; + // LOG_INFO("hcp 版本:{} 模型路径:{}", hcp_get_version(), model_path); + string model_path = models_dir + "/models/village/motor_rainshed_310p.om" ; + LOG_INFO("mRainCls 版本:{} 模型路径:{}", mrc_get_version(), model_path); - hcp_param param; + // hcp_param param; + mrc_param param; char modelNames[100]; strcpy(modelNames, model_path.c_str()); param.modelNames = modelNames; @@ -97,7 +101,8 @@ namespace ai_engine_module ACL_CALL(aclrtCreateContext(&m_algorthim_ctx, m_devId), ACL_SUCCESS, -1); int status; - if (!(init_ = (0 == (status = hcp_init(&tools_, param))))) + // if (!(init_ = (0 == (status = hcp_init(&tools_, param))))) + if (!(init_ = (0 == (status = mrc_init(&tools_, param))))) LOG_ERROR("Init MotorRefitProcessSdk failed error code is {}", status); else if (!task_param_manager_) @@ -269,14 +274,16 @@ namespace ai_engine_module } /* 2. collection result. */ int n_input_image = flattened_imgs.size(); - hcp_analysis_result model_results[n_input_image]; + // hcp_analysis_result model_results[n_input_image]; + mrc_result model_results[n_input_image]; { int steps = (n_input_image + MAX_BATCH - 1) / MAX_BATCH; for (int step = 0; step < steps; ++step) { int offset = step * MAX_BATCH; int batch_size = (step == steps - 1) ? n_input_image - offset : MAX_BATCH; - hcp_batch(tools_, flattened_imgs.data() + offset, batch_size, model_results + offset); + // hcp_batch(tools_, flattened_imgs.data() + offset, batch_size, model_results + offset); + mrc_batch(tools_, flattened_imgs.data() + offset, batch_size, model_results + offset); } } @@ -295,8 +302,11 @@ namespace ai_engine_module const auto& src_img = vec_det_input_images[flattened_idx_to_batch_idx[n]]; auto &model_result = model_results[n]; - auto &pred = model_result.res_objs[12]; // 211008模型索引12对应是否有雨棚 - const label_t label = static_cast(pred.res_index); + // auto &pred = model_result.res_objs[12]; // 211008模型索引12对应是否有雨棚 + // const label_t label = static_cast(pred.res_index); + auto &pred = model_result; + const label_t label = static_cast(pred.index); + for (auto algor_type_iter = algors.begin();algor_type_iter != algors.end(); ++algor_type_iter) { const algorithm_type_t algor_type = *algor_type_iter; diff --git a/src/ai_engine_module/motocycle_refit_process.h b/src/ai_engine_module/motocycle_refit_process.h index f519892..b3c9d70 100644 --- a/src/ai_engine_module/motocycle_refit_process.h +++ b/src/ai_engine_module/motocycle_refit_process.h @@ -7,7 +7,8 @@ #include "../ai_platform/task_param_manager.h" #include "../ai_platform/macro_definition.h" #include "ai_engine_header.h" -#include "human_car_parsing.h" +// #include "human_car_parsing.h" +#include "motor_rainshed_cls.h" #include "acl/acl.h" #include "acl/ops/acl_dvpp.h" @@ -26,8 +27,8 @@ namespace ai_engine_module enum class label_t { PLACEHOLDER = -1, - norefit = 0, //无雨棚 - refit = 1, //有雨棚 + norefit = 1, //无雨棚 + refit = 0, //有雨棚 }; typedef struct input_data_wrap_t diff --git a/src/ai_engine_module/motor_rainshed_cls.h b/src/ai_engine_module/motor_rainshed_cls.h new file mode 100644 index 0000000..c4ca8e3 --- /dev/null +++ b/src/ai_engine_module/motor_rainshed_cls.h @@ -0,0 +1,120 @@ +/************************************************************************* +* Version: motor_rainshed_cls_v0.0.0.20230921 +* CopyRight : 中国科学院自动化所模式识别实验室图像视频组 +* UpdateDate:20230921 +* Content : 二轮车是否加装雨棚 +*************************************************************************/ +#ifndef MOTORRAINCLS_H_ +#define MOTORRAINCLS_H_ + +#if _MSC_VER +#ifdef MOTORRAINCLS_EXPORTS +#define MOTORRAINCLS_API __declspec(dllexport) +#else +#define MOTORRAINCLS_API __declspec(dllimport) +#endif +#else +#define MOTORRAINCLS_API __attribute__ ((visibility ("default"))) +#endif + +#include "sy_common.h" + + + +#ifndef MAX_BATCH_SIZE +#define MAX_BATCH_SIZE 16 +#endif + + +#ifdef __cplusplus +extern "C" +{ +#endif + + + +//分类结果 +#ifndef MRCRESULT_ +#define MRCRESULT_ +typedef struct mrc_result +{ + float score; + int index; +}mrc_result; +#endif + + +#ifndef __MRCPARAM__ +#define __MRCPARAM__ + typedef struct mrc_param + { + //int mode; //运行模式(DEVICE_GPU / DEVICE_CPU) + //mrc_param() :mode(DEVICE_GPU), gpuid(0) {}; + int devId; //ָ指定显卡id + char* modelNames; + float thresld; //阈值 + }mrc_param; +#endif + + /************************************************************************* + * FUNCTION: mrc_init + * PURPOSE: 载入模型 + * PARAM: + [in] handle - 句柄 + [in] params - 参数 + * RETURN: 成功(0)或者错误代码 + * NOTES: + *************************************************************************/ + MOTORRAINCLS_API int mrc_init(void ** handle, mrc_param param); + + /************************************************************************* + * FUNCTION: mrc_process + * PURPOSE: 二轮车加装雨棚分类 + * PARAM: + [in] handle - 检测句柄 + [in] img_data - 图像数据 + [in] result - 结果 内存在外部申请 + * RETURN: 成功(0) 或 错误代码(< 0) + * NOTES: + *************************************************************************/ + MOTORRAINCLS_API int mrc_process(void *handle, sy_img img_data, mrc_result * result); + + /************************************************************************* + * FUNCTION: mrc_batch + * PURPOSE: 二轮车加装雨棚分类 batch + * PARAM: + [in] handle - 检测句柄 + [in] img_data_array - 图像数据 + [in] batch_size - 图像数目 + [in] result - 结果 内存在外部申请 + * RETURN: 成功(0) 或 错误代码(< 0) + * NOTES: + *************************************************************************/ + MOTORRAINCLS_API int mrc_batch(void *handle, sy_img* img_data_array, int batch_size, mrc_result * result); + + + /************************************************************************* + * FUNCTION: mrc_release + * PURPOSE: 释放 + * PARAM: + [in] handle - handle + * RETURN: NULL + * NOTES: + *************************************************************************/ + MOTORRAINCLS_API void mrc_release(void ** handle); + + + /************************************************************************* + * FUNCTION: mrc_get_version + * PURPOSE: + * PARAM: NULL + * RETURN: 版本号 + * NOTES: + *************************************************************************/ + MOTORRAINCLS_API const char * mrc_get_version(); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/src/ai_platform/MultiSourceProcess.cpp b/src/ai_platform/MultiSourceProcess.cpp index daf008a..e03020b 100755 --- a/src/ai_platform/MultiSourceProcess.cpp +++ b/src/ai_platform/MultiSourceProcess.cpp @@ -189,12 +189,12 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ if (!motor_phoneprocess_.init(vptParam.gpuid, models_dir)) { LOG_FATAL("Init motor_phone failed"); return -1; - } + }*/ //电动车改装(加雨棚) if (!motor_refitprocess_.init(vptParam.gpuid, models_dir)) { LOG_FATAL("Init motor_refit failed"); return -1; - }*/ + } #endif #ifdef WITH_FACE_DET_SS @@ -710,7 +710,7 @@ bool CMultiSourceProcess::finish_task(const string taskID, const bool delete_sna motor_hsprocess_.force_release_result(taskID); motor_refit_phoneprocess_.force_release_result(taskID); // motor_phoneprocess_.force_release_result(taskID); - // motor_refitprocess_.force_release_result(taskID); + motor_refitprocess_.force_release_result(taskID); m_task_param_manager->delete_task_param(taskID); #endif @@ -899,12 +899,12 @@ int CMultiSourceProcess::algorthim_vpt(vector vec_gpuMem){ algorithm_truck_manned(vpt_interest_task_id, vec_vptMem, vptResult); // 二轮车超员/未戴盔 algorithm_motor_hs_process(vpt_interest_task_id, vec_vptMem, vptResult); - // 二轮车驾乘人员使用手机及加雨棚 + // 二轮车驾乘人员使用手机(人骑车辅助版本) algorithm_motor_refit_phone_process(vpt_interest_task_id, vec_vptMem, vptResult); /*// 二轮车驾乘人员使用手机 - algorithm_motor_phone_process(vpt_interest_task_id, vec_vptMem, vptResult); + algorithm_motor_phone_process(vpt_interest_task_id, vec_vptMem, vptResult);*/ // 电动车改装(加雨棚) - algorithm_motor_refit_process(vpt_interest_task_id, vec_vptMem, vptResult);*/ + algorithm_motor_refit_process(vpt_interest_task_id, vec_vptMem, vptResult); village_snapshot(vpt_interest_task_id, vec_vptMem, deleteObjectID); #endif @@ -1357,7 +1357,7 @@ void CMultiSourceProcess::algorithm_motor_hs_process(vector& vpt_interes } } -// 二轮车驾乘人员使用手机及加雨棚 +// 二轮车驾乘人员使用手机(人骑车辅助版) void CMultiSourceProcess::algorithm_motor_refit_phone_process(vector& vpt_interest_task_id, vector vpt_interest_imgs, vector& vptResult) { @@ -1372,8 +1372,9 @@ void CMultiSourceProcess::algorithm_motor_refit_phone_process(vector& vp auto task_id = *_task_id_iter; auto algor_map = m_task_param_manager->get_task_other_param(task_id); - if (algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != algor_map->end() || - algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) != algor_map->end()) { + // if (algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != algor_map->end() || + // algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) != algor_map->end()) { + if (algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != algor_map->end()) { interest_task_id.emplace_back(task_id); interest_imgs.emplace_back(vpt_interest_imgs[_idx]); interest_vpt_result.emplace_back(vptResult[_idx]); @@ -1409,7 +1410,7 @@ void CMultiSourceProcess::algorithm_motor_phone_process(vector& vpt_inte if (!interest_imgs.empty()){ motor_phoneprocess_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); } -} +}*/ // 电动车改装(加雨棚) void CMultiSourceProcess::algorithm_motor_refit_process(vector& vpt_interest_task_id, vector vpt_interest_imgs, @@ -1436,7 +1437,7 @@ void CMultiSourceProcess::algorithm_motor_refit_process(vector& vpt_inte if (!interest_imgs.empty()){ motor_refitprocess_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); } -}*/ +} // for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径) void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, vector vec_vptMem, vector> deleteObjectID) { @@ -1579,8 +1580,8 @@ void CMultiSourceProcess::village_snapshot(vector& vpt_interest_task_id, const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT); const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; - // 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}); - 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}); + 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}); + // 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}); if (result.get()) { village_alarm = true; algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_VEHICLE_REFIT); diff --git a/src/ai_platform/MultiSourceProcess.h b/src/ai_platform/MultiSourceProcess.h index 9439c5c..c8c4640 100755 --- a/src/ai_platform/MultiSourceProcess.h +++ b/src/ai_platform/MultiSourceProcess.h @@ -151,7 +151,7 @@ private: ai_engine_module::motocycle_hs_process::MotorHsProcess motor_hsprocess_; ai_engine_module::motocycle_refit_phone_process::MotorRefitPhoneProcess motor_refit_phoneprocess_; // ai_engine_module::motocycle_phone_process::MotorPhoneProcess motor_phoneprocess_; - // ai_engine_module::motocycle_refit_process::MotorRefitProcess motor_refitprocess_; + ai_engine_module::motocycle_refit_process::MotorRefitProcess motor_refitprocess_; face_det_ai_engine m_face_det_ai_engine; // 人脸检测 diff --git a/src/demo/Makefile b/src/demo/Makefile index 05c1c1d..af7c49b 100755 --- a/src/demo/Makefile +++ b/src/demo/Makefile @@ -33,7 +33,7 @@ lib_dir=-L/usr/local/Ascend/ascend-toolkit/6.3.RC1/runtime/lib64 \ lib=-lacl_dvpp -lascendcl -lacl_dvpp_mpi -lruntime -lascendalog -lc_sec -lmsprofiler -lgert -lmmpa -lascend_hal -lexe_graph -lge_executor -lgraph -lprofapi -lascend_protobuf -lerror_manager -lhybrid_executor -lregister -ldavinci_executor -lge_common -lge_common_base \ -lplatform -lgraph_base -lqos_manager -LIBS= -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lhs_motor_process -lphone_motor_det -lhcp_vdec -latlaslic -lvpt_ascend\ +LIBS= -L $(DEPEND_DIR) -lvpt_det_vdec -lsycheck -lface_det_vdec -lhs_tri_process -lhs_truck_process -lhs_motor_process -lphone_motor_det -lhcp_vdec -lmotor_rainshed_vdec -latlaslic -lvpt_ascend\ -L $(OPENCV_ROOT)/lib -lopencv_world\ -L $(JSON_ROOT)/lib -ljsoncpp \ -L $(FFMPEG_ROOT)/lib -lavformat -lavcodec -lswscale -lavutil -lavfilter -lswresample -lavdevice \ diff --git a/src/demo/demo.cpp b/src/demo/demo.cpp index ae23911..c08fdf5 100755 --- a/src/demo/demo.cpp +++ b/src/demo/demo.cpp @@ -172,8 +172,10 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty case algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE: { auto algor_params = new algor_config_param_manned_incident; { - algor_params->m = 8; - algor_params->n = 10; + // algor_params->m = 10; + // algor_params->n = 8; + algor_params->m = 15; + algor_params->n = 12; algor_params->obj_confidence_threshold = 0.5f; algor_params->obj_min_height = 16; algor_params->obj_min_width = 64; @@ -197,8 +199,10 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty case algorithm_type_t::NONMOTOR_VEHICLE_REFIT: { auto algor_params = new algor_config_param_manned_incident; { - algor_params->m = 10; - algor_params->n = 8; + // algor_params->m = 10; + // algor_params->n = 8; + algor_params->m = 15; + algor_params->n = 12; algor_params->obj_confidence_threshold = 0.5f; algor_params->obj_min_height = 6; algor_params->obj_min_width = 32; diff --git a/src/reprocessing_module/snapshot_reprocessing.cpp b/src/reprocessing_module/snapshot_reprocessing.cpp index e8b2cfe..b8bbdf2 100755 --- a/src/reprocessing_module/snapshot_reprocessing.cpp +++ b/src/reprocessing_module/snapshot_reprocessing.cpp @@ -770,7 +770,7 @@ void snapshot_reprocessing::release_finished_locus_snapshot(const string taskid, return; } - for(auto ss = total_snapshot_info.begin(); ss != total_snapshot_info.end(); ss++) + for(auto ss = total_snapshot_info.begin(); ss != total_snapshot_info.end();) { if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0) { @@ -778,10 +778,11 @@ void snapshot_reprocessing::release_finished_locus_snapshot(const string taskid, VPCUtil::vpc_img_release(ss->second.snapShot); VPCUtil::vpc_img_release(ss->second.snapShotLittle); } - total_snapshot_info.erase(ss); - return; + total_snapshot_info.erase(ss++); } + else ss++; } + return; } @@ -809,7 +810,7 @@ void snapshot_reprocessing::release_village_finished_locus_snapshot(const string return; } - for(auto ss = total_village_snapshot_info.begin(); ss != total_village_snapshot_info.end(); ss++) + for(auto ss = total_village_snapshot_info.begin(); ss != total_village_snapshot_info.end();) { if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0) { @@ -819,10 +820,11 @@ void snapshot_reprocessing::release_village_finished_locus_snapshot(const string VPCUtil::vpc_img_release(ss->second.snapShots[i].snapShotLittle); } } - total_village_snapshot_info.erase(ss); - return; + total_village_snapshot_info.erase(ss++); } + else ss++; } + return; } @@ -851,7 +853,7 @@ void snapshot_reprocessing::release_finished_face_locus_snapshot(const string ta return; } - for(auto ss = total_face_snapshot_info.begin(); ss != total_face_snapshot_info.end(); ss++) + for(auto ss = total_face_snapshot_info.begin(); ss != total_face_snapshot_info.end();) { if (strcmp(ss->first.video_id.c_str(), taskid.c_str()) == 0) { @@ -859,8 +861,9 @@ void snapshot_reprocessing::release_finished_face_locus_snapshot(const string ta VPCUtil::vpc_img_release(ss->second.snapShot); VPCUtil::vpc_img_release(ss->second.snapShotLittle); } - total_face_snapshot_info.erase(ss); - return; + total_face_snapshot_info.erase(ss++); } + else ss++; } + return; } \ No newline at end of file