Commit 5f4efeaa720ee085dd0e2198faba371971aa293d
1 parent
c5fce6ce
玩手机增加车辆朝向及雨棚过滤
Showing
5 changed files
with
584 additions
and
16 deletions
src/ai_engine_module/motocycle_refit_phone_process.cpp
0 → 100644
1 | +#include <algorithm> | |
2 | +#include "./motocycle_refit_phone_process.h" | |
3 | +#include <cmath> | |
4 | +#include "../decoder/interface/DeviceMemory.hpp" | |
5 | +#include "../common/logger.hpp" | |
6 | +#include "../ai_platform/mvpt_process_assist.h" | |
7 | + | |
8 | + | |
9 | +namespace ai_engine_module | |
10 | +{ | |
11 | + namespace motocycle_refit_phone_process | |
12 | + { | |
13 | + static std::set<algorithm_type_t> algor_type_list_ = { | |
14 | + algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE, | |
15 | + algorithm_type_t::NONMOTOR_VEHICLE_REFIT, | |
16 | + }; | |
17 | + | |
18 | + inline bool is_valid_label(const label_t &label) { | |
19 | + return ((label == label_t::usephone) || | |
20 | + (label == label_t::call)); | |
21 | + } | |
22 | + | |
23 | + std::set<algorithm_type_t> task_id_to_algorithm_type_seq(const task_id_t &task_id, | |
24 | + task_param_manager *const task_param) { | |
25 | + std::set<algorithm_type_t> seq; | |
26 | + auto &&algor_map = task_param->get_task_other_param(task_id); | |
27 | + if (algor_map) { | |
28 | + // LOG_TRACE("task id is {} size algor type {}", task_id, algor_map->size()); | |
29 | + for (auto iter = algor_map->begin(); iter != algor_map->end(); ++iter) { | |
30 | + if (algor_type_list_.count(iter->first) > 0) | |
31 | + seq.emplace(iter->first); | |
32 | + } | |
33 | + } | |
34 | + return seq; // N(RVO) | |
35 | + } | |
36 | + | |
37 | + bool is_valid_box(const int top, const int left, const int right, const int bottom, const float score, | |
38 | + const algorithm_type_t &algor_type, | |
39 | + const task_param_manager::algo_param_type_t_ *params_ptr = nullptr) { | |
40 | + if (!params_ptr) | |
41 | + return false; | |
42 | + | |
43 | + if (!snapshot_legal_inarea(params_ptr->basic_param->algor_valid_rect, left, top, right, bottom)) | |
44 | + return false; | |
45 | + | |
46 | + if (params_ptr->algor_param == nullptr) | |
47 | + return false; | |
48 | + | |
49 | + | |
50 | + const unsigned width = right - left; | |
51 | + const unsigned height = bottom - top; | |
52 | + | |
53 | + if (width == 0 || height == 0) | |
54 | + return false; | |
55 | + | |
56 | + //! TODO: use switch to replace. | |
57 | + using data_t = algor_config_param_manned_incident; | |
58 | + data_t *algor_params_ptr = (data_t *) (params_ptr->algor_param); | |
59 | + | |
60 | + if ((width < algor_params_ptr->obj_min_width || height < algor_params_ptr->obj_min_height || score < algor_params_ptr->obj_confidence_threshold)) | |
61 | + return false; | |
62 | + | |
63 | + return true; | |
64 | + } | |
65 | + | |
66 | + | |
67 | + MotorRefitPhoneProcess::MotorRefitPhoneProcess() | |
68 | + : task_param_manager_(nullptr) | |
69 | + { | |
70 | + | |
71 | + } | |
72 | + | |
73 | + MotorRefitPhoneProcess::~MotorRefitPhoneProcess() | |
74 | + { | |
75 | + if (phone_tools_) { | |
76 | + motor_phone_release(&phone_tools_); | |
77 | + phone_tools_ = nullptr; | |
78 | + } | |
79 | + if (hcp_tools_) { | |
80 | + motor_phone_release(&hcp_tools_); | |
81 | + hcp_tools_ = nullptr; | |
82 | + } | |
83 | + if (m_algorthim_ctx) { | |
84 | + aclrtDestroyContext(m_algorthim_ctx); | |
85 | + } | |
86 | + } | |
87 | + | |
88 | + bool MotorRefitPhoneProcess::init(int gpu_id, string models_dir) | |
89 | + { | |
90 | + init_ = false; | |
91 | + | |
92 | + string model_phone_path = models_dir + "/models/village/motor_phone_310p.om" ; | |
93 | + string model_hcp_path = models_dir + "/models/village/hcp211008_310p.om" ; | |
94 | + LOG_INFO("motor_phone 版本:{} 模型路径:{} hcp 版本:{} 模型路径:{}", motor_phone_getversion(), model_phone_path, hcp_get_version(), model_hcp_path); | |
95 | + | |
96 | + motor_phone_param phone_param; | |
97 | + char phone_modelNames[100]; | |
98 | + strcpy(phone_modelNames, model_phone_path.c_str()); | |
99 | + phone_param.modelNames = phone_modelNames; | |
100 | + phone_param.thresld = 0.35; | |
101 | + phone_param.devId = gpu_id; | |
102 | + | |
103 | + hcp_param hcp_param; | |
104 | + char hcp_modelNames[100]; | |
105 | + strcpy(hcp_modelNames, model_hcp_path.c_str()); | |
106 | + hcp_param.modelNames = hcp_modelNames; | |
107 | + hcp_param.devId = gpu_id; | |
108 | + | |
109 | + m_devId = gpu_id; | |
110 | + ACL_CALL(aclrtSetDevice(m_devId), ACL_SUCCESS, -1); | |
111 | + ACL_CALL(aclrtCreateContext(&m_algorthim_ctx, m_devId), ACL_SUCCESS, -1); | |
112 | + | |
113 | + int status; | |
114 | + if (!(init_ = (0 == (status = hcp_init(&hcp_tools_, hcp_param))))) | |
115 | + LOG_ERROR("Init MotorRefitProcessSdk failed error code is {}", status); | |
116 | + else if (!(init_ = (0 == (status = motor_phone_init(&phone_tools_, phone_param))))) | |
117 | + LOG_ERROR("Init MotorRefitPhoneProcessSdk failed error code is {}", status); | |
118 | + else | |
119 | + if (!task_param_manager_) | |
120 | + task_param_manager_ = task_param_manager::getInstance(); | |
121 | + return init_; | |
122 | + } | |
123 | + | |
124 | + | |
125 | + bool MotorRefitPhoneProcess::check_initied() | |
126 | + { | |
127 | + if (!init_) | |
128 | + LOG_ERROR("[%s:%d] call init function please.", __FILE__, __LINE__); | |
129 | + return init_; | |
130 | + } | |
131 | + | |
132 | + | |
133 | + void MotorRefitPhoneProcess::force_release_result(const task_id_t& task_id) { | |
134 | + for (auto iter = id_to_result_.begin(); iter != id_to_result_.end();) { | |
135 | + const auto& key = iter->first; | |
136 | + if (key.task_id == task_id) { | |
137 | + auto& value = iter->second; | |
138 | + if (value.origin_img_desc != nullptr) { | |
139 | + VPCUtil::vpc_pic_desc_release(value.origin_img_desc); | |
140 | + } | |
141 | + | |
142 | + if (value.roi_img_desc != nullptr) { | |
143 | + VPCUtil::vpc_pic_desc_release(value.roi_img_desc); | |
144 | + } | |
145 | + iter = id_to_result_.erase(iter); | |
146 | + } | |
147 | + else { | |
148 | + ++iter; | |
149 | + } | |
150 | + | |
151 | + } | |
152 | + } | |
153 | + | |
154 | + std::shared_ptr<results_data_t> MotorRefitPhoneProcess::get_result_by_objectid(const id_t& id, bool do_erase) | |
155 | + { | |
156 | + auto it = id_to_result_.find(id); | |
157 | + if (it == id_to_result_.end()) | |
158 | + return std::shared_ptr<results_data_t>(nullptr); | |
159 | + std::shared_ptr<results_data_t> res = std::make_shared<results_data_t>(it->second); | |
160 | + if (do_erase) | |
161 | + id_to_result_.erase(id); | |
162 | + return res; | |
163 | + } | |
164 | + | |
165 | + bool MotorRefitPhoneProcess::update_mstreams(const std::vector<task_id_t>& taskIds, vector<DeviceMemory*> vec_det_input_images, const std::vector<onelevel_det_result> &det_results) | |
166 | + { | |
167 | + if (!check_initied()) | |
168 | + return false; | |
169 | + | |
170 | + if (det_results.empty()) | |
171 | + { | |
172 | + LOG_DEBUG("detection result is empty."); | |
173 | + return false; | |
174 | + } | |
175 | + | |
176 | + struct stream_idx_and_algor_seq_t { | |
177 | + unsigned stream_idx; | |
178 | + std::set<algorithm_type_t> algors; | |
179 | + }; | |
180 | + | |
181 | + int n_images = det_results.size(); // or n_stream | |
182 | + | |
183 | + unsigned flattened_idx = 0; | |
184 | + std::map<int, int> flattened_idx_to_batch_idx; | |
185 | + //! 记录每个box对应的算法以及流id. | |
186 | + std::map<unsigned, stream_idx_and_algor_seq_t> flattened_idx_to_algor_seq; | |
187 | + | |
188 | + /* 1. Crop & keep some interest class. */ | |
189 | + auto taskId_iter = taskIds.begin(); | |
190 | + std::vector<sy_img> flattened_imgs(0); | |
191 | + std::vector<vpc_img_info> flattened_vpc_imgs(0); | |
192 | + std::vector<input_data_wrap_t> flattened_interest_data(0); // | |
193 | + VPCUtil* pVpcUtil = VPCUtil::getInstance(); | |
194 | + for (int n = 0; n < n_images; ++n) | |
195 | + { | |
196 | + int n_interest_obj = 0; | |
197 | + auto& src_img = vec_det_input_images[n]; | |
198 | + int src_img_w = src_img->getWidth(); | |
199 | + int src_img_h = src_img->getHeight(); | |
200 | + | |
201 | + auto& boxes_of_one_image = det_results[n].obj; | |
202 | + for (int i = 0; i < det_results[n].obj_count; ++i) | |
203 | + { | |
204 | + auto& box = boxes_of_one_image[i]; | |
205 | + if (static_cast<det_class_label_t>(box.index) == det_class_label_t::MOTOCYCLE) | |
206 | + { | |
207 | + auto& taskId = *taskId_iter; | |
208 | + input_data_wrap_t data; | |
209 | + int top = std::max(int(box.top - (IMAGE_CROP_EXPAND_RATIO * box.top)), 0); | |
210 | + int left = std::max(int(box.left - (IMAGE_CROP_EXPAND_RATIO * box.left)), 0); | |
211 | + int right = std::min(int(box.right + (IMAGE_CROP_EXPAND_RATIO * box.right)), src_img_w); | |
212 | + int bottom = std::min(int(box.bottom + (IMAGE_CROP_EXPAND_RATIO * box.bottom)), src_img_h); | |
213 | + | |
214 | + //! loop per algor from set. | |
215 | + stream_idx_and_algor_seq_t stream_idx_and_algor_seq{n, {}}; | |
216 | + std::set<algorithm_type_t> algorithm_type_seq = task_id_to_algorithm_type_seq(taskId, | |
217 | + task_param_manager_); // N(RVO). | |
218 | + | |
219 | + for (auto algor_iter = algorithm_type_seq.begin();algor_iter != algorithm_type_seq.end(); ++algor_iter) { | |
220 | + const algorithm_type_t algor_type = *algor_iter; | |
221 | + auto &&algor_param_wrap = task_param_manager_->get_task_other_param(taskId, algor_type); | |
222 | + if (!algor_param_wrap) { | |
223 | + LOG_ERROR("{} is nullptr when get algor param from task_param", taskId.c_str()); | |
224 | + continue; | |
225 | + } | |
226 | + | |
227 | + if (!is_valid_box(top, left, right, bottom, box.confidence, algor_type, algor_param_wrap)) | |
228 | + continue; | |
229 | + | |
230 | + stream_idx_and_algor_seq.algors.emplace(algor_type); | |
231 | + } | |
232 | + | |
233 | + if (stream_idx_and_algor_seq.algors.empty()) | |
234 | + continue; | |
235 | + | |
236 | + int width = right - left; | |
237 | + int height = bottom - top; | |
238 | + | |
239 | + data.box.top = top; | |
240 | + data.box.left = left; | |
241 | + data.box.right = right; | |
242 | + data.box.bottom = bottom; | |
243 | + data.box.score = box.confidence; | |
244 | + data.taskId = taskId; | |
245 | + data.objId = box.id; | |
246 | + | |
247 | + // 抠图 | |
248 | + video_object_info obj; | |
249 | + strcpy(obj.task_id, taskId.c_str()); | |
250 | + obj.object_id = box.id; | |
251 | + obj.left = left; obj.top = top; | |
252 | + obj.right = right; obj.bottom = bottom; | |
253 | + | |
254 | + vpc_img_info img_info = pVpcUtil->crop(src_img, obj); | |
255 | + | |
256 | + sy_img img; | |
257 | + img.w_ = width; | |
258 | + img.h_ = height; | |
259 | + img.c_ = src_img->getChannel(); | |
260 | + | |
261 | + if (img_info.pic_desc != nullptr) { | |
262 | + void *outputDataDev = acldvppGetPicDescData(img_info.pic_desc); | |
263 | + img.data_ = reinterpret_cast<unsigned char*>(outputDataDev); | |
264 | + } | |
265 | + else { | |
266 | + LOG_ERROR("Crop image NPU failed wh is [{}, {}] ltrb is [{} {} {} {}]", | |
267 | + src_img_w, src_img_h, data.box.left, data.box.top, data.box.right, data.box.bottom); | |
268 | + continue; | |
269 | + } | |
270 | + | |
271 | + flattened_imgs.emplace_back(std::move(img)); | |
272 | + flattened_vpc_imgs.emplace_back(std::move(img_info)); | |
273 | + flattened_interest_data.emplace_back(std::move(data)); | |
274 | + flattened_idx_to_algor_seq[flattened_idx] = std::move(stream_idx_and_algor_seq); | |
275 | + flattened_idx_to_batch_idx[flattened_idx++] = n; | |
276 | + } | |
277 | + } | |
278 | + ++taskId_iter; | |
279 | + } | |
280 | + | |
281 | + int ret = aclrtSetCurrentContext(m_algorthim_ctx); | |
282 | + if (ACL_SUCCESS != ret) { | |
283 | + return false; | |
284 | + } | |
285 | + /* 2. collection result. */ | |
286 | + int n_input_image = flattened_imgs.size(); | |
287 | + hcp_analysis_result model_results[n_input_image]; | |
288 | + // motor_phone_result model_results[n_input_image]; | |
289 | + { | |
290 | + int steps = (n_input_image + MAX_BATCH - 1) / MAX_BATCH; | |
291 | + for (int step = 0; step < steps; ++step) | |
292 | + { | |
293 | + int offset = step * MAX_BATCH; | |
294 | + int batch_size = (step == steps - 1) ? n_input_image - offset : MAX_BATCH; | |
295 | + hcp_batch(hcp_tools_, flattened_imgs.data() + offset, batch_size, model_results + offset); | |
296 | + // motor_phone_process_batch(phone_tools_, flattened_imgs.data() + offset, batch_size, model_results + offset); | |
297 | + } | |
298 | + } | |
299 | + | |
300 | + /* 3. postprocess. */ | |
301 | + { | |
302 | + for (int n = 0; n < n_input_image; ++n) | |
303 | + { | |
304 | + auto& det_result = flattened_interest_data[n]; | |
305 | + auto& objId = det_result.objId; | |
306 | + auto& task_id = det_result.taskId; | |
307 | + | |
308 | + auto &stream_idx_and_algor_seq = flattened_idx_to_algor_seq[n]; | |
309 | + auto &algors = stream_idx_and_algor_seq.algors; | |
310 | + // auto &steram_idx = stream_idx_and_algor_seq.stream_idx; | |
311 | + | |
312 | + const auto& src_img = vec_det_input_images[flattened_idx_to_batch_idx[n]]; | |
313 | + auto &model_result = model_results[n]; | |
314 | + auto &orient_pred = model_result.res_objs[11]; // 211008模型索引11对应车辆朝向 0–(正面),1-(背面),2-(侧面) | |
315 | + auto &refit_pred = model_result.res_objs[12]; // 211008模型索引12对应是否有雨棚 0–(无),1-(有) | |
316 | + | |
317 | + | |
318 | + for (auto algor_type_iter = algors.begin();algor_type_iter != algors.end(); ++algor_type_iter) { | |
319 | + const algorithm_type_t algor_type = *algor_type_iter; | |
320 | + | |
321 | + auto &&algor_param_wrap = task_param_manager_->get_task_other_param(task_id, algor_type); | |
322 | + if (!algor_param_wrap) { | |
323 | + LOG_ERROR("{} is nullptr when get algor param from task_param", task_id); | |
324 | + continue; | |
325 | + } | |
326 | + auto algor_param = ((algor_param_type)algor_param_wrap->algor_param); | |
327 | + | |
328 | + id_t obj_key = obj_key_t{ objId, task_id, algor_type}; | |
329 | + if (id_to_result_.find(obj_key) != id_to_result_.end()) | |
330 | + continue; | |
331 | + | |
332 | + // LOG_TRACE("task id is {} algor type is {} obj_id {}", task_id, int(algor_type), objId); | |
333 | + | |
334 | + auto& e = id_to_mn_[obj_key]; | |
335 | + ++e.m_frame; | |
336 | + | |
337 | + if (algor_type == algorithm_type_t::NONMOTOR_VEHICLE_REFIT && refit_pred.res_index != 1) | |
338 | + continue; | |
339 | + | |
340 | + // 数量小于设定阈值不报警 | |
341 | + if (algor_type == algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) { | |
342 | + if (refit_pred.res_index != 0 || orient_pred.res_index != 0) continue; //有雨棚或不是正面则不判手机 | |
343 | + motor_phone_result phone_results[1]; | |
344 | + motor_phone_process_batch(phone_tools_, flattened_imgs.data() + n, 1, phone_results); | |
345 | + int phone_cnt = 0; //统计玩手机/打电话的检测目标个数 | |
346 | + for (unsigned i = 0; i < phone_results[0].objcount; ++i) { | |
347 | + auto &box = phone_results[0].objinfo[i]; | |
348 | + const label_t label = static_cast<label_t>(box.index); | |
349 | + if (!is_valid_label(label)) | |
350 | + continue; | |
351 | + LOG_TRACE("task id is {} obj_id {} label {} index {} score {}", task_id, objId, label, box.index, box.confidence); | |
352 | + phone_cnt ++; | |
353 | + } | |
354 | + if (phone_cnt < 1) continue; | |
355 | + } | |
356 | + | |
357 | + | |
358 | + { | |
359 | + if (++e.n_frame == algor_param->n) | |
360 | + { | |
361 | + results_data_t result; | |
362 | + { | |
363 | + result.box = det_result.box; | |
364 | + result.taskId = det_result.taskId; | |
365 | + result.objId = det_result.objId; | |
366 | + result.algor_type = algor_type; | |
367 | + // 原图 | |
368 | + vpc_img_info src_img_info = VPCUtil::vpc_devMem2vpcImg(src_img); | |
369 | + result.origin_img_desc = src_img_info.pic_desc; | |
370 | + // 抠图--拷贝后赋值 | |
371 | + void *outputDataDev = acldvppGetPicDescData(flattened_vpc_imgs[n].pic_desc); | |
372 | + int nBufferSize = acldvppGetPicDescSize(flattened_vpc_imgs[n].pic_desc); | |
373 | + | |
374 | + void *devBuffer = nullptr; | |
375 | + auto ret = acldvppMalloc(&devBuffer, nBufferSize); | |
376 | + if (ret != ACL_SUCCESS) { | |
377 | + LOG_ERROR("acldvppMalloc failed, size = %u, errorCode = %d.", nBufferSize, static_cast<int32_t>(ret)); | |
378 | + return false; | |
379 | + } | |
380 | + aclrtMemcpy(devBuffer, nBufferSize, outputDataDev, nBufferSize, ACL_MEMCPY_DEVICE_TO_DEVICE); | |
381 | + | |
382 | + acldvppPicDesc *vpcInputDesc_= acldvppCreatePicDesc(); | |
383 | + acldvppSetPicDescData(vpcInputDesc_, devBuffer); | |
384 | + acldvppSetPicDescFormat(vpcInputDesc_, PIXEL_FORMAT_YUV_SEMIPLANAR_420); | |
385 | + acldvppSetPicDescWidth(vpcInputDesc_, acldvppGetPicDescWidth(flattened_vpc_imgs[n].pic_desc)); | |
386 | + acldvppSetPicDescHeight(vpcInputDesc_, acldvppGetPicDescHeight(flattened_vpc_imgs[n].pic_desc)); | |
387 | + acldvppSetPicDescWidthStride(vpcInputDesc_, acldvppGetPicDescWidthStride(flattened_vpc_imgs[n].pic_desc)); | |
388 | + acldvppSetPicDescHeightStride(vpcInputDesc_, acldvppGetPicDescHeightStride(flattened_vpc_imgs[n].pic_desc)); | |
389 | + acldvppSetPicDescSize(vpcInputDesc_, nBufferSize); | |
390 | + | |
391 | + result.roi_img_desc = vpcInputDesc_; //需复制 | |
392 | + } | |
393 | + id_to_result_.emplace(obj_key, std::move(result)); | |
394 | + } | |
395 | + } | |
396 | + | |
397 | + if (e.m_frame == algor_param->m) | |
398 | + e.reset(); | |
399 | + | |
400 | + } | |
401 | + | |
402 | + VPCUtil::vpc_img_release(flattened_vpc_imgs[n]); //flattened_imgs[n].data_ | |
403 | + | |
404 | + } | |
405 | + } | |
406 | + | |
407 | + return true; | |
408 | + } | |
409 | + | |
410 | + } // namespace motocycle_refit_phone_process | |
411 | + | |
412 | +} // namespace ai_engine_module | |
413 | + | ... | ... |
src/ai_engine_module/motocycle_refit_phone_process.h
0 → 100644
1 | +#pragma once | |
2 | +#include <deque> | |
3 | +#include <map> | |
4 | +#include <vector> | |
5 | +#include <memory> | |
6 | +#include "../util/vpc_util.h" | |
7 | +#include "../ai_platform/task_param_manager.h" | |
8 | +#include "../ai_platform/macro_definition.h" | |
9 | +#include "ai_engine_header.h" | |
10 | +#include "human_car_parsing.h" | |
11 | +#include "motor_phone_det.h" | |
12 | +#include "acl/acl.h" | |
13 | +#include "acl/ops/acl_dvpp.h" | |
14 | + | |
15 | +#define MAX_BATCH 20 | |
16 | +#define IMAGE_CROP_EXPAND_RATIO 0 | |
17 | +#define MAX_OBJ_BOX_COUNT 100 | |
18 | + | |
19 | +namespace ai_engine_module | |
20 | +{ | |
21 | + namespace motocycle_refit_phone_process | |
22 | + { | |
23 | + // typedef long id_t; | |
24 | + using id_t = obj_key_t; | |
25 | + using task_id_t = std::string; | |
26 | + using algor_param_type = algor_config_param_manned_incident*; | |
27 | + | |
28 | + enum class label_t { | |
29 | + PLACEHOLDER = -1, | |
30 | + smoke = 0, //抽烟 | |
31 | + usephone = 1, //玩手机 | |
32 | + call = 2, //接打电话 | |
33 | + food = 3, // | |
34 | + handrail = 4, //手握在车把上 | |
35 | + hand = 5, //手悬空 | |
36 | + }; | |
37 | + | |
38 | + typedef struct input_data_wrap_t | |
39 | + { | |
40 | + id_t id; | |
41 | + long objId; | |
42 | + std::string taskId; | |
43 | + box_t box; | |
44 | + } input_data_wrap_t; | |
45 | + | |
46 | + | |
47 | + typedef struct mn_frame_t | |
48 | + { | |
49 | + uint m_frame; | |
50 | + uint n_frame; | |
51 | + | |
52 | + // explicit | |
53 | + mn_frame_t(uint m = 0, uint n = 0) | |
54 | + : m_frame(m) | |
55 | + , n_frame(n) | |
56 | + {} | |
57 | + | |
58 | + void reset() | |
59 | + { | |
60 | + m_frame = 0; | |
61 | + n_frame = 0; | |
62 | + } | |
63 | + | |
64 | + } mn_frame_t; | |
65 | + | |
66 | + | |
67 | + typedef struct results_data_t | |
68 | + { | |
69 | + box_t box; | |
70 | + acldvppPicDesc* origin_img_desc{nullptr}; | |
71 | + acldvppPicDesc* roi_img_desc{nullptr}; | |
72 | + id_t id; | |
73 | + long objId; | |
74 | + std::string taskId; | |
75 | + algorithm_type_t algor_type; | |
76 | + } results_data_t; | |
77 | + | |
78 | + class MotorRefitPhoneProcess | |
79 | + { | |
80 | + /** | |
81 | + * @brief | |
82 | + * 1. move able | |
83 | + */ | |
84 | + public: | |
85 | + MotorRefitPhoneProcess(); | |
86 | + | |
87 | + ~MotorRefitPhoneProcess(); | |
88 | + | |
89 | + bool check_initied(); | |
90 | + bool init(int gpu_id, string models_dir); | |
91 | + bool update_mstreams(const std::vector<task_id_t>& taskIds, vector<DeviceMemory*> vec_det_input_images, const std::vector<onelevel_det_result> &det_results); | |
92 | + std::shared_ptr<results_data_t> get_result_by_objectid(const id_t& id, bool do_erase = true); | |
93 | + | |
94 | + void force_release_result(const task_id_t& task_id); | |
95 | + | |
96 | + MotorRefitPhoneProcess(const MotorRefitPhoneProcess&) = delete; | |
97 | + MotorRefitPhoneProcess& operator=(const MotorRefitPhoneProcess&) = delete; | |
98 | + | |
99 | + private: | |
100 | + static algorithm_type_t algor_type_; | |
101 | + int m_devId; | |
102 | + aclrtContext m_algorthim_ctx; | |
103 | + | |
104 | + bool init_; | |
105 | + void* phone_tools_; | |
106 | + void* hcp_tools_; | |
107 | + task_param_manager* task_param_manager_; | |
108 | + std::map<id_t, mn_frame_t> id_to_mn_; | |
109 | + std::map<id_t, results_data_t> id_to_result_; | |
110 | + }; | |
111 | + } // namespace motocycle_refit_phone_process | |
112 | +} // namespace ai_engine_module | |
113 | + | ... | ... |
src/ai_platform/MultiSourceProcess.cpp
... | ... | @@ -178,6 +178,13 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ |
178 | 178 | LOG_FATAL("Init motor_hs failed"); |
179 | 179 | return -1; |
180 | 180 | } |
181 | + | |
182 | + //二轮车使用手机及加雨棚 | |
183 | + if (!motor_refit_phoneprocess_.init(vptParam.gpuid, models_dir)) { | |
184 | + LOG_FATAL("Init motor_phone failed"); | |
185 | + return -1; | |
186 | + } | |
187 | + /* | |
181 | 188 | //二轮车使用手机检测 |
182 | 189 | if (!motor_phoneprocess_.init(vptParam.gpuid, models_dir)) { |
183 | 190 | LOG_FATAL("Init motor_phone failed"); |
... | ... | @@ -187,7 +194,7 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ |
187 | 194 | if (!motor_refitprocess_.init(vptParam.gpuid, models_dir)) { |
188 | 195 | LOG_FATAL("Init motor_refit failed"); |
189 | 196 | return -1; |
190 | - } | |
197 | + }*/ | |
191 | 198 | #endif |
192 | 199 | |
193 | 200 | #ifdef WITH_FACE_DET_SS |
... | ... | @@ -701,8 +708,9 @@ bool CMultiSourceProcess::finish_task(const string taskID, const bool delete_sna |
701 | 708 | tricycle_manned_.force_release_result(taskID); |
702 | 709 | truck_manned_.force_release_result(taskID); |
703 | 710 | motor_hsprocess_.force_release_result(taskID); |
704 | - motor_phoneprocess_.force_release_result(taskID); | |
705 | - motor_refitprocess_.force_release_result(taskID); | |
711 | + motor_refit_phoneprocess_.force_release_result(taskID); | |
712 | + // motor_phoneprocess_.force_release_result(taskID); | |
713 | + // motor_refitprocess_.force_release_result(taskID); | |
706 | 714 | |
707 | 715 | m_task_param_manager->delete_task_param(taskID); |
708 | 716 | #endif |
... | ... | @@ -891,10 +899,12 @@ int CMultiSourceProcess::algorthim_vpt(vector<DeviceMemory*> vec_gpuMem){ |
891 | 899 | algorithm_truck_manned(vpt_interest_task_id, vec_vptMem, vptResult); |
892 | 900 | // 二轮车超员/未戴盔 |
893 | 901 | algorithm_motor_hs_process(vpt_interest_task_id, vec_vptMem, vptResult); |
894 | - // 二轮车驾乘人员使用手机 | |
902 | + // 二轮车驾乘人员使用手机及加雨棚 | |
903 | + algorithm_motor_refit_phone_process(vpt_interest_task_id, vec_vptMem, vptResult); | |
904 | + /*// 二轮车驾乘人员使用手机 | |
895 | 905 | algorithm_motor_phone_process(vpt_interest_task_id, vec_vptMem, vptResult); |
896 | 906 | // 电动车改装(加雨棚) |
897 | - algorithm_motor_refit_process(vpt_interest_task_id, vec_vptMem, vptResult); | |
907 | + algorithm_motor_refit_process(vpt_interest_task_id, vec_vptMem, vptResult);*/ | |
898 | 908 | village_snapshot(vpt_interest_task_id, vec_vptMem, deleteObjectID); |
899 | 909 | #endif |
900 | 910 | |
... | ... | @@ -1347,7 +1357,34 @@ void CMultiSourceProcess::algorithm_motor_hs_process(vector<string>& vpt_interes |
1347 | 1357 | } |
1348 | 1358 | } |
1349 | 1359 | |
1350 | -// 二轮车驾乘人员使用手机 | |
1360 | +// 二轮车驾乘人员使用手机及加雨棚 | |
1361 | +void CMultiSourceProcess::algorithm_motor_refit_phone_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, | |
1362 | + vector<onelevel_det_result>& vptResult) { | |
1363 | + | |
1364 | + vector<string> interest_task_id; | |
1365 | + vector<onelevel_det_result> interest_vpt_result; | |
1366 | + vector<DeviceMemory*> interest_imgs; | |
1367 | + | |
1368 | + int _idx = 0; | |
1369 | + for (auto _task_id_iter = vpt_interest_task_id.begin(); _task_id_iter != vpt_interest_task_id.end(); | |
1370 | + ++_task_id_iter, ++_idx) // loop task_id; | |
1371 | + { | |
1372 | + auto task_id = *_task_id_iter; | |
1373 | + auto algor_map = m_task_param_manager->get_task_other_param(task_id); | |
1374 | + | |
1375 | + if (algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE) != algor_map->end() || | |
1376 | + algor_map->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT) != algor_map->end()) { | |
1377 | + interest_task_id.emplace_back(task_id); | |
1378 | + interest_imgs.emplace_back(vpt_interest_imgs[_idx]); | |
1379 | + interest_vpt_result.emplace_back(vptResult[_idx]); | |
1380 | + } | |
1381 | + } | |
1382 | + | |
1383 | + if (!interest_imgs.empty()){ | |
1384 | + motor_refit_phoneprocess_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); | |
1385 | + } | |
1386 | +} | |
1387 | +/*// 二轮车驾乘人员使用手机 | |
1351 | 1388 | void CMultiSourceProcess::algorithm_motor_phone_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, |
1352 | 1389 | vector<onelevel_det_result>& vptResult) { |
1353 | 1390 | |
... | ... | @@ -1399,7 +1436,7 @@ void CMultiSourceProcess::algorithm_motor_refit_process(vector<string>& vpt_inte |
1399 | 1436 | if (!interest_imgs.empty()){ |
1400 | 1437 | motor_refitprocess_.update_mstreams(interest_task_id, interest_imgs, interest_vpt_result); |
1401 | 1438 | } |
1402 | -} | |
1439 | +}*/ | |
1403 | 1440 | |
1404 | 1441 | // for snapshot algorithm. 轨迹结束目标 做最后的结果返回(当前返回算法结果+快照保存路径) |
1405 | 1442 | void CMultiSourceProcess::village_snapshot(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vec_vptMem, vector<vector<int>> deleteObjectID) { |
... | ... | @@ -1517,7 +1554,8 @@ void CMultiSourceProcess::village_snapshot(vector<string>& vpt_interest_task_id, |
1517 | 1554 | const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE); |
1518 | 1555 | const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; |
1519 | 1556 | |
1520 | - auto result = motor_phoneprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE}); | |
1557 | + // auto result = motor_phoneprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE}); | |
1558 | + auto result = motor_refit_phoneprocess_.get_result_by_objectid(ai_engine_module::obj_key_t{obj_key.obj_id, obj_key.video_id, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE}); | |
1521 | 1559 | if (result.get()) { |
1522 | 1560 | village_alarm = true; |
1523 | 1561 | algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE); |
... | ... | @@ -1541,7 +1579,8 @@ void CMultiSourceProcess::village_snapshot(vector<string>& vpt_interest_task_id, |
1541 | 1579 | const auto &algor_other_params = task_other_params->find(algorithm_type_t::NONMOTOR_VEHICLE_REFIT); |
1542 | 1580 | const algor_basic_config_param_t *basic_param = algor_other_params->second->basic_param; |
1543 | 1581 | |
1544 | - 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}); | |
1582 | + // 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}); | |
1583 | + 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}); | |
1545 | 1584 | if (result.get()) { |
1546 | 1585 | village_alarm = true; |
1547 | 1586 | algorithm_types.push_back((int)algorithm_type_t::NONMOTOR_VEHICLE_REFIT); | ... | ... |
src/ai_platform/MultiSourceProcess.h
... | ... | @@ -19,6 +19,7 @@ |
19 | 19 | #include "../ai_engine_module/tricycle_manned_process.h" |
20 | 20 | #include "../ai_engine_module/truck_manned_process.h" |
21 | 21 | #include "../ai_engine_module/motocycle_hs_process.h" |
22 | +#include "../ai_engine_module/motocycle_refit_phone_process.h" | |
22 | 23 | #include "../ai_engine_module/motocycle_phone_process.h" |
23 | 24 | #include "../ai_engine_module/motocycle_refit_process.h" |
24 | 25 | #include "../util/JpegUtil.h" |
... | ... | @@ -77,6 +78,8 @@ private: |
77 | 78 | void algorithm_truck_manned(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, vector<onelevel_det_result>& vptResult); |
78 | 79 | // 二轮车超员及未戴盔 |
79 | 80 | void algorithm_motor_hs_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, vector<onelevel_det_result>& vptResult); |
81 | + // 电动车改装(加雨棚)及二轮车驾乘人员使用手机 | |
82 | + void algorithm_motor_refit_phone_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, vector<onelevel_det_result>& vptResult); | |
80 | 83 | // 二轮车驾乘人员使用手机 |
81 | 84 | void algorithm_motor_phone_process(vector<string>& vpt_interest_task_id, vector<DeviceMemory*> vpt_interest_imgs, vector<onelevel_det_result>& vptResult); |
82 | 85 | // 电动车改装(加雨棚) |
... | ... | @@ -146,8 +149,9 @@ private: |
146 | 149 | ai_engine_module::tricycle_manned_process::TricycleMannedProcess tricycle_manned_; |
147 | 150 | ai_engine_module::truck_manned_process::TruckMannedProcess truck_manned_; |
148 | 151 | ai_engine_module::motocycle_hs_process::MotorHsProcess motor_hsprocess_; |
149 | - ai_engine_module::motocycle_phone_process::MotorPhoneProcess motor_phoneprocess_; | |
150 | - ai_engine_module::motocycle_refit_process::MotorRefitProcess motor_refitprocess_; | |
152 | + ai_engine_module::motocycle_refit_phone_process::MotorRefitPhoneProcess motor_refit_phoneprocess_; | |
153 | + // ai_engine_module::motocycle_phone_process::MotorPhoneProcess motor_phoneprocess_; | |
154 | + // ai_engine_module::motocycle_refit_process::MotorRefitProcess motor_refitprocess_; | |
151 | 155 | |
152 | 156 | face_det_ai_engine m_face_det_ai_engine; // 人脸检测 |
153 | 157 | ... | ... |
src/demo/demo.cpp
... | ... | @@ -705,7 +705,7 @@ string createTask(void *handle, std::vector<algorithm_type_t> algor_vec, int gi, |
705 | 705 | // tparam.ipc_url = "rtsp://122.97.218.170:8604/openUrl/V5nXRHa?params=eyJwcm90b2NhbCI6InJ0c3AiLCJjbGllbnRUeXBlIjoib3Blbl9hcGkiLCJleHByaWVUaW1lIjotMSwicHJvdG9jb2wiOiJydHNwIiwiZXhwaXJlVGltZSI6MzAwLCJlbmFibGVNR0MiOnRydWUsImV4cGFuZCI6InN0YW5kYXJkPXJ0c3Amc3RyZWFtZm9ybT1ydHAiLCJhIjoiMTBjZjM4N2JjY2Y5NDg3YzhjNWYzNjE2M2ViMWUyNTJ8MXwwfDEiLCJ0IjoxfQ=="; |
706 | 706 | break; |
707 | 707 | case 4: |
708 | - tparam.ipc_url = "/opt/share/data/Street.uvf"; | |
708 | + tparam.ipc_url = "/data/share/data/Street.uvf"; | |
709 | 709 | break; |
710 | 710 | case 5: |
711 | 711 | tparam.ipc_url = "/data/share/data/公安局老桥头_CVR15F89410_1465819864_1B.mp4"; |
... | ... | @@ -714,7 +714,7 @@ string createTask(void *handle, std::vector<algorithm_type_t> algor_vec, int gi, |
714 | 714 | tparam.ipc_url = "/data/share/data/不带头盔2.mp4"; |
715 | 715 | break; |
716 | 716 | case 7: |
717 | - tparam.ipc_url = "/opt/share/data/caishenkezhan.mp4"; | |
717 | + tparam.ipc_url = "/data/share/data/hczr1.mp4"; | |
718 | 718 | break; |
719 | 719 | case 8: |
720 | 720 | tparam.ipc_url = "/opt/share/data/1-00000001d9.mp4"; |
... | ... | @@ -840,7 +840,6 @@ void test_gpu(int gpuID){ |
840 | 840 | |
841 | 841 | std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE, |
842 | 842 | algorithm_type_t::NONMOTOR_VEHICLE_REFIT}; |
843 | - // std::vector<algorithm_type_t> algor_vec2 = {algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::TRUCK_MANNED}; | |
844 | 843 | std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::FACE_SNAPSHOT}; |
845 | 844 | |
846 | 845 | /* |
... | ... | @@ -863,10 +862,10 @@ void test_gpu(int gpuID){ |
863 | 862 | // createTask(handle, algor_vec, 1); |
864 | 863 | // createTask(handle, algor_vec, 2); |
865 | 864 | // createTask(handle, algor_vec, 3); |
866 | - // createTask(handle, algor_vec, 4); | |
865 | + createTask(handle, algor_vec2, 4); | |
867 | 866 | createTask(handle, algor_vec2, 5); |
868 | 867 | createTask(handle, algor_vec2, 6); |
869 | - // createTask(handle, algor_vec, 7); | |
868 | + createTask(handle, algor_vec2, 7); | |
870 | 869 | // createTask(handle, algor_vec, 8); |
871 | 870 | // createTask(handle, algor_vec, 9); |
872 | 871 | // createTask(handle, algor_vec, 10); | ... | ... |