Commit 8c495cc96a825d0be2339760f5c10ca5ffc7eb4e
1 parent
12fade9b
增加实线掉头(515)功能
Showing
9 changed files
with
454 additions
and
26 deletions
src/ai_engine_module/road_seg_correlation_algor.cpp
... | ... | @@ -20,6 +20,7 @@ namespace ai_engine_module |
20 | 20 | algorithm_type_t::PERSON_CROSS, |
21 | 21 | algorithm_type_t::NONMOTOR_WRONGDIRECTION, |
22 | 22 | algorithm_type_t::VEHICLE_WRONGDIRECTION, |
23 | + algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND, | |
23 | 24 | algorithm_type_t::VEHICLE_NOTGIVEWAY, |
24 | 25 | }; |
25 | 26 | |
... | ... | @@ -237,6 +238,91 @@ namespace ai_engine_module |
237 | 238 | return true; } |
238 | 239 | } |
239 | 240 | /*----------------------分割线---------------分割线--------------------*/ |
241 | + // 获取轨迹起点/终点:去除离群点后取平均 | |
242 | + bool find_traceStartEnd(const vector<sy_point>& tracker_list, int check_frames, jxline& trace_line) { | |
243 | + int stcnt = 0, edcnt = 0; | |
244 | + float center_sum_x = 0, center_sum_y = 0, center_nsum_x = 0, center_nsum_y = 0; | |
245 | + for (int tmp = tracker_list.size()-check_frames; tmp < tracker_list.size()-check_frames+3; tmp++) { | |
246 | + center_sum_x += tracker_list[tmp].x_; | |
247 | + center_sum_y += tracker_list[tmp].y_; | |
248 | + } | |
249 | + float center_ave_x = center_sum_x / 3; float center_ave_y = center_sum_y / 3; | |
250 | + for (int tmp = tracker_list.size()-check_frames; tmp < tracker_list.size()-11; tmp++) { | |
251 | + if (abs(tracker_list[tmp].x_ - center_ave_x) > 300 || abs(tracker_list[tmp].y_ - center_ave_y) > 300) | |
252 | + continue; | |
253 | + center_nsum_x += tracker_list[tmp].x_; | |
254 | + center_nsum_y += tracker_list[tmp].y_; | |
255 | + stcnt += 1; | |
256 | + } | |
257 | + | |
258 | + float center_edsum_x = 0, center_edsum_y = 0, center_ednsum_x = 0, center_ednsum_y = 0; | |
259 | + for (int tmp = tracker_list.size()-3; tmp < tracker_list.size(); tmp++) { | |
260 | + center_edsum_x += tracker_list[tmp].x_; | |
261 | + center_edsum_y += tracker_list[tmp].y_; | |
262 | + } | |
263 | + float center_edave_x = center_edsum_x / 3; float center_edave_y = center_edsum_y / 3; | |
264 | + for (int tmp = tracker_list.size()-3; tmp < tracker_list.size(); tmp++) { | |
265 | + if (abs(tracker_list[tmp].x_ - center_edave_x) > 300 || abs(tracker_list[tmp].y_ - center_edave_y) > 300) | |
266 | + continue; | |
267 | + center_ednsum_x += tracker_list[tmp].x_; | |
268 | + center_ednsum_y += tracker_list[tmp].y_; | |
269 | + edcnt += 1; | |
270 | + } | |
271 | + | |
272 | + if (stcnt > 0 && edcnt > 0) { | |
273 | + trace_line.xa = center_nsum_x / stcnt; trace_line.ya = center_nsum_y / stcnt; | |
274 | + trace_line.xb = center_ednsum_x / edcnt; trace_line.yb = center_ednsum_y / edcnt; | |
275 | + float t_diff_x = trace_line.xb - trace_line.xa, t_diff_y = trace_line.yb - trace_line.ya; | |
276 | + float temp_dist = sqrt(t_diff_x * t_diff_x + t_diff_y * t_diff_y); | |
277 | + if (temp_dist > 50) return true; // 位移限制 | |
278 | + } | |
279 | + | |
280 | + return false; | |
281 | + } | |
282 | + | |
283 | + // 判断是否相交 | |
284 | + bool is_intersect(jxline myline1, jxline myline2) | |
285 | + { | |
286 | + // 快速排斥实验 | |
287 | + if (myline1.get_max_x() < myline2.get_min_x() || | |
288 | + myline2.get_max_x() < myline1.get_min_x() || | |
289 | + myline1.get_max_y() < myline2.get_min_y() || | |
290 | + myline2.get_max_y() < myline1.get_min_y()) | |
291 | + return false; | |
292 | + | |
293 | + // 跨立实验(叉积异号) | |
294 | + if (((((float)myline1.xa - (float)myline2.xa)*((float)myline2.yb - (float)myline2.ya) - ((float)myline1.ya - (float)myline2.ya)*((float)myline2.xb - (float)myline2.xa))* | |
295 | + (((float)myline1.xb - (float)myline2.xa)*((float)myline2.yb - (float)myline2.ya) - ((float)myline1.yb - (float)myline2.ya)*((float)myline2.xb - (float)myline2.xa))) > 0 || | |
296 | + ((((float)myline2.xa - (float)myline1.xa)*((float)myline1.yb - (float)myline1.ya) - ((float)myline2.ya - (float)myline1.ya)*((float)myline1.xb - (float)myline1.xa))* | |
297 | + (((float)myline2.xb - (float)myline1.xa)*((float)myline1.yb - (float)myline1.ya) - ((float)myline2.yb - (float)myline1.ya)*((float)myline1.xb - (float)myline1.xa))) > 0) | |
298 | + return false; | |
299 | + | |
300 | + return true; | |
301 | + } | |
302 | + | |
303 | + // 判断掉头:以轨迹中间为界,判断前后方向是否一致 | |
304 | + bool vTurnAround(const vector<sy_point>& tracker_list, int check_frames) { | |
305 | + int trackcnt = tracker_list.size(); | |
306 | + int half_check_frames = check_frames / 2; | |
307 | + tr_point p_start, p_end, p_half; | |
308 | + p_start.x = tracker_list[trackcnt-check_frames-1].x_; p_start.y = tracker_list[trackcnt-check_frames-1].y_; | |
309 | + p_end.x = tracker_list[trackcnt-1].x_; p_end.y = tracker_list[trackcnt-1].y_; | |
310 | + p_half.x = tracker_list[trackcnt-half_check_frames-1].x_; p_half.y = tracker_list[trackcnt-half_check_frames-1].y_; | |
311 | + // 车辆方向 | |
312 | + tr_point car_toward1, car_toward2; | |
313 | + car_toward1.x = p_half.x - p_start.x; car_toward1.y = p_half.y - p_start.y; | |
314 | + car_toward2.x = p_end.x - p_half.x; car_toward2.y = p_end.y - p_half.y; | |
315 | + | |
316 | + float temp_dist1 = sqrt(car_toward1.x * car_toward1.x + car_toward1.y * car_toward1.y); | |
317 | + float temp_dist2 = sqrt(car_toward2.x * car_toward2.x + car_toward2.y * car_toward2.y); | |
318 | + if (temp_dist1 < 40 || temp_dist2 < 40) return false; // 位移限制 | |
319 | + | |
320 | + int deg1 = atan2(car_toward1.y, car_toward1.x) * 180 / Pi; // 返回与x轴的夹角 | |
321 | + int deg2 = atan2(car_toward2.y, car_toward2.x) * 180 / Pi; | |
322 | + int deg_diff = abs(deg1 - deg2); | |
323 | + if (deg_diff < 135) { return false; } | |
324 | + else { return true; } | |
325 | + } | |
240 | 326 | |
241 | 327 | vector<tr_point> Mbuild_area(vector<int> args) |
242 | 328 | { |
... | ... | @@ -494,7 +580,8 @@ namespace ai_engine_module |
494 | 580 | continue; |
495 | 581 | |
496 | 582 | stream_idx_and_algor_seq.algors.emplace(algor_type); |
497 | - if (algor_type == algorithm_type_t::VEHICLE_WRONGDIRECTION || algor_type == algorithm_type_t::VEHICLE_NOTGIVEWAY) has_vehicle_algor = true; | |
583 | + if (algor_type == algorithm_type_t::VEHICLE_WRONGDIRECTION || algor_type == algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND || | |
584 | + algor_type == algorithm_type_t::VEHICLE_NOTGIVEWAY) has_vehicle_algor = true; | |
498 | 585 | } |
499 | 586 | |
500 | 587 | if (stream_idx_and_algor_seq.algors.empty()) |
... | ... | @@ -591,7 +678,8 @@ namespace ai_engine_module |
591 | 678 | auto fence_labels_ = fence_labels[flattened_idx_to_batch_idx[n]]; |
592 | 679 | |
593 | 680 | vector<vector<int>> vehiclelanes_regions; //机动车区域 |
594 | - vector<vector<int>> crosswalk_regions; //人行道区域+十字路口区域 | |
681 | + vector<vector<int>> crosswalk_regions; //人行道+十字路口区域 | |
682 | + vector<vector<int>> solidlines; //黄实线+白实线 | |
595 | 683 | // printf("seg_labels.size:%d\n",seg_labels.size()); |
596 | 684 | for (unsigned i = 0; i < seg_labels.size(); ++i) { |
597 | 685 | const label_t label = static_cast<label_t>(seg_labels[i]); |
... | ... | @@ -603,6 +691,10 @@ namespace ai_engine_module |
603 | 691 | vector<int> cur_region(seg_regions[i].begin(),seg_regions[i].end()); |
604 | 692 | crosswalk_regions.push_back(cur_region); |
605 | 693 | } |
694 | + if ((label == label_t::yellow_solidline || label == label_t::white_solidline)) { | |
695 | + vector<int> cur_region(seg_regions[i].begin(),seg_regions[i].end()); | |
696 | + solidlines.push_back(cur_region); | |
697 | + } | |
606 | 698 | } |
607 | 699 | |
608 | 700 | vector<vector<int>> roadseg_fence_regions;//车道分割护栏区域 |
... | ... | @@ -637,7 +729,7 @@ namespace ai_engine_module |
637 | 729 | if ((algor_type == algorithm_type_t::NONMOTOR_IN_VEHICLELANE || algor_type == algorithm_type_t::NONMOTOR_CEOSSPARKLINE || algor_type == algorithm_type_t::NONMOTOR_WRONGDIRECTION) && !is_valid_nomotor(static_cast<det_class_label_t>(det_result.box.cls))) |
638 | 730 | continue; |
639 | 731 | |
640 | - if ((algor_type == algorithm_type_t::VEHICLE_WRONGDIRECTION || algor_type == algorithm_type_t::VEHICLE_NOTGIVEWAY) && !is_valid_car(static_cast<det_class_label_t>(det_result.box.cls))) | |
732 | + if ((algor_type == algorithm_type_t::VEHICLE_WRONGDIRECTION || algor_type == algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND || algor_type == algorithm_type_t::VEHICLE_NOTGIVEWAY) && !is_valid_car(static_cast<det_class_label_t>(det_result.box.cls))) | |
641 | 733 | continue; |
642 | 734 | |
643 | 735 | auto& e = id_to_mn_[obj_key]; |
... | ... | @@ -716,6 +808,32 @@ namespace ai_engine_module |
716 | 808 | if (!isalarm) continue; |
717 | 809 | } |
718 | 810 | |
811 | + // 机动车实线掉头 | |
812 | + if (algor_type == algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) { | |
813 | + bool isalarm = false; | |
814 | + int check_frames = 20; //4s 监控4s内的轨迹情况 | |
815 | + if (m_total_obj_info[trace_obj_key].center_points.size() > check_frames) { | |
816 | + jxline trace_line; | |
817 | + bool ret = find_traceStartEnd(m_total_obj_info[trace_obj_key].center_points, check_frames, trace_line); | |
818 | + if (ret) { | |
819 | + for (auto region : solidlines) { | |
820 | + vector<tr_point> tr_boxes = Mbuild_area(region); if (tr_boxes.size() < 2) continue; | |
821 | + for (int tmp_p = 0; tmp_p < tr_boxes.size() - 1; tmp_p++) { | |
822 | + jxline cur_line; | |
823 | + cur_line.xa = tr_boxes[tmp_p].x; cur_line.ya = tr_boxes[tmp_p].y; | |
824 | + cur_line.xb = tr_boxes[tmp_p + 1].x; cur_line.yb = tr_boxes[tmp_p + 1].y; | |
825 | + if (is_intersect(trace_line, cur_line)) { //压线 | |
826 | + bool cur_flag = vTurnAround(m_total_obj_info[trace_obj_key].center_points, check_frames);// 掉头 todo: 根据关键点判车头车尾朝向是否发生改变 | |
827 | + if (cur_flag) { isalarm = true; break; } | |
828 | + } | |
829 | + } | |
830 | + if (isalarm) break; | |
831 | + } | |
832 | + } | |
833 | + } | |
834 | + if (!isalarm) continue; | |
835 | + } | |
836 | + | |
719 | 837 | // 机动车不让行:针对人行道区域有行人,车辆不停车的情形 |
720 | 838 | if (algor_type == algorithm_type_t::VEHICLE_NOTGIVEWAY) { |
721 | 839 | bool isalarm = false; |
... | ... | @@ -748,7 +866,8 @@ namespace ai_engine_module |
748 | 866 | |
749 | 867 | { |
750 | 868 | if (++e.n_frame == algor_param->n || |
751 | - algor_type == algorithm_type_t::NONMOTOR_CEOSSPARKLINE || algor_type == algorithm_type_t::PERSON_CROSS ) //部分功能当前版本暂不投票 | |
869 | + algor_type == algorithm_type_t::NONMOTOR_CEOSSPARKLINE || algor_type == algorithm_type_t::PERSON_CROSS || | |
870 | + algor_type == algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND ) //部分功能当前版本暂不投票 | |
752 | 871 | { |
753 | 872 | results_data_t result; |
754 | 873 | { | ... | ... |
src/ai_engine_module/road_seg_correlation_algor.h
... | ... | @@ -36,7 +36,10 @@ namespace ai_engine_module |
36 | 36 | crosswalk = 5, //人行横道 |
37 | 37 | no_parking_area = 6, //禁停区域 |
38 | 38 | interestion_area = 7, //十字路口区域 |
39 | - // green_belt_area = 8, //绿化带区域 | |
39 | + yellow_solidline = 8, //黄实线 | |
40 | + white_solidline = 9, //白实线 | |
41 | + white_dottedline = 10, //虚线 | |
42 | + yellow_dottedline = 11, //黄虚线 | |
40 | 43 | }; |
41 | 44 | |
42 | 45 | enum class fence_label_t { |
... | ... | @@ -124,6 +127,39 @@ namespace ai_engine_module |
124 | 127 | std::map<id_t, mn_frame_t> id_to_mn_; |
125 | 128 | std::map<id_t, results_data_t> id_to_result_; |
126 | 129 | }; |
130 | + | |
131 | + class jxline | |
132 | + { | |
133 | + public: | |
134 | + int xa; | |
135 | + int ya; | |
136 | + int xb; | |
137 | + int yb; | |
138 | + jxline() {} | |
139 | + jxline(int xa, int ya, int xb, int yb) | |
140 | + { | |
141 | + this->xa = xa; | |
142 | + this->ya = ya; | |
143 | + this->xb = xb; | |
144 | + this->yb = yb; | |
145 | + } | |
146 | + int get_max_x() | |
147 | + { | |
148 | + return xa > xb ? xa : xb; | |
149 | + } | |
150 | + int get_min_x() | |
151 | + { | |
152 | + return xa > xb ? xb : xa; | |
153 | + } | |
154 | + int get_max_y() | |
155 | + { | |
156 | + return ya > yb ? ya : yb; | |
157 | + } | |
158 | + int get_min_y() | |
159 | + { | |
160 | + return ya > yb ? yb : ya; | |
161 | + } | |
162 | + }; | |
127 | 163 | } // namespace road_seg_correlation_process |
128 | 164 | } // namespace ai_engine_module |
129 | 165 | ... | ... |
src/ai_engine_module/road_seg_statistics.cpp
... | ... | @@ -215,7 +215,7 @@ cv::Mat RoadSegProcess::seg_post_process(bool large_resolution, unsigned char *s |
215 | 215 | for (int i = 0; i < lanes.size(); ++i) { |
216 | 216 | int thickness = 4; |
217 | 217 | for (int j = 0; j < lanes[i].size()-1; ++j) { |
218 | - cv::line(mask_rmlane, lanes[i][j], lanes[i][j+1], cats[i], thickness); | |
218 | + cv::line(mask_rmlane, lanes[i][j], lanes[i][j+1], {seg_colors[cats[i]][0],seg_colors[cats[i]][1],seg_colors[cats[i]][2]}, thickness); | |
219 | 219 | // std::cout << lanes[i][j] << " " << lanes[i][j+1] << " " << cats[i] << std::endl; |
220 | 220 | } |
221 | 221 | } | ... | ... |
src/ai_engine_module/road_seg_statistics.h
... | ... | @@ -77,7 +77,8 @@ private: |
77 | 77 | int seg_num_seg = 7; //道路分割种类(不包含背景) |
78 | 78 | int seg_min_region_area = 512; //1024 |
79 | 79 | float seg_min_lane_score = 0.35; //230625 |
80 | - uint8_t seg_colors[9][3] = { {0, 0, 0}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {0, 255, 128}, {128, 255, 255}, {255, 128, 255}, {255, 255, 128}, {60, 180, 0}}; | |
80 | + uint8_t seg_colors[13][3] = { {0, 0, 0}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {0, 255, 128}, {128, 255, 255}, {255, 128, 255}, {255, 255, 128}, {60, 180, 0}, {0, 60, 180}, | |
81 | + {0, 180, 60}, {60, 0, 180}, {180, 0, 60} }; | |
81 | 82 | uint8_t lane_colors[9][3] = { {0, 0, 0}, {255, 255, 0}, {255, 0, 255}, {0, 255, 255}, {128, 255, 0}, {255, 128, 0}, {128, 0, 255}, {255, 0, 128}, {0, 128, 255}}; |
82 | 83 | }; |
83 | 84 | ... | ... |
src/ai_platform/MultiSourceProcess.cpp
... | ... | @@ -1647,7 +1647,8 @@ void CMultiSourceProcess::algorithm_roadseg_correlation_process(vector<string>& |
1647 | 1647 | algor_map->find(algorithm_type_t::PERSON_CROSS) != algor_map->end() || |
1648 | 1648 | algor_map->find(algorithm_type_t::NONMOTOR_WRONGDIRECTION) != algor_map->end() || |
1649 | 1649 | algor_map->find(algorithm_type_t::VEHICLE_WRONGDIRECTION) != algor_map->end() || |
1650 | - algor_map->find(algorithm_type_t::VEHICLE_NOTGIVEWAY) != algor_map->end() | |
1650 | + algor_map->find(algorithm_type_t::VEHICLE_NOTGIVEWAY) != algor_map->end() || | |
1651 | + algor_map->find(algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND) != algor_map->end() | |
1651 | 1652 | ) { |
1652 | 1653 | |
1653 | 1654 | m_RoadSegTaskMtx.lock(); |
... | ... | @@ -1845,7 +1846,7 @@ void CMultiSourceProcess::village_snapshot(vector<string>& vpt_interest_task_id, |
1845 | 1846 | } |
1846 | 1847 | |
1847 | 1848 | vector<algo_type> roadseg_algor = {algorithm_type_t::PERSON_IN_VEHICLELANE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_IN_VEHICLELANE, algorithm_type_t::NONMOTOR_CEOSSPARKLINE, |
1848 | - algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY }; | |
1849 | + algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY, algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND }; | |
1849 | 1850 | for (size_t idx = 0; idx < roadseg_algor.size(); ++idx) { |
1850 | 1851 | if (algor_param[task_id].count(roadseg_algor.at(idx))) { |
1851 | 1852 | const auto &algor_other_params = task_other_params->find(roadseg_algor.at(idx)); | ... | ... |
src/ai_platform/task_param_manager.cpp
... | ... | @@ -88,6 +88,9 @@ bool copy_algor_param_aux(const algorithm_type_t &algor_type, const std::string |
88 | 88 | case algorithm_type_t::VEHICLE_NOTGIVEWAY: |
89 | 89 | m_algor_config_params[task_id].vehicle_algors.insert(algor_type); |
90 | 90 | goto _manned_param_copy; |
91 | + case algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND: | |
92 | + m_algor_config_params[task_id].vehicle_algors.insert(algor_type); | |
93 | + goto _manned_param_copy; | |
91 | 94 | case algorithm_type_t::TRUCK_MANNED: { |
92 | 95 | m_algor_config_params[task_id].vehicle_algors.insert(algor_type); |
93 | 96 | _manned_param_copy : { | ... | ... |
src/decoder/test_face.cpp renamed to src/decoder/test_face.cpp1
src/decoder/test_recoder.cpp
0 → 100644
1 | +#include "./interface/DecoderManager.h" | |
2 | +#include <mutex> | |
3 | +#include <thread> | |
4 | +#include <chrono> | |
5 | + | |
6 | +using namespace std; | |
7 | + | |
8 | +struct decode_cbk_userdata{ | |
9 | + string task_id; | |
10 | + void* opaque; | |
11 | + void* opaque1; | |
12 | +}; | |
13 | + | |
14 | +deque<DeviceMemory*> m_RgbDataList; | |
15 | +mutex m_DataListMtx; | |
16 | + | |
17 | +thread* m_pAlgorthimThread{nullptr}; | |
18 | +thread* m_recodeThread{nullptr}; | |
19 | +bool m_bfinish{false}; | |
20 | +int m_devId = 0; | |
21 | +const char* task_id = "test0"; | |
22 | +int skip_frame_ = 5; | |
23 | +int m_batch_size = 20; | |
24 | + | |
25 | +deque<RecoderInfo> m_recoderinfo_queue; | |
26 | +mutex m_recoderinfo_queue_mtx; | |
27 | + | |
28 | +void algorthim_process_thread(); | |
29 | +void recode_thread(); | |
30 | +void algorthim_face_detect(vector<DeviceMemory*> vec_gpuMem); | |
31 | + | |
32 | +void test_recode_thread(); | |
33 | + | |
34 | +void post_decod_cbk(const void * userPtr, DeviceMemory* devFrame){ | |
35 | + do{ | |
36 | + if(m_bfinish){ | |
37 | + break; | |
38 | + } | |
39 | + m_DataListMtx.lock(); | |
40 | + if(m_RgbDataList.size() >= 30){ | |
41 | + m_DataListMtx.unlock(); | |
42 | + std::this_thread::sleep_for(std::chrono::milliseconds(3)); | |
43 | + continue; | |
44 | + } | |
45 | + m_RgbDataList.push_back(devFrame); | |
46 | + m_DataListMtx.unlock(); | |
47 | + break; | |
48 | + }while (true); | |
49 | +} | |
50 | + | |
51 | +void decode_finished_cbk(const void * userPtr){ | |
52 | + decode_cbk_userdata* ptr = (decode_cbk_userdata*)userPtr; | |
53 | + if (ptr!= nullptr){ | |
54 | + printf("task finished: %s \n", ptr->task_id.c_str()); | |
55 | + } | |
56 | + delete ptr; | |
57 | + ptr = nullptr; | |
58 | +} | |
59 | + | |
60 | +int main(){ | |
61 | + | |
62 | + // 创建解码任务 | |
63 | + DecoderManager* pDecManager = DecoderManager::getInstance(); | |
64 | + | |
65 | + MgrDecConfig config; | |
66 | + config.name = task_id; | |
67 | + config.cfg.uri = "/opt/cmhu/data/公安局老桥头_CVR15F89410_1465819864_1B.mp4"; | |
68 | + config.cfg.post_decoded_cbk = post_decod_cbk; | |
69 | + config.cfg.decode_finished_cbk = decode_finished_cbk; | |
70 | + config.cfg.force_tcp = true; // rtsp用tcp | |
71 | + config.cfg.gpuid = to_string(m_devId); | |
72 | + config.cfg.skip_frame = skip_frame_; | |
73 | + | |
74 | + config.dec_type = DECODER_TYPE_DVPP; | |
75 | + | |
76 | + AbstractDecoder* dec = pDecManager->createDecoder(config); | |
77 | + if (!dec){ | |
78 | + printf("创建解码器失败 \n"); | |
79 | + return false; | |
80 | + } | |
81 | + | |
82 | + decode_cbk_userdata* userPtr = new decode_cbk_userdata; | |
83 | + userPtr->task_id = string(task_id); | |
84 | + pDecManager->setPostDecArg(config.name, userPtr); | |
85 | + pDecManager->setFinishedDecArg(config.name, userPtr); | |
86 | + | |
87 | + | |
88 | + int input_image_width = 0; | |
89 | + int input_image_height = 0; | |
90 | + pDecManager->getResolution(config.name, input_image_width, input_image_height); | |
91 | + | |
92 | + | |
93 | + // 创建算法线程 | |
94 | + m_pAlgorthimThread = new thread([](void* arg) { | |
95 | + algorthim_process_thread(); | |
96 | + return (void*)0; | |
97 | + } | |
98 | + , nullptr); | |
99 | + | |
100 | + // m_recodeThread = new thread([](void* arg) { | |
101 | + // recode_thread(); | |
102 | + // return (void*)0; | |
103 | + // } | |
104 | + // , nullptr); | |
105 | + | |
106 | + m_recodeThread = new thread([](void* arg) { | |
107 | + test_recode_thread(); | |
108 | + return (void*)0; | |
109 | + } | |
110 | + , nullptr); | |
111 | + | |
112 | + pDecManager->startDecodeByName(config.name); | |
113 | + | |
114 | + while (getchar() != 'q'); | |
115 | +} | |
116 | + | |
117 | +void algorthim_process_thread(){ | |
118 | + | |
119 | + while (true){ | |
120 | + if(m_bfinish){ | |
121 | + break; | |
122 | + } | |
123 | + | |
124 | + vector<DeviceMemory*> vec_gpuMem; | |
125 | + m_DataListMtx.lock(); | |
126 | + while (!m_RgbDataList.empty()){ | |
127 | + DeviceMemory* gpuMem = m_RgbDataList.front(); | |
128 | + if(gpuMem->getMem() == nullptr){ | |
129 | + // 错误数据,直接删除 | |
130 | + delete gpuMem; | |
131 | + gpuMem = nullptr; | |
132 | + printf("mem is null \n"); | |
133 | + } else { | |
134 | + vec_gpuMem.push_back(gpuMem); | |
135 | + } | |
136 | + m_RgbDataList.pop_front(); | |
137 | + if(vec_gpuMem.size() >= m_batch_size){ | |
138 | + break; | |
139 | + } | |
140 | + } | |
141 | + m_DataListMtx.unlock(); | |
142 | + | |
143 | + if(vec_gpuMem.size() <= 0){ | |
144 | + std::this_thread::sleep_for(std::chrono::milliseconds(3)); | |
145 | + continue; | |
146 | + } | |
147 | + | |
148 | + algorthim_face_detect(vec_gpuMem); | |
149 | + | |
150 | + for(int i=0;i < vec_gpuMem.size(); i++){ | |
151 | + DeviceMemory* mem = vec_gpuMem[i]; | |
152 | + if(mem->getSize() <= 0){ | |
153 | + continue; | |
154 | + } | |
155 | + delete mem; | |
156 | + mem = nullptr; | |
157 | + } | |
158 | + vec_gpuMem.clear(); | |
159 | + | |
160 | + } | |
161 | + | |
162 | + printf("algorthim_process_thread exit. \n"); | |
163 | +} | |
164 | + | |
165 | +static int interval = 0; | |
166 | +static int obj_id = 0; | |
167 | + | |
168 | +void algorthim_face_detect(vector<DeviceMemory*> vec_gpuMem) { | |
169 | + interval ++ ; | |
170 | + | |
171 | + if(interval % 50 != 0) { | |
172 | + return; | |
173 | + } | |
174 | + | |
175 | + for(int i= 0; i < vec_gpuMem.size(); i++) { | |
176 | + DeviceMemory* mem = vec_gpuMem[i]; | |
177 | + string task_id = mem->getId(); | |
178 | + | |
179 | + RecoderInfo recoderInfo; | |
180 | + recoderInfo.task_id = task_id; | |
181 | + recoderInfo.object_id = std::to_string(obj_id); | |
182 | + recoderInfo.recoderPath = "./res/recode"; | |
183 | + recoderInfo.frame_nb = mem->getFrameNb(); | |
184 | + | |
185 | + m_recoderinfo_queue_mtx.lock(); | |
186 | + m_recoderinfo_queue.push_back(recoderInfo); | |
187 | + m_recoderinfo_queue_mtx.unlock(); | |
188 | + | |
189 | + obj_id++; | |
190 | + | |
191 | + } | |
192 | +} | |
193 | + | |
194 | +void test_recode_thread() { | |
195 | + unsigned long long frame_index = 0; | |
196 | + while(true) { | |
197 | + std::this_thread::sleep_for(std::chrono::milliseconds(10)); | |
198 | + | |
199 | + DeviceMemory* mem = nullptr; | |
200 | + m_DataListMtx.lock(); | |
201 | + while (!m_RgbDataList.empty()){ | |
202 | + DeviceMemory* gpuMem = m_RgbDataList.front(); | |
203 | + if(gpuMem->getMem() == nullptr){ | |
204 | + // 错误数据,直接删除 | |
205 | + delete gpuMem; | |
206 | + gpuMem = nullptr; | |
207 | + printf("mem is null \n"); | |
208 | + } else { | |
209 | + frame_index ++ ; | |
210 | + if (frame_index % 50 == 0) { | |
211 | + RecoderInfo recoderInfo; | |
212 | + recoderInfo.task_id = gpuMem->getId(); | |
213 | + recoderInfo.object_id = std::to_string(obj_id); | |
214 | + recoderInfo.recoderPath = "./res/recode"; | |
215 | + recoderInfo.frame_nb = gpuMem->getFrameNb(); | |
216 | + | |
217 | + DecoderManager* pDecManager = DecoderManager::getInstance(); | |
218 | + pDecManager->doRecode(recoderInfo); | |
219 | + | |
220 | + obj_id++; | |
221 | + } | |
222 | + delete gpuMem; | |
223 | + gpuMem = nullptr; | |
224 | + } | |
225 | + m_RgbDataList.pop_front(); | |
226 | + } | |
227 | + m_DataListMtx.unlock(); | |
228 | + } | |
229 | +} | |
230 | + | |
231 | +void recode_thread() { | |
232 | + while(true) { | |
233 | + | |
234 | + m_recoderinfo_queue_mtx.lock(); | |
235 | + if(m_recoderinfo_queue.size() <= 0) { | |
236 | + m_recoderinfo_queue_mtx.unlock(); | |
237 | + std::this_thread::sleep_for(std::chrono::milliseconds(5)); | |
238 | + continue; | |
239 | + } | |
240 | + | |
241 | + RecoderInfo info = m_recoderinfo_queue.front(); | |
242 | + m_recoderinfo_queue.pop_front(); | |
243 | + m_recoderinfo_queue_mtx.unlock(); | |
244 | + | |
245 | + DecoderManager* pDecManager = DecoderManager::getInstance(); | |
246 | + pDecManager->doRecode(info); | |
247 | + } | |
248 | +} | |
0 | 249 | \ No newline at end of file | ... | ... |
src/demo/demo.cpp
... | ... | @@ -396,6 +396,27 @@ void set_task_params(task_param &tparam, const unsigned &idx, const algorithm_ty |
396 | 396 | algor_init_params->basic_param = basic_params; |
397 | 397 | } break; |
398 | 398 | |
399 | + case algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND: { | |
400 | + auto algor_params = new algor_config_param_manned_incident; | |
401 | + { | |
402 | + algor_params->m = 10; | |
403 | + algor_params->n = 8; | |
404 | + algor_params->obj_confidence_threshold = 0.5f; | |
405 | + algor_params->obj_min_height = 40; | |
406 | + algor_params->obj_min_width = 40; | |
407 | + } | |
408 | + | |
409 | + auto basic_params = new algor_basic_config_param_t; | |
410 | + { | |
411 | + basic_params->video_folder = "res/video_recode"; | |
412 | + basic_params->result_folder = "res/vehicle_solid_turnaround"; | |
413 | + basic_params->result_folder_little = "res/vehicle_solid_turnaround_little"; | |
414 | + } | |
415 | + | |
416 | + algor_init_params->algor_param = algor_params; | |
417 | + algor_init_params->basic_param = basic_params; | |
418 | + } break; | |
419 | + | |
399 | 420 | |
400 | 421 | case algorithm_type_t::FACE_SNAPSHOT: { |
401 | 422 | auto basic_params = new algor_basic_config_param_t; |
... | ... | @@ -1037,11 +1058,10 @@ void test_gpu(int gpuID){ |
1037 | 1058 | |
1038 | 1059 | 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, |
1039 | 1060 | algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS, algorithm_type_t::PERSON_IN_VEHICLELANE, algorithm_type_t::NONMOTOR_IN_VEHICLELANE, |
1040 | - algorithm_type_t::NONMOTOR_CEOSSPARKLINE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY}; | |
1041 | - std::vector<algorithm_type_t> algor_vec3 = {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, | |
1042 | - algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS}; | |
1043 | - // std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::NONMOTOR_VEHICLE_NOHELMET, algorithm_type_t::NONMOTOR_VEHICLE_OVERMAN, algorithm_type_t::TRICYCLE_MANNED, algorithm_type_t::NONMOTOR_VEHICLE_USEPHONE, | |
1044 | - // algorithm_type_t::NONMOTOR_VEHICLE_REFIT}; | |
1061 | + algorithm_type_t::NONMOTOR_CEOSSPARKLINE, algorithm_type_t::PERSON_CROSS, algorithm_type_t::NONMOTOR_WRONGDIRECTION, algorithm_type_t::VEHICLE_WRONGDIRECTION, algorithm_type_t::VEHICLE_NOTGIVEWAY, algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND}; | |
1062 | + // std::vector<algorithm_type_t> algor_vec3 = {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, | |
1063 | + // algorithm_type_t::NONMOTOR_VEHICLE_REFIT, algorithm_type_t::PERSON_RUNNING_REDLIGHTS, algorithm_type_t::NONMOTOR_RUNNING_REDLIGHTS}; | |
1064 | + std::vector<algorithm_type_t> algor_vec3 = {algorithm_type_t::VEHICLE_SOLIDLINETURNAROUND}; | |
1045 | 1065 | |
1046 | 1066 | /* |
1047 | 1067 | int repeat_num = 1000; |
... | ... | @@ -1063,18 +1083,18 @@ void test_gpu(int gpuID){ |
1063 | 1083 | // createTask(handle, algor_vec, 1); |
1064 | 1084 | // createTask(handle, algor_vec, 2); |
1065 | 1085 | // createTask(handle, algor_vec, 3); |
1066 | - // createTask(handle, algor_vec3, 4); | |
1067 | - createTask(handle, algor_vec2, 5); | |
1068 | - createTask(handle, algor_vec2, 6); | |
1069 | - createTask(handle, algor_vec2, 7); | |
1070 | - createTask(handle, algor_vec2, 8); | |
1071 | - createTask(handle, algor_vec2, 9); | |
1072 | - createTask(handle, algor_vec2, 10); | |
1073 | - createTask(handle, algor_vec2, 11); | |
1074 | - createTask(handle, algor_vec2, 12); | |
1075 | - createTask(handle, algor_vec2, 13); | |
1076 | - createTask(handle, algor_vec2, 14); | |
1077 | - createTask(handle, algor_vec2, 15); | |
1086 | + createTask(handle, algor_vec3, 4); | |
1087 | + createTask(handle, algor_vec3, 5); | |
1088 | + createTask(handle, algor_vec3, 6); | |
1089 | + createTask(handle, algor_vec3, 7); | |
1090 | + createTask(handle, algor_vec3, 8); | |
1091 | + createTask(handle, algor_vec3, 9); | |
1092 | + createTask(handle, algor_vec3, 10); | |
1093 | + // createTask(handle, algor_vec3, 11); | |
1094 | + // createTask(handle, algor_vec3, 12); | |
1095 | + // createTask(handle, algor_vec3, 13); | |
1096 | + // createTask(handle, algor_vec3, 14); | |
1097 | + // createTask(handle, algor_vec3, 15); | |
1078 | 1098 | // createTask(handle, algor_vec2, 16); |
1079 | 1099 | // createTask(handle, algor_vec2, 17); |
1080 | 1100 | // createTask(handle, algor_vec2, 18); | ... | ... |