Commit 06b897ec0781447183034d6468573565a6572878

Authored by Hu Chunming
1 parent c5b54127

代码优化

src/ai_platform/MultiSourceProcess.cpp
@@ -82,135 +82,134 @@ CMultiSourceProcess::~CMultiSourceProcess(){ @@ -82,135 +82,134 @@ CMultiSourceProcess::~CMultiSourceProcess(){
82 } 82 }
83 83
84 int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ 84 int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){
85 - if (CheckTime()) {  
86 - set_default_logger(LogLevel(vptParam.log_level), "multi_source_process", vptParam.log_path, vptParam.log_mem, vptParam.log_mem);  
87 - LOG_INFO("编译时间:{} {}", __DATE__, __TIME__); 85 + if (!CheckTime()) {
  86 + return AUTHOR_ERROR;
  87 + }
88 88
89 - SourceSingleton::getInstance(); 89 + set_default_logger(LogLevel(vptParam.log_level), "multi_source_process", vptParam.log_path, vptParam.log_mem, vptParam.log_mem);
  90 + LOG_INFO("编译时间:{} {}", __DATE__, __TIME__);
90 91
91 - skip_frame_ = 5;  
92 - m_batch_size = 20; 92 + SourceSingleton::getInstance();
93 93
94 - m_devId = vptParam.gpuid; 94 + skip_frame_ = 5;
  95 + m_batch_size = 20;
95 96
96 - string models_dir = vptParam.models_dir; 97 + m_devId = vptParam.gpuid;
97 98
98 - VPTProcess_PARAM vparam;  
99 - vparam.gpuid = m_devId;  
100 - vparam.max_batch = m_batch_size;  
101 - vparam.threshold = 0.4;  
102 - vparam.model_dir = models_dir; 99 + string models_dir = vptParam.models_dir;
103 100
104 - aclrtSetDevice(m_devId); 101 + VPTProcess_PARAM vparam;
  102 + vparam.gpuid = m_devId;
  103 + vparam.max_batch = m_batch_size;
  104 + vparam.threshold = 0.4;
  105 + vparam.model_dir = models_dir;
105 106
106 - int ret = vpt_process.init(vparam);  
107 - if (ret < 0){  
108 - return ret;  
109 - } 107 + aclrtSetDevice(m_devId);
110 108
111 - //三轮车头肩检测  
112 - if (!tricycle_manned_.init(vptParam.gpuid, models_dir)) {  
113 - LOG_FATAL("Init tricycle_hs failed");  
114 - return -1;  
115 - } 109 + int ret = vpt_process.init(vparam);
  110 + if (ret < 0){
  111 + return ret;
  112 + }
116 113
117 - //货车头肩检测  
118 - if (!truck_manned_.init(vptParam.gpuid, models_dir)) {  
119 - LOG_FATAL("Init truck_hs failed");  
120 - return -1;  
121 - } 114 + //三轮车头肩检测
  115 + if (!tricycle_manned_.init(vptParam.gpuid, models_dir)) {
  116 + LOG_FATAL("Init tricycle_hs failed");
  117 + return -1;
  118 + }
122 119
123 - //二轮车头肩检测  
124 - if (!motor_hsprocess_.init(vptParam.gpuid, models_dir)) {  
125 - LOG_FATAL("Init motor_hs failed");  
126 - return -1;  
127 - } 120 + //货车头肩检测
  121 + if (!truck_manned_.init(vptParam.gpuid, models_dir)) {
  122 + LOG_FATAL("Init truck_hs failed");
  123 + return -1;
  124 + }
128 125
129 - #ifdef WITH_FACE_DET_SS  
130 - // 人脸检测初始化  
131 - facedet_ai_engine_param fd_param;  
132 - char model_path_yolov5s[100];  
133 - strcpy(model_path_yolov5s, (models_dir + "/models/face_detect/face_det_yolov5s_310p.om").c_str());  
134 - fd_param.sdk_param.det_modelNames = model_path_yolov5s;  
135 - char model_path_ldmk[100];  
136 - strcpy(model_path_ldmk, (models_dir + "/models/face_detect/face_ldmk_310p.om").c_str());  
137 - fd_param.sdk_param.ldmk_modelNames = model_path_ldmk;  
138 - char model_path_pose[100];  
139 - strcpy(model_path_pose, (models_dir + "/models/face_detect/face_pose_310p.om").c_str());  
140 - fd_param.sdk_param.pose_modelNames = model_path_pose;  
141 - char model_path_score[100];  
142 - strcpy(model_path_score, (models_dir + "/models/face_detect/face_score_310p.om").c_str());  
143 - fd_param.sdk_param.score_modelNames = model_path_score;  
144 - char model_path_fuzzy[100];  
145 - strcpy(model_path_fuzzy, (models_dir + "/models/face_detect/face_fuzzy_310p.om").c_str());  
146 - fd_param.sdk_param.fuzzy_modelNames = model_path_fuzzy;  
147 - char model_path_occlusion[100];  
148 - strcpy(model_path_occlusion, (models_dir + "/models/face_detect/face_occlusion_310p.om").c_str());  
149 - fd_param.sdk_param.occlusion_modelNames = model_path_occlusion;  
150 - fd_param.sdk_param.thresld = 0.6;  
151 - fd_param.sdk_param.devId = m_devId;  
152 - fd_param.sdk_param.auth_license = "sy_tongtu_aiplatform_sdk_2023";  
153 - fd_param.sdk_param.facial_fea_point_config = SY_CONFIG_OPEN; //是否启动关键点检测  
154 - fd_param.sdk_param.pose_config = SY_CONFIG_OPEN; //是否启动姿态角  
155 - fd_param.sdk_param.quality_config = SY_CONFIG_OPEN; //是否启动质量检测  
156 - fd_param.sdk_param.score_config = SY_CONFIG_OPEN; //是否启动人脸置信度 //SY_CONFIG_OPEN SY_CONFIG_CLOSE  
157 - fd_param.sdk_param.max_result_count = 50;  
158 - ret = m_face_det_ai_engine.init_ai_engine(fd_param);  
159 - if (ret < 0 ) {  
160 - LOG_FATAL("Init face detection failed");  
161 - return ret;  
162 - }  
163 - #endif 126 + //二轮车头肩检测
  127 + if (!motor_hsprocess_.init(vptParam.gpuid, models_dir)) {
  128 + LOG_FATAL("Init motor_hs failed");
  129 + return -1;
  130 + }
  131 +
  132 + #ifdef WITH_FACE_DET_SS
  133 + // 人脸检测初始化
  134 + facedet_ai_engine_param fd_param;
  135 + char model_path_yolov5s[100];
  136 + strcpy(model_path_yolov5s, (models_dir + "/models/face_detect/face_det_yolov5s_310p.om").c_str());
  137 + fd_param.sdk_param.det_modelNames = model_path_yolov5s;
  138 + char model_path_ldmk[100];
  139 + strcpy(model_path_ldmk, (models_dir + "/models/face_detect/face_ldmk_310p.om").c_str());
  140 + fd_param.sdk_param.ldmk_modelNames = model_path_ldmk;
  141 + char model_path_pose[100];
  142 + strcpy(model_path_pose, (models_dir + "/models/face_detect/face_pose_310p.om").c_str());
  143 + fd_param.sdk_param.pose_modelNames = model_path_pose;
  144 + char model_path_score[100];
  145 + strcpy(model_path_score, (models_dir + "/models/face_detect/face_score_310p.om").c_str());
  146 + fd_param.sdk_param.score_modelNames = model_path_score;
  147 + char model_path_fuzzy[100];
  148 + strcpy(model_path_fuzzy, (models_dir + "/models/face_detect/face_fuzzy_310p.om").c_str());
  149 + fd_param.sdk_param.fuzzy_modelNames = model_path_fuzzy;
  150 + char model_path_occlusion[100];
  151 + strcpy(model_path_occlusion, (models_dir + "/models/face_detect/face_occlusion_310p.om").c_str());
  152 + fd_param.sdk_param.occlusion_modelNames = model_path_occlusion;
  153 + fd_param.sdk_param.thresld = 0.6;
  154 + fd_param.sdk_param.devId = m_devId;
  155 + fd_param.sdk_param.auth_license = "sy_tongtu_aiplatform_sdk_2023";
  156 + fd_param.sdk_param.facial_fea_point_config = SY_CONFIG_OPEN; //是否启动关键点检测
  157 + fd_param.sdk_param.pose_config = SY_CONFIG_OPEN; //是否启动姿态角
  158 + fd_param.sdk_param.quality_config = SY_CONFIG_OPEN; //是否启动质量检测
  159 + fd_param.sdk_param.score_config = SY_CONFIG_OPEN; //是否启动人脸置信度 //SY_CONFIG_OPEN SY_CONFIG_CLOSE
  160 + fd_param.sdk_param.max_result_count = 50;
  161 + ret = m_face_det_ai_engine.init_ai_engine(fd_param);
  162 + if (ret < 0 ) {
  163 + LOG_FATAL("Init face detection failed");
  164 + return ret;
  165 + }
  166 +#endif
164 167
165 - m_task_param_manager = task_param_manager::getInstance();  
166 - m_snapshot_reprocessing = new snapshot_reprocessing(m_devId);  
167 - m_save_snapshot_reprocessing = new save_snapshot_reprocessing(m_devId); 168 + m_task_param_manager = task_param_manager::getInstance();
  169 + m_snapshot_reprocessing = new snapshot_reprocessing(m_devId);
  170 + m_save_snapshot_reprocessing = new save_snapshot_reprocessing(m_devId);
168 171
169 - #ifdef POST_USE_RABBITMQ  
170 - mq_manager_ = new mq::Manager();  
171 - #endif 172 +#ifdef POST_USE_RABBITMQ
  173 + mq_manager_ = new mq::Manager();
  174 +#endif
172 175
173 - VPCUtil* pVpcUtil = VPCUtil::getInstance();  
174 - pVpcUtil->init(m_devId); 176 + VPCUtil* pVpcUtil = VPCUtil::getInstance();
  177 + pVpcUtil->init(m_devId);
175 178
176 - m_pAlgorthimThread = new thread([](void* arg) {  
177 - CMultiSourceProcess* process = (CMultiSourceProcess*)arg ;  
178 - process->algorthim_process_thread();  
179 - return (void*)0;  
180 - }  
181 - , this); 179 + m_pAlgorthimThread = new thread([](void* arg) {
  180 + CMultiSourceProcess* process = (CMultiSourceProcess*)arg ;
  181 + process->algorthim_process_thread();
  182 + return (void*)0;
  183 + }
  184 + , this);
182 185
183 - m_recode_thread = new thread([](void* arg) {  
184 - CMultiSourceProcess* process = (CMultiSourceProcess*)arg ;  
185 - process->recode_thread();  
186 - return (void*)0;  
187 - }  
188 - , this);  
189 -  
190 -  
191 - m_timing_snapshot_thread = new std::thread(  
192 - [](void* arg)  
193 - {  
194 - CMultiSourceProcess* _this=(CMultiSourceProcess*)arg;  
195 - if(_this != nullptr){  
196 - _this->timing_snapshot_thread();  
197 - }else{  
198 - LOG_ERROR("定时抓拍线程启动失败 !");  
199 - }  
200 - return (void*)0;  
201 - }, this);  
202 -  
203 - if(nullptr == m_timing_snapshot_thread){  
204 - LOG_ERROR("定时抓拍线程启动失败 !"); 186 + m_recode_thread = new thread([](void* arg) {
  187 + CMultiSourceProcess* process = (CMultiSourceProcess*)arg ;
  188 + process->recode_thread();
  189 + return (void*)0;
205 } 190 }
  191 + , this);
206 192
207 - LOG_INFO("InitAlgorthim succeed !");  
208 193
209 - return 0;  
210 - }  
211 - else {  
212 - return AUTHOR_ERROR; 194 + m_timing_snapshot_thread = new std::thread(
  195 + [](void* arg)
  196 + {
  197 + CMultiSourceProcess* _this=(CMultiSourceProcess*)arg;
  198 + if(_this != nullptr){
  199 + _this->timing_snapshot_thread();
  200 + }else{
  201 + LOG_ERROR("定时抓拍线程启动失败 !");
  202 + }
  203 + return (void*)0;
  204 + }, this);
  205 +
  206 + if(nullptr == m_timing_snapshot_thread){
  207 + LOG_ERROR("定时抓拍线程启动失败 !");
213 } 208 }
  209 +
  210 + LOG_INFO("InitAlgorthim succeed !");
  211 +
  212 + return 0;
214 } 213 }
215 214
216 #ifdef POST_USE_RABBITMQ 215 #ifdef POST_USE_RABBITMQ