Commit 581a68a4b0aa1e76c84194edf2fdcd61b0d49766
1 parent
8d319775
修正parse_road无返回值导致崩溃的问题;
返回值中sy_point更换为cv::Point; 优化model_path
Showing
21 changed files
with
114 additions
and
1027 deletions
jni/VehicleNativeInterface.cpp
... | ... | @@ -126,28 +126,22 @@ JNIEXPORT jint JNICALL Java_com_objecteye_nativeinterface_vehicle_VehicleNativeI |
126 | 126 | //�㷨���ò��� |
127 | 127 | jclass cls_vehcileAnalysisParam = env->GetObjectClass(vehicleAnalysisParam); |
128 | 128 | |
129 | - jfieldID fid_dbpath = env->GetFieldID(cls_vehcileAnalysisParam, "dbPath", "Ljava/lang/String;"); | |
130 | - jfieldID fid_modelspath = env->GetFieldID(cls_vehcileAnalysisParam, "modelsPath", "Ljava/lang/String;"); | |
129 | + jfieldID fid_sdk_path = env->GetFieldID(cls_vehcileAnalysisParam, "sdk_path", "Ljava/lang/String;"); | |
131 | 130 | jfieldID fid_gpuid = env->GetFieldID(cls_vehcileAnalysisParam, "gpuId", "I"); |
132 | 131 | |
133 | - jstring str_dbpath = (jstring)env->GetObjectField(vehicleAnalysisParam, fid_dbpath); | |
134 | - const char *dbpath = env->GetStringUTFChars(str_dbpath, JNI_FALSE); | |
135 | - jstring str_modlespath = (jstring)env->GetObjectField(vehicleAnalysisParam, fid_modelspath); | |
136 | - const char *models_path = env->GetStringUTFChars(str_modlespath, JNI_FALSE); | |
132 | + jstring str_sdk_path = (jstring)env->GetObjectField(vehicleAnalysisParam, fid_sdk_path); | |
133 | + const char *sdk_path = env->GetStringUTFChars(str_sdk_path, JNI_FALSE); | |
137 | 134 | jint gpuid = env->GetIntField(vehicleAnalysisParam, fid_gpuid); |
138 | 135 | |
139 | 136 | void *vaHandle = NULL; |
140 | 137 | VillageParam param; |
141 | 138 | param.dev_id = gpuid; |
142 | - param.db_path = dbpath; | |
143 | - param.model_path = models_path; | |
139 | + param.sdk_path = sdk_path; | |
144 | 140 | int ret = village_pic_init(&vaHandle, param); |
145 | - if (ret != SUCCESS) | |
146 | - { | |
141 | + if (ret != SUCCESS) { | |
147 | 142 | printf("jni info:va_init failed."); |
148 | 143 | return ret; |
149 | 144 | } |
150 | - | |
151 | 145 | |
152 | 146 | if (ret == SUCCESS) |
153 | 147 | { |
... | ... | @@ -166,8 +160,7 @@ JNIEXPORT jint JNICALL Java_com_objecteye_nativeinterface_vehicle_VehicleNativeI |
166 | 160 | temp[0] = (jlong)vaHandle; |
167 | 161 | env->SetLongArrayRegion(handle, 0, 1, temp); |
168 | 162 | } |
169 | - env->ReleaseStringUTFChars(str_dbpath, dbpath); | |
170 | - env->ReleaseStringUTFChars(str_modlespath, models_path); | |
163 | + env->ReleaseStringUTFChars(str_sdk_path, sdk_path); | |
171 | 164 | return ret; |
172 | 165 | } |
173 | 166 | |
... | ... | @@ -564,7 +557,7 @@ JNIEXPORT jint JNICALL Java_com_objecteye_nativeinterface_vehicle_VehicleNativeI |
564 | 557 | for (int k = 0; k < line_info.vec_pt.size(); k++) |
565 | 558 | { |
566 | 559 | auto pt = line_info.vec_pt[k]; |
567 | - jobject line_info_point = env->NewObject(cls_SyPoint, mid_SyPoint, pt.x_, pt.y_); | |
560 | + jobject line_info_point = env->NewObject(cls_SyPoint, mid_SyPoint, pt.x, pt.y); | |
568 | 561 | env->SetObjectArrayElement(ptArray, k, line_info_point); |
569 | 562 | } |
570 | 563 | |
... | ... | @@ -584,7 +577,7 @@ JNIEXPORT jint JNICALL Java_com_objecteye_nativeinterface_vehicle_VehicleNativeI |
584 | 577 | for (int k = 0; k < road_info.vec_pt.size(); k++) |
585 | 578 | { |
586 | 579 | auto pt = road_info.vec_pt[k]; |
587 | - jobject road_info_point = env->NewObject(cls_SyPoint, mid_SyPoint, pt.x_, pt.y_); | |
580 | + jobject road_info_point = env->NewObject(cls_SyPoint, mid_SyPoint, pt.x, pt.y); | |
588 | 581 | env->SetObjectArrayElement(ptArray, k, road_info_point); |
589 | 582 | } |
590 | 583 | ... | ... |
src/PicAnalysis.cpp
... | ... | @@ -19,7 +19,7 @@ int PicAnalysis::init(VillageParam param) { |
19 | 19 | |
20 | 20 | int ret = SY_FAILED; |
21 | 21 | |
22 | - ret = m_vehicle_analysis.init(dev_id, 16); | |
22 | + ret = m_vehicle_analysis.init(dev_id, param.sdk_path, 16); | |
23 | 23 | if(0 != ret){ |
24 | 24 | return -1; |
25 | 25 | } |
... | ... | @@ -27,37 +27,38 @@ int PicAnalysis::init(VillageParam param) { |
27 | 27 | // head_tail_param ht_param; |
28 | 28 | // ht_param.devId = dev_id; |
29 | 29 | // ht_param.max_batch = 16; |
30 | + // ht_param.sdk_path = param.sdk_path; | |
30 | 31 | // ret = m_head_tail_algorithm.init(ht_param); |
31 | 32 | // if(0 != ret){ |
32 | 33 | // return -1; |
33 | 34 | // } |
34 | 35 | |
35 | - ret = m_clothes_algorithm.init(dev_id); | |
36 | + ret = m_clothes_algorithm.init(dev_id, param.sdk_path); | |
36 | 37 | if(0 != ret){ |
37 | 38 | return -1; |
38 | 39 | } |
39 | 40 | |
40 | - ret = m_human_algorithm.init(dev_id); | |
41 | + ret = m_human_algorithm.init(dev_id, param.sdk_path); | |
41 | 42 | if(0 != ret){ |
42 | 43 | return -1; |
43 | 44 | } |
44 | 45 | |
45 | - ret = m_human_car_algorithm.init(dev_id); | |
46 | + ret = m_human_car_algorithm.init(dev_id, param.sdk_path); | |
46 | 47 | if(0 != ret){ |
47 | 48 | return -1; |
48 | 49 | } |
49 | 50 | |
50 | - ret = m_motor_rainshed_algorithm.init(dev_id); | |
51 | + ret = m_motor_rainshed_algorithm.init(dev_id, param.sdk_path); | |
51 | 52 | if(0 != ret){ |
52 | 53 | return -1; |
53 | 54 | } |
54 | 55 | |
55 | - ret = m_motor_phone_algorithm.init(dev_id); | |
56 | + ret = m_motor_phone_algorithm.init(dev_id, param.sdk_path); | |
56 | 57 | if(0 != ret){ |
57 | 58 | return -1; |
58 | 59 | } |
59 | 60 | |
60 | - ret = m_road_seg_algorithm.init(dev_id); | |
61 | + ret = m_road_seg_algorithm.init(dev_id, param.sdk_path); | |
61 | 62 | if(0 != ret){ |
62 | 63 | return -1; |
63 | 64 | } |
... | ... | @@ -356,9 +357,9 @@ vector<AnalysisResult> PicAnalysis::analysis_img(vector<sy_img> vec_img){ |
356 | 357 | } |
357 | 358 | |
358 | 359 | //压黄实线 |
359 | - result_info.cross_line = m_road_seg_algorithm.check_cross_line(road_info.vec_line, vehicle_rect); | |
360 | + result_info.cross_line = m_road_seg_algorithm.check_cross_line(road_info.vec_line, vehicle_rect, src.width, src.height); | |
360 | 361 | // 压导流线 |
361 | - result_info.cross_diversion_line = m_road_seg_algorithm.check_cross_region(road_info.vec_road, vehicle_rect, 3); //3是导流线区域 | |
362 | + result_info.cross_diversion_line = m_road_seg_algorithm.check_cross_region(road_info.vec_road, vehicle_rect, src.width, src.height, 3); //3是导流线区域 | |
362 | 363 | } |
363 | 364 | } |
364 | 365 | ... | ... |
src/ai_engine_module/HumanAnalysis.cpp
... | ... | @@ -11,12 +11,14 @@ HumanAnalysis::~HumanAnalysis() |
11 | 11 | release(); |
12 | 12 | } |
13 | 13 | |
14 | -int HumanAnalysis::init(int devId){ | |
14 | +int HumanAnalysis::init(int devId, std::string sdk_root){ | |
15 | 15 | ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED); |
16 | 16 | ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED); |
17 | 17 | |
18 | + std::string model_path = sdk_root + "/models/hp/hp220908_310p.om"; | |
19 | + | |
18 | 20 | hp_param param; |
19 | - param.modelNames = "./models/hp/hp220908_310p.om"; | |
21 | + param.modelNames = (char*)model_path.data(); | |
20 | 22 | param.devId = devId; |
21 | 23 | |
22 | 24 | cout << "hp_init start " << endl; | ... | ... |
src/ai_engine_module/HumanAnalysis.h
src/ai_engine_module/HumanCarAnalysis.cpp
... | ... | @@ -13,12 +13,14 @@ HumanCarAnalysis::~HumanCarAnalysis() |
13 | 13 | release(); |
14 | 14 | } |
15 | 15 | |
16 | -int HumanCarAnalysis::init(int devId){ | |
16 | +int HumanCarAnalysis::init(int devId, std::string sdk_root){ | |
17 | 17 | ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED); |
18 | 18 | ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED); |
19 | 19 | |
20 | + std::string model_path = sdk_root + "/models/hcp/hcp211008_310p.om"; | |
21 | + | |
20 | 22 | hcp_param param; |
21 | - param.modelNames = "./models/hcp/hcp211008_310p.om"; | |
23 | + param.modelNames = (char*)model_path.data(); | |
22 | 24 | param.devId = devId; |
23 | 25 | |
24 | 26 | cout << "hcp_init start " << endl; | ... | ... |
src/ai_engine_module/HumanCarAnalysis.h
src/ai_engine_module/MotorPhoneAnalysis.cpp
... | ... | @@ -10,11 +10,13 @@ MotorPhoneAnalysis::~MotorPhoneAnalysis() |
10 | 10 | release(); |
11 | 11 | } |
12 | 12 | |
13 | -int MotorPhoneAnalysis::init(int devId){ | |
13 | +int MotorPhoneAnalysis::init(int devId, std::string sdk_root){ | |
14 | 14 | ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED); |
15 | 15 | |
16 | + std::string model_path = sdk_root + "/models/motor_phone/motor_phone1127_310p.om"; | |
17 | + | |
16 | 18 | motor_phone_param param; |
17 | - param.modelNames = "./models/motor_phone/motor_phone1127_310p.om"; | |
19 | + param.modelNames = (char*)model_path.data(); | |
18 | 20 | param.thresld = 0.25; |
19 | 21 | param.devId = devId; |
20 | 22 | ... | ... |
src/ai_engine_module/MotorPhoneAnalysis.h
src/ai_engine_module/MotorRainshedAnalysis.cpp
... | ... | @@ -10,11 +10,13 @@ MotorRainshedAnalysis::~MotorRainshedAnalysis() |
10 | 10 | release(); |
11 | 11 | } |
12 | 12 | |
13 | -int MotorRainshedAnalysis::init(int devId){ | |
13 | +int MotorRainshedAnalysis::init(int devId, std::string sdk_root){ | |
14 | 14 | ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED); |
15 | 15 | |
16 | + std::string model_path = sdk_root + "/models/rainshed/motor_rainshed_231123_310p.om"; | |
17 | + | |
16 | 18 | mrc_param param; |
17 | - param.modelNames = "./models/rainshed/motor_rainshed_231123_310p.om"; | |
19 | + param.modelNames = (char*)model_path.data(); | |
18 | 20 | param.thresld = 0.0; |
19 | 21 | param.devId = devId; |
20 | 22 | ... | ... |
src/ai_engine_module/MotorRainshedAnalysis.h
src/ai_engine_module/RoadSegAnalysis.cpp
... | ... | @@ -12,11 +12,13 @@ RoadSegAnalysis::~RoadSegAnalysis() |
12 | 12 | release(); |
13 | 13 | } |
14 | 14 | |
15 | -int RoadSegAnalysis::init(int devId){ | |
15 | +int RoadSegAnalysis::init(int devId, std::string sdk_root){ | |
16 | 16 | ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED); |
17 | 17 | |
18 | + std::string model_path = sdk_root + "/models/road_seg/tzroad_seg240108_310p.om"; | |
19 | + | |
18 | 20 | rs_param param; |
19 | - param.modelNames = "./models/road_seg/tzroad_seg240108_310p.om"; | |
21 | + param.modelNames = (char*)model_path.data(); | |
20 | 22 | param.thresld = 0.25; |
21 | 23 | param.devId = devId; |
22 | 24 | |
... | ... | @@ -93,33 +95,20 @@ RoadInfo RoadSegAnalysis::parse_road(rs_result one_result, sy_img src) |
93 | 95 | cv::Mat seg_output = seg_post_process(large_resolution, one_result.seg_array, combined, poly_masks, region_classes, lanes, cats, x_sort); //m_masks:mask前的结果 poly_masks后的结果 |
94 | 96 | |
95 | 97 | for (int i = 0; i < lanes.size(); ++i) { |
96 | - std::vector<cv::Point> points = lanes[i]; | |
97 | 98 | LineInfo info; |
98 | - for (size_t j = 0; j < points.size(); j++) | |
99 | - { | |
100 | - sy_point pt; | |
101 | - pt.x_ = points[j].x; | |
102 | - pt.y_ = points[j].y; | |
103 | - | |
104 | - info.vec_pt.push_back(pt); | |
105 | - } | |
99 | + info.vec_pt = lanes[i]; | |
106 | 100 | info.line_type = cats[i]; |
107 | 101 | one_road.vec_line.push_back(info); |
108 | 102 | } |
109 | 103 | |
110 | 104 | for (int i = 0; i < poly_masks.size(); ++i) { |
111 | - std::vector<cv::Point> points = poly_masks[i]; | |
112 | 105 | SegInfo seg_info; |
113 | - for (int j = 0; j < points.size(); ++j) { | |
114 | - sy_point pt; | |
115 | - pt.x_ = points[j].x; | |
116 | - pt.y_ = points[j].y; | |
117 | - | |
118 | - seg_info.vec_pt.push_back(pt); | |
119 | - } | |
106 | + seg_info.vec_pt = poly_masks[i]; | |
120 | 107 | seg_info.seg_type = region_classes[i]; |
121 | 108 | one_road.vec_road.push_back(seg_info); |
122 | 109 | } |
110 | + | |
111 | + return one_road; | |
123 | 112 | } |
124 | 113 | |
125 | 114 | std::vector<SegInfo> RoadSegAnalysis::parse_direct(rs_result one_result, sy_img src) { |
... | ... | @@ -133,21 +122,26 @@ std::vector<SegInfo> RoadSegAnalysis::parse_direct(rs_result one_result, sy_img |
133 | 122 | |
134 | 123 | cv::Mat seg_output = seg_post_process(large_resolution, one_result.direct_seg, combined, poly_masks, region_classes, lanes, cats, x_sort); //m_masks:mask前的结果 poly_masks后的结果 |
135 | 124 | |
125 | + | |
126 | + cv::Mat image(cv::Size(640, 360), CV_8UC3, cv::Scalar(0, 0, 0)); | |
127 | + | |
136 | 128 | std::vector<SegInfo> vec_road; |
137 | 129 | for (int i = 0; i < poly_masks.size(); ++i) { |
138 | - std::vector<cv::Point> points = poly_masks[i]; | |
139 | 130 | SegInfo seg_info; |
140 | - for (int j = 0; j < points.size(); ++j) { | |
141 | - sy_point pt; | |
142 | - pt.x_ = points[j].x; | |
143 | - pt.y_ = points[j].y; | |
144 | - | |
145 | - seg_info.vec_pt.push_back(pt); | |
146 | - } | |
147 | 131 | seg_info.seg_type = region_classes[i]; |
132 | + seg_info.vec_pt = poly_masks[i]; | |
133 | + | |
134 | + int k = seg_info.seg_type; | |
135 | + const cv::Scalar color(seg_colors[k][0], seg_colors[k][1], seg_colors[k][2]); | |
136 | + | |
137 | + polylines(image, seg_info.vec_pt, true, color, 3, cv::LINE_AA); | |
138 | + | |
148 | 139 | vec_road.push_back(seg_info); |
149 | 140 | } |
150 | 141 | |
142 | + cv::imwrite("./direct.jpg", image); | |
143 | + image.release(); | |
144 | + | |
151 | 145 | return vec_road; |
152 | 146 | } |
153 | 147 | |
... | ... | @@ -202,17 +196,15 @@ int RoadSegAnalysis::check_reverse_driving(std::vector<SegInfo>& vec_direct, sy_ |
202 | 196 | for (size_t i = 0; i < vec_direct.size(); i++) { |
203 | 197 | SegInfo& region = vec_direct[i]; |
204 | 198 | if (region.seg_type == 1) { |
205 | - std::vector<cv::Point> vec_pt; | |
206 | - for (size_t j = 0; j < region.vec_pt.size(); j++) { | |
207 | - double dist = pointPolygonTest(polygon_pts, cv::Point2f(region.vec_pt[j].x_, region.vec_pt[j].y_), false); | |
199 | + for (size_t j = 0; j < polygon_pts.size(); j++) { | |
200 | + double dist = pointPolygonTest(region.vec_pt, polygon_pts[j], false); | |
208 | 201 | if (dist > 0) { |
209 | 202 | coming_count ++; |
210 | 203 | } |
211 | 204 | } |
212 | 205 | } else if (region.seg_type == 2) { |
213 | - std::vector<cv::Point> vec_pt; | |
214 | - for (size_t j = 0; j < region.vec_pt.size(); j++) { | |
215 | - double dist = pointPolygonTest(polygon_pts, cv::Point2f(region.vec_pt[j].x_, region.vec_pt[j].y_), false); | |
206 | + for (size_t j = 0; j < polygon_pts.size(); j++) { | |
207 | + double dist = pointPolygonTest(region.vec_pt, polygon_pts[j], false); | |
216 | 208 | if (dist > 0) { |
217 | 209 | leaving_count ++; |
218 | 210 | } |
... | ... | @@ -259,10 +251,10 @@ int RoadSegAnalysis::check_reverse_driving(std::vector<SegInfo>& vec_direct, sy_ |
259 | 251 | return -1; |
260 | 252 | } |
261 | 253 | |
262 | -int RoadSegAnalysis::check_cross_line(std::vector<LineInfo>& vec_line, sy_rect src_rc) { | |
254 | +int RoadSegAnalysis::check_cross_line(std::vector<LineInfo>& vec_line, sy_rect src_rc, int src_width, int src_height) { | |
263 | 255 | |
264 | - float scale_w = 640.0 / src_rc.width_; | |
265 | - float scale_h = 360.0 / src_rc.height_; | |
256 | + float scale_w = 640.0 / src_width; | |
257 | + float scale_h = 360.0 / src_height; | |
266 | 258 | |
267 | 259 | sy_rect rc; |
268 | 260 | rc.left_ = src_rc.left_ * scale_w; |
... | ... | @@ -294,9 +286,8 @@ int RoadSegAnalysis::check_cross_line(std::vector<LineInfo>& vec_line, sy_rect s |
294 | 286 | if (line.line_type == 1 || line.line_type == 2) { |
295 | 287 | // 黄实线 |
296 | 288 | int in_count = 0; |
297 | - std::vector<cv::Point> vec_pt; | |
298 | 289 | for (size_t j = 0; j < line.vec_pt.size(); j++) { |
299 | - double dist = pointPolygonTest(polygon_pts, cv::Point2f(line.vec_pt[j].x_, line.vec_pt[j].y_), false); | |
290 | + double dist = pointPolygonTest(polygon_pts, line.vec_pt[j], false); | |
300 | 291 | if (dist > 0) { |
301 | 292 | in_count ++; |
302 | 293 | } |
... | ... | @@ -312,7 +303,16 @@ int RoadSegAnalysis::check_cross_line(std::vector<LineInfo>& vec_line, sy_rect s |
312 | 303 | return -1; |
313 | 304 | } |
314 | 305 | |
315 | -int RoadSegAnalysis::check_cross_region(std::vector<SegInfo>& vec_reg, sy_rect rc, int region_type) { | |
306 | +int RoadSegAnalysis::check_cross_region(std::vector<SegInfo>& vec_reg, sy_rect src_rc, int src_width, int src_height, int region_type) { | |
307 | + | |
308 | + float scale_w = 640.0 / src_width; | |
309 | + float scale_h = 360.0 / src_height; | |
310 | + | |
311 | + sy_rect rc; | |
312 | + rc.left_ = src_rc.left_ * scale_w; | |
313 | + rc.width_ = src_rc.width_ * scale_w; | |
314 | + rc.top_ = src_rc.top_ * scale_h; | |
315 | + rc.height_ = src_rc.height_ * scale_h; | |
316 | 316 | |
317 | 317 | std::vector<cv::Point> polygon_pts; |
318 | 318 | cv::Point pt_lt; |
... | ... | @@ -336,11 +336,11 @@ int RoadSegAnalysis::check_cross_region(std::vector<SegInfo>& vec_reg, sy_rect r |
336 | 336 | for (size_t i = 0; i < vec_reg.size(); i++) { |
337 | 337 | SegInfo& seg = vec_reg[i]; |
338 | 338 | if (seg.seg_type == region_type) { |
339 | - // 黄实线 | |
339 | + | |
340 | 340 | int in_count = 0; |
341 | - std::vector<cv::Point> vec_pt; | |
341 | + // 车辆与region相交 | |
342 | 342 | for (size_t j = 0; j < seg.vec_pt.size(); j++) { |
343 | - double dist = pointPolygonTest(polygon_pts, cv::Point2f(seg.vec_pt[j].x_, seg.vec_pt[j].y_), false); | |
343 | + double dist = pointPolygonTest(polygon_pts, seg.vec_pt[j], false); | |
344 | 344 | if (dist > 0) { |
345 | 345 | in_count ++; |
346 | 346 | } |
... | ... | @@ -350,76 +350,20 @@ int RoadSegAnalysis::check_cross_region(std::vector<SegInfo>& vec_reg, sy_rect r |
350 | 350 | {//有5个点就认为是压线了 |
351 | 351 | return 1; |
352 | 352 | } |
353 | + | |
354 | + // 车辆与region相交情形未检测出来,检测车辆在region中情形 | |
355 | + for (size_t j = 0; j < polygon_pts.size(); j++) { | |
356 | + double dist = pointPolygonTest(seg.vec_pt, polygon_pts[j], false); | |
357 | + if (dist > 0) { | |
358 | + return 1; | |
359 | + } | |
360 | + } | |
353 | 361 | } |
354 | 362 | } |
355 | 363 | |
356 | 364 | return -1; |
357 | 365 | } |
358 | 366 | |
359 | -// cv::Mat imshow_lanes(cv::Mat img, const rs_lane* lanes, int lane_count) { | |
360 | -// float scale_w = img.cols / 640.0; | |
361 | -// float scale_h = img.rows / 360.0; | |
362 | -// std::vector<std::pair<std::vector<cv::Point>, int>> combined; | |
363 | -// lanes_process(lanes, lane_count, combined, scale_w, scale_h); | |
364 | - | |
365 | -// for (const auto& lane_info : combined) { | |
366 | -// const auto& xys = lane_info.first; | |
367 | -// int cls = lane_info.second; | |
368 | -// cv::Scalar color(lane_colors[cls][0],lane_colors[cls][1],lane_colors[cls][2]); | |
369 | -// for (size_t i = 1; i < xys.size(); ++i) { | |
370 | -// cv::line(img, xys[i - 1], xys[i], color, 4); | |
371 | -// } | |
372 | -// } | |
373 | - | |
374 | -// return img; | |
375 | -// } | |
376 | - | |
377 | -// void RoadSegAnalysis::post_direct(rs_result one_result, sy_img src){ | |
378 | -// int src_width = src.w_; | |
379 | -// int src_height = src.h_; | |
380 | -// int w = 640; | |
381 | -// int h = 360; | |
382 | -// float alpha = 0.75; | |
383 | -// cv::Mat overlayed_direct_img(cv::Size(w,h), CV_8UC3, cv::Scalar(0, 0, 0)); | |
384 | -// // 将车道线标签转换为彩色图像 | |
385 | -// for (int i = 0; i < h; ++i) { | |
386 | -// for (int j = 0; j < w; ++j) { | |
387 | -// int idx = one_result.direct_seg[(i * w + j)]; | |
388 | -// overlayed_direct_img.at<cv::Vec3b>(i, j)[0] = seg_colors[idx][0]; // R通道; | |
389 | -// overlayed_direct_img.at<cv::Vec3b>(i, j)[1] = seg_colors[idx][1]; // G通道 | |
390 | -// overlayed_direct_img.at<cv::Vec3b>(i, j)[2] = seg_colors[idx][2]; // B通道 | |
391 | -// } | |
392 | -// } | |
393 | -// cv::resize(overlayed_direct_img, overlayed_direct_img, cv::Size(src_width,src_height), 0, 0, cv::INTER_LINEAR); | |
394 | -// // 将原始图像和彩色车道线图进行混合 | |
395 | -// // cv::addWeighted(cvImg, alpha, overlayed_direct_img, 1 - alpha, 0, overlayed_direct_img); | |
396 | -// cv::Mat img_direct_lane = imshow_lanes(overlayed_direct_img, one_result.reg_array, one_result.lane_count); | |
397 | -// cv::imwrite("img_direct_lane.jpg", img_direct_lane); | |
398 | - | |
399 | - | |
400 | -// std::vector<std::pair<std::vector<cv::Point>, int>> combined; | |
401 | -// lanes_process(one_result.reg_array, one_result.lane_count, combined); | |
402 | -// std::vector<std::vector<cv::Point>> poly_masks, lanes, direct_masks, merge_masks; | |
403 | -// std::vector<int> region_classes, cats, direct_classes, merge_classes; | |
404 | -// cv::Mat background_mask; | |
405 | -// std::map<double, int> x_sort; | |
406 | -// bool large_resolution = false; | |
407 | -// if (src_height > 1920) large_resolution = true; | |
408 | -// cv::Mat seg_output = seg_post_process(large_resolution, one_result.seg_array, combined, poly_masks, region_classes, lanes, cats, x_sort, background_mask); //m_masks:mask前的结果 poly_masks后的结果 | |
409 | -// cv::Mat direct_output = direct_post_process(large_resolution, one_result.direct_seg, direct_masks, direct_classes); | |
410 | -// cv::Mat merge_output = merge_direct_process(large_resolution, one_result.direct_seg, merge_masks, merge_classes); | |
411 | - | |
412 | -// cv::Mat image(cv::Size(w,h), CV_8UC3, cv::Scalar(0, 0, 0)); | |
413 | -// cv::Mat vis_image = mask_to_rgb(image, seg_output); | |
414 | -// cv::Mat direct_image = mask_to_rgb(image, direct_output); | |
415 | -// cv::Mat merge_image = mask_to_rgb(image, merge_output); | |
416 | -// cv::imwrite("vis_image.jpg", vis_image); | |
417 | -// cv::imwrite("direct_image.jpg", direct_image); | |
418 | -// cv::imwrite("merge_image.jpg", merge_image); | |
419 | -// cv::imwrite("background_mask.jpg", background_mask); | |
420 | -// } | |
421 | - | |
422 | - | |
423 | 367 | cv::Mat RoadSegAnalysis::mask_to_rgb(cv::Mat img, cv::Mat mask) { |
424 | 368 | cv::Mat masks = img.clone(); |
425 | 369 | int reg_cls = 8; |
... | ... | @@ -612,10 +556,6 @@ cv::Mat RoadSegAnalysis::seg_post_process(bool large_resolution, unsigned char * |
612 | 556 | if (x_sort.count(centr_x)) centr_x += 0.0001; |
613 | 557 | x_sort.insert(std::make_pair(centr_x, count)); |
614 | 558 | ++ count; |
615 | - // for (auto iter: contours_poly) { | |
616 | - // std::cout << "contour " << iter << " " << cat << std::endl; | |
617 | - // } | |
618 | - | |
619 | 559 | } |
620 | 560 | } |
621 | 561 | } | ... | ... |
src/ai_engine_module/RoadSegAnalysis.h
... | ... | @@ -18,15 +18,15 @@ public: |
18 | 18 | RoadSegAnalysis(/* args */); |
19 | 19 | ~RoadSegAnalysis(); |
20 | 20 | |
21 | - int init(int devId); | |
21 | + int init(int devId, std::string sdk_root); | |
22 | 22 | |
23 | 23 | std::vector<RoadInfo> detect(vector<sy_img> vec_img); |
24 | 24 | |
25 | 25 | int check_reverse_driving(std::vector<SegInfo>& vec_direct, sy_rect rc, int src_width, int src_height, int head_or_tail); |
26 | 26 | |
27 | - int check_cross_line(std::vector<LineInfo>& vec_line, sy_rect rc); | |
27 | + int check_cross_line(std::vector<LineInfo>& vec_line, sy_rect rc, int src_width, int src_height); | |
28 | 28 | |
29 | - int check_cross_region(std::vector<SegInfo>& vec_reg, sy_rect rc, int region_type); | |
29 | + int check_cross_region(std::vector<SegInfo>& vec_reg, sy_rect rc, int src_width, int src_height, int region_type); | |
30 | 30 | |
31 | 31 | private: |
32 | 32 | int release(); | ... | ... |
src/ai_engine_module/VehicleAnalysis.cpp
... | ... | @@ -9,7 +9,7 @@ VehicleAnalysis::~VehicleAnalysis() { |
9 | 9 | release(); |
10 | 10 | } |
11 | 11 | |
12 | -int VehicleAnalysis::init(int devId, int max_batch_size) { | |
12 | +int VehicleAnalysis::init(int devId, std::string sdk_root, int max_batch_size) { | |
13 | 13 | |
14 | 14 | param.vehicle_detect_config= SY_CONFIG_OPEN; //1.开启车检测 SY_CONFIG_CLOSE SY_CONFIG_OPEN |
15 | 15 | param.vehicle_recg_config= SY_CONFIG_OPEN; //4.开启车型识别 |
... | ... | @@ -52,9 +52,11 @@ int VehicleAnalysis::init(int devId, int max_batch_size) { |
52 | 52 | //车颜色阈值 |
53 | 53 | param.vc_thresld = 0.5; |
54 | 54 | |
55 | + string dbPath = sdk_root + "/models/vehicle_analysis/db/vr_h0725x210605_r191230.db"; | |
56 | + string models_path = sdk_root + "/models/vehicle_analysis/"; | |
55 | 57 | //车型参数 |
56 | - param.dbPath="./models/vehicle_analysis/db/vr_h0725x210605_r191230.db"; | |
57 | - param.models_Path="./models/vehicle_analysis/"; //所有模型的地址 | |
58 | + param.dbPath= (char*)dbPath.data(); | |
59 | + param.models_Path= (char*)models_path.data(); //所有模型的地址 | |
58 | 60 | |
59 | 61 | cout << "va_init start " << endl; |
60 | 62 | // 内部有 ctx | ... | ... |
src/ai_engine_module/VehicleAnalysis.h
src/ai_engine_module/VehicleHeadTail.cpp
... | ... | @@ -17,8 +17,10 @@ int VehicleHeadTail::init(head_tail_param param){ |
17 | 17 | |
18 | 18 | LOG_INFO("head_tail version: head_tail_256.2024.12.18"); |
19 | 19 | |
20 | + string model_path = param.sdk_root + "/models/car_head_tail/head_tail_256_241220_310P.om"; | |
21 | + | |
20 | 22 | m_cnn_cls = new CnnCls(); |
21 | - int ret = m_cnn_cls->Init("./models/car_head_tail/head_tail_256_241220_310P.om"); | |
23 | + int ret = m_cnn_cls->Init(model_path.c_str()); | |
22 | 24 | if (ret != SY_SUCCESS) { |
23 | 25 | delete m_cnn_cls; |
24 | 26 | m_cnn_cls = nullptr; | ... | ... |
src/ai_engine_module/VehicleHeadTail.h
src/ai_engine_module/VidClothes.cpp
... | ... | @@ -9,11 +9,13 @@ VidClothes::~VidClothes() |
9 | 9 | release(); |
10 | 10 | } |
11 | 11 | |
12 | -int VidClothes::init(int devId){ | |
12 | +int VidClothes::init(int devId, std::string sdk_root){ | |
13 | 13 | ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED); |
14 | 14 | |
15 | + std::string model_path = sdk_root + "/models/vid_clothes/vidClothes0325_310P.om"; | |
16 | + | |
15 | 17 | vidclothes_param param; |
16 | - param.modelNames = "./models/vid_clothes/vidClothes0325_310P.om"; | |
18 | + param.modelNames = (char*)model_path.data(); | |
17 | 19 | param.thresld = 0.0; |
18 | 20 | param.devId = devId; |
19 | 21 | ... | ... |
src/ai_engine_module/VidClothes.h
src/ai_engine_module/va_test.cpp0 deleted
1 | -#include <iostream> | |
2 | -#include <sstream> | |
3 | -#include <fstream> | |
4 | - | |
5 | -#include "sy_common.h" | |
6 | -#include "sy_errorinfo.h" | |
7 | -#include "vehicle_analysis.h" | |
8 | -#include "vehicle_result.h" | |
9 | - | |
10 | -#include "opencv2/opencv.hpp" | |
11 | -#include "opencv2/imgcodecs/legacy/constants_c.h" | |
12 | -#include "opencv2/imgproc/types_c.h" | |
13 | -#include "time.h" | |
14 | -#include "sys/time.h" | |
15 | - | |
16 | -#include "utils.h" | |
17 | -#include "dvpp_process.h" | |
18 | - | |
19 | -using namespace std; | |
20 | -using namespace cv; | |
21 | - | |
22 | -#include <chrono> | |
23 | -#include <dirent.h> | |
24 | - | |
25 | - | |
26 | - | |
27 | -//static char colorLabel[13][8] = { "棕", "橙", "灰", "白", "粉", "紫", "红", "绿", "蓝", "银", "青", "黄", "黑" }; | |
28 | -static std::vector<std::string> CARCOLOR1 = { | |
29 | - "BROWN","ORANGE","GRAY","WHITE","PINK","PURPLE","RED","GREEN","BLUE", | |
30 | - "SILVER","CYAN","YELLOW","BLACK" | |
31 | -}; | |
32 | - | |
33 | -static char vsLabel[11][40] = { "diao", "guan", "huo", "zha", "jiao","jiu", "la", "xiao", "qing", "sui","wei" }; | |
34 | - | |
35 | - | |
36 | -double msecond() { | |
37 | - struct timeval tv; | |
38 | - gettimeofday(&tv, 0); | |
39 | - return (tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0); | |
40 | -} | |
41 | - | |
42 | - | |
43 | -void getAllNm(std::string pthNm, std::vector<std::string>& fileList) | |
44 | -{ | |
45 | - DIR *dir; | |
46 | - struct dirent *ptr; | |
47 | - dir = opendir(pthNm.c_str()); ///open the dir | |
48 | - int filenum = 0; | |
49 | - while((ptr = readdir(dir)) != NULL) ///read the list of this dir | |
50 | - { | |
51 | - // char* to string | |
52 | - std::string curNm = ptr->d_name; | |
53 | - if(curNm != "." && curNm != "..") | |
54 | - { | |
55 | - filenum++; | |
56 | - fileList.push_back(curNm); | |
57 | - //printf("file %d name: %s\n", filenum, curNm.c_str()); | |
58 | - } | |
59 | - } | |
60 | - closedir(dir); | |
61 | -} | |
62 | - | |
63 | - | |
64 | -void CvBGR2NV21(Mat& bgr, unsigned char* yuv) { | |
65 | - int stride = (bgr.cols + 127) / 128 * 128; | |
66 | - int strideH = (bgr.rows + 15) / 16 * 16; | |
67 | - for (int i = 0; i < bgr.rows; i++) { | |
68 | - for (int j = 0; j < bgr.cols; j++) { | |
69 | - int B = bgr.at<cv::Vec3b>(i, j)[0]; | |
70 | - int G = bgr.at<cv::Vec3b>(i, j)[1]; | |
71 | - int R = bgr.at<cv::Vec3b>(i, j)[2]; | |
72 | - | |
73 | - int Y = (77 * R + 150 * G + 29 * B) >> 8; | |
74 | - yuv[i * stride + j] = (Y < 0) ? 0 : ((Y > 255) ? 255 : Y); | |
75 | - if (i % 2 == 0 && j % 2 == 0) { | |
76 | - int U = ((-44 * R - 87 * G + 131 * B) >> 8) + 128; | |
77 | - int V = ((131 * R - 110 * G - 21 * B) >> 8) + 128; | |
78 | - yuv[strideH * stride + i / 2 * stride + j] = (V < 0) ? 0 : ((V > 255) ? 255 : V); | |
79 | - yuv[strideH * stride + i / 2 * stride + j + 1] = (U < 0) ? 0 : ((U > 255) ? 255 : U); | |
80 | - } | |
81 | - } | |
82 | - } | |
83 | -} | |
84 | - | |
85 | - | |
86 | - | |
87 | - | |
88 | - | |
89 | - | |
90 | - | |
91 | -int main() { | |
92 | - | |
93 | - //ofstream oFile; | |
94 | - //打开要输出的文件 | |
95 | - //oFile.open("va_result.csv", ios::out | ios::trunc); | |
96 | - //oFile << "image" << "," << "image_quality_score" << "," << "count" << "," << "vehicle_info" << endl; | |
97 | - | |
98 | - | |
99 | - cout << va_get_version() << endl; | |
100 | - | |
101 | - //string imagepath= "./vpt/"; | |
102 | - //string saveimagepath= "./result/"; | |
103 | - //int gpuid = 0; | |
104 | - | |
105 | - //string imagepath= "/home/HwHiAiUser/WH/vehicle_analysis202105/data/vpt/"; | |
106 | - //string imagepath= "/home/HwHiAiUser/WH/vehicle_analysis202105/data/bug/"; | |
107 | - string img_file_path= "/data/wanghong/Atlas310pro/vehicle_analysis202303/data/bug/"; | |
108 | - //string imagepath= "/home/HwHiAiUser/WH/vehicle_analysis202105/data/img/"; | |
109 | - //string imagepath= "/home/HwHiAiUser/WH/vehicle_analysis202105/data/carset/"; | |
110 | - string saveimagepath= "/data/wanghong/Atlas310pro/vehicle_analysis202303/data/result/"; | |
111 | - int gpuid = 0; | |
112 | - | |
113 | - va_param param; | |
114 | - param.vehicle_detect_config= SY_CONFIG_OPEN; //1.开启车检测 SY_CONFIG_CLOSE SY_CONFIG_OPEN | |
115 | - param.vehicle_color_config= SY_CONFIG_OPEN; //3.开启车颜色识别 | |
116 | - param.vehicle_recg_config= SY_CONFIG_OPEN; //4.开启车型识别 | |
117 | - param.vehicle_recg_supplement_config= SY_CONFIG_OPEN; //4.开启车型识别补充识别 | |
118 | - param.vehicle_plate_det_recg_config= SY_CONFIG_OPEN; //5.开启车牌检测识别 | |
119 | - param.vehicle_pendant_det_config= SY_CONFIG_OPEN; //6.开启车属性检测识别 | |
120 | - param.vehicle_illegal_config= SY_CONFIG_OPEN; //7.开启车违规 | |
121 | - param.vehicle_feature_config= SY_CONFIG_OPEN; //8.开启车辆特征提取 | |
122 | - param.vehicle_motor_tricycle_analysis_config= SY_CONFIG_OPEN; //8.摩托车分析 | |
123 | - param.vehicle_manned_config= SY_CONFIG_OPEN; //8.开启载人分析 | |
124 | - | |
125 | - | |
126 | - param.gpuid=gpuid; | |
127 | - | |
128 | - //车检测参数 | |
129 | - //param.vehicle_det_param.process_min_l = 720;// 720; | |
130 | - //param.vehicle_det_param.process_max_l = 1280;//1280; | |
131 | - //param.vehicle_det_param.thresld=0.3; | |
132 | - //param.min_obj_size=200; //最小目标 | |
133 | - param.vehicle_det_thresld=0.4; | |
134 | - | |
135 | - //车牌检测参数 | |
136 | - //param.vehicle_plate_det_param.process_min_l=320; | |
137 | - //param.vehicle_plate_det_param.process_max_l=320; | |
138 | - //param.vehicle_plate_det_param.thresld=0.4; | |
139 | - param.vehicle_plate_det_thresld=0.5; | |
140 | - | |
141 | - //车属性检测参数 | |
142 | - //param.vehicle_attribute_det_param.process_min_l=360; | |
143 | - //param.vehicle_attribute_det_param.process_max_l=640; | |
144 | - //param.vehicle_attribute_det_param.thresld=0.3; | |
145 | - param.vehicle_attribute_det_thresld=0.5; | |
146 | - | |
147 | - //车logo检测参数 | |
148 | - //param.vehicle_logo_det_param.process_min_l=512; | |
149 | - //param.vehicle_logo_det_param.process_max_l=512; | |
150 | - //param.vehicle_logo_det_param.thresld=0.1; | |
151 | - param.vehicle_logo_det_thresld=0.1; | |
152 | - | |
153 | - //车颜色阈值 | |
154 | - param.vc_thresld = 0.5; | |
155 | - | |
156 | - //车型参数 | |
157 | - param.dbPath="/data/wanghong/Atlas310pro/vehicle_analysis202303/vehicle_analysis/db/vr_h0725x210605_r191230.db"; | |
158 | - //param.dbPath="../db/vr_h0725x210605_r191230.db"; | |
159 | - | |
160 | - param.models_Path="/data/wanghong/Atlas310pro/vehicle_analysis202303/vehicle_analysis/all_models/"; //所有模型的地址 | |
161 | - //param.models_Path="../modelsPath/"; //所有模型的地址 | |
162 | - | |
163 | - | |
164 | - int ret0= va_acl_init(); | |
165 | - | |
166 | - void* handle = nullptr; | |
167 | - cout << "init start " << endl; | |
168 | - int ret = va_init(&handle, param); | |
169 | - if (ret == 0) { | |
170 | - cout << "init success " << endl; | |
171 | - } | |
172 | - else | |
173 | - return ret; | |
174 | - | |
175 | - | |
176 | - | |
177 | - | |
178 | -// void* handle111 = nullptr; | |
179 | -// cout << "init2 start " << endl; | |
180 | -// int ret2 = va_init(&handle111, param); | |
181 | -// if (ret2 == 0) { | |
182 | -// cout << "init2 success " << endl; | |
183 | -// } | |
184 | -// else | |
185 | -// { | |
186 | -// cout << "init2 failed " << endl; | |
187 | -// return ret2; | |
188 | -// } | |
189 | - | |
190 | - | |
191 | - | |
192 | - double t3=0; | |
193 | - int count =0; | |
194 | - | |
195 | -//temp | |
196 | - aclrtContext ctx; | |
197 | - ACL_CALL(aclrtCreateContext(&ctx, gpuid), ACL_ERROR_NONE, SY_FAILED); | |
198 | - ACL_CALL(aclrtSetCurrentContext(ctx), ACL_ERROR_NONE, SY_FAILED); | |
199 | - | |
200 | - aclrtStream stream = nullptr; | |
201 | - ACL_CALL(aclrtCreateStream(&stream), ACL_ERROR_NONE, SY_FAILED); | |
202 | - DvppProcess* dvpp = new DvppProcess(); | |
203 | - dvpp->InitResource(stream); | |
204 | - | |
205 | -for(int iter =0;iter<100;iter++) | |
206 | -{ | |
207 | - //ifstream infile("list.txt"); | |
208 | - //ifstream infile("list_bug.txt"); | |
209 | - //ifstream infile("list_700W.txt"); | |
210 | - //ifstream infile("list_img.txt"); | |
211 | - //string file; | |
212 | - std::vector<std::string> fileList; | |
213 | - getAllNm(img_file_path,fileList); | |
214 | - if (fileList.empty()) throw std::logic_error("No suitable images were found"); | |
215 | - | |
216 | - | |
217 | - for (auto & file : fileList) | |
218 | - { | |
219 | - string filename = img_file_path + file; | |
220 | - cout << "img path: " << filename << endl; | |
221 | - const int batch_size = 1; | |
222 | - printf("batch_size=%d \n",batch_size); | |
223 | - | |
224 | - Mat cvImg = imread(filename.c_str()); | |
225 | - sy_img imgs[batch_size]; | |
226 | - | |
227 | - ACL_CALL(aclrtSetCurrentContext(ctx), ACL_ERROR_NONE, SY_FAILED); | |
228 | - ImageData src[batch_size], dvpp_data[batch_size]; | |
229 | - if(1) | |
230 | - { | |
231 | - for (int b = 0; b < batch_size; b++) { | |
232 | - Utils::ReadImageFile(src[b], filename); //将二进制图像读入内存,并读取宽高信息 | |
233 | - ACL_CALL(dvpp->CvtJpegToYuv420sp(dvpp_data[b], src[b]), SY_SUCCESS, SY_FAILED); //解码 | |
234 | - imgs[b].w_ = dvpp_data[b].width;//dvpp_data[b].alignWidth; | |
235 | - imgs[b].h_ = dvpp_data[b].height;//dvpp_data[b].alignHeight; | |
236 | - imgs[b].data_ = dvpp_data[b].data.get();//(uint8_t*)Utils::CopyDataDeviceToLocal(dvpp_data[b].data.get(), dvpp_data[b].size); | |
237 | - } | |
238 | - } | |
239 | - | |
240 | - ImageData img_data_dvpp[batch_size]; | |
241 | - sy_img imgs_device[batch_size]; | |
242 | - if(0) | |
243 | - { | |
244 | - uint32_t alignWidth = (cvImg.cols + 127) / 128 * 128; | |
245 | - uint32_t alignHeight = (cvImg.rows + 15) / 16 * 16; | |
246 | - uint32_t size = alignWidth * alignHeight * 1.5; | |
247 | - std::shared_ptr<uint8_t> data = shared_ptr<uint8_t>((new uint8_t[size]), | |
248 | - [](uint8_t* p) {delete [] p;}); | |
249 | - CvBGR2NV21(cvImg, data.get()); | |
250 | - | |
251 | - for (int i = 0; i < batch_size; i++) { | |
252 | - imgs[i].w_ = cvImg.cols; | |
253 | - imgs[i].h_ = cvImg.rows; | |
254 | - imgs[i].data_ = data.get(); | |
255 | - //转到device输入 | |
256 | - Utils::CopysyImageDataToDvpp(img_data_dvpp[i], imgs[i]); | |
257 | - imgs_device[i].w_ = img_data_dvpp[i].width;//dvpp_data[b].alignWidth; | |
258 | - imgs_device[i].h_ = img_data_dvpp[i].height;//dvpp_data[b].alignHeight; | |
259 | - imgs_device[i].data_ = img_data_dvpp[i].data.get(); | |
260 | - } | |
261 | - } | |
262 | - | |
263 | - if(0) | |
264 | - { | |
265 | - uint32_t alignWidth = (cvImg.cols + 127) / 128 * 128; | |
266 | - uint32_t alignHeight = (cvImg.rows + 15) / 16 * 16; | |
267 | - uint32_t size = alignWidth * alignHeight * 1.5; | |
268 | - std::shared_ptr<uint8_t> data = shared_ptr<uint8_t>((new uint8_t[size]), | |
269 | - [](uint8_t* p) {delete [] p;}); | |
270 | - CvBGR2NV21(cvImg, data.get()); | |
271 | - | |
272 | - for (int i = 0; i < batch_size; i++) { | |
273 | - imgs[i].w_ = cvImg.cols; | |
274 | - imgs[i].h_ = cvImg.rows; | |
275 | - imgs[i].data_ = data.get(); | |
276 | - } | |
277 | - | |
278 | - } | |
279 | - | |
280 | - count++; | |
281 | - | |
282 | - va_result *result=new va_result[batch_size]; | |
283 | - for(int b=0;b<batch_size;b++) | |
284 | - { | |
285 | - result[b].count=0; | |
286 | - result[b].info=new vehicle_info[100]; | |
287 | - for(int c=0; c<100; c++) | |
288 | - { | |
289 | - result[b].info[c].vehicle_pendant_det_res.vpd_res=new v_pendant_d_info[300]; | |
290 | - } | |
291 | - } | |
292 | - | |
293 | - double t1,t2; | |
294 | - t1 = msecond(); | |
295 | - | |
296 | - std::cout << "Predict----------------------------------"<< std::endl; | |
297 | - int ret = va_batch(handle, imgs, batch_size, result); | |
298 | - //int ret = va_batch(handle, imgs_device, batch_size, result); | |
299 | - t2 = msecond(); | |
300 | - printf("va_teat info:va_batch time: %.2f\n", (t2 - t1)); | |
301 | - t3 += t2-t1; | |
302 | - | |
303 | - std::cout << "output----------------------------------"<< std::endl; | |
304 | - | |
305 | - for (int b = 0; b < batch_size; b++) | |
306 | - { | |
307 | - if(param.vehicle_detect_config==SY_CONFIG_CLOSE)//不做车头检测时,应设result[b].count=1,即输入是车头图像,只含1辆车。 | |
308 | - result[b].count=1; | |
309 | - | |
310 | - //oFile << file << ","<< result[b].count<< "," <<endl;; | |
311 | - std::cout <<"car_count:" <<result[b].count<< std::endl; | |
312 | - for(int c=0;c<result[b].count;c++) | |
313 | - { | |
314 | - //temp,中间结果,输出车牌被置黑的车小图 | |
315 | - //if(0) | |
316 | - //{ | |
317 | - // cv::Mat tmp(result[b].info[c].car_img_data_cpu[0].h_, result[b].info[c].car_img_data_cpu[0].w_, CV_8UC3, result[b].info[c].car_img_data_cpu[0].data_); | |
318 | - // char str_i[100]; | |
319 | - // sprintf(str_i, "%d_", c); | |
320 | - // cv::imwrite((save_folder_roi+str_i+i).c_str(),tmp); | |
321 | - //} | |
322 | - | |
323 | - | |
324 | - std::string str_vehicle_type; | |
325 | - int vehicle_type=result[b].info[c].type; | |
326 | - //std::cout << "vehicle_type="<<vehicle_type<< std::endl; | |
327 | - if (vehicle_type==0)str_vehicle_type = "head"; | |
328 | - else if (vehicle_type==1)str_vehicle_type = "rear"; | |
329 | - else if (vehicle_type==2)str_vehicle_type = "motor"; | |
330 | - else if (vehicle_type==3)str_vehicle_type = "tricycle"; | |
331 | - else if (vehicle_type==4)str_vehicle_type = "body"; | |
332 | - else if (vehicle_type==5)str_vehicle_type = "body_nova"; | |
333 | - std::cout << " vehicle_type:"<<str_vehicle_type<< std::endl; | |
334 | - | |
335 | - //1.车头结果:蓝框//2.车窗结果:绿框 | |
336 | - if(param.vehicle_detect_config==SY_CONFIG_OPEN) | |
337 | - { | |
338 | - //车身 | |
339 | - //std::cout << "vehicle_body_detect_res info:"<< std::endl; | |
340 | - if(result[b].info[c].vehicle_body_detect_res.rect.width_>0) | |
341 | - { | |
342 | - float vehicle_body_detect_res_score = result[b].info[c].vehicle_body_detect_res.score; | |
343 | - int x1=result[b].info[c].vehicle_body_detect_res.rect.left_; | |
344 | - int y1=result[b].info[c].vehicle_body_detect_res.rect.top_; | |
345 | - int x2=result[b].info[c].vehicle_body_detect_res.rect.left_+result[b].info[c].vehicle_body_detect_res.rect.width_; | |
346 | - int y2=result[b].info[c].vehicle_body_detect_res.rect.top_+result[b].info[c].vehicle_body_detect_res.rect.height_; | |
347 | - std::cout << " vehicle_body_detect_res_score:" <<vehicle_body_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl; | |
348 | - | |
349 | - Point lt(x1, y1); | |
350 | - Point rb(x2, y2); | |
351 | - rectangle(cvImg, lt, rb, cv::Scalar(0, 255,255), 4); | |
352 | - } | |
353 | - | |
354 | - //车头 | |
355 | - //std::cout << "vehicle_detect_res info:"<< std::endl; | |
356 | - if(result[b].info[c].vehicle_detect_res.rect.width_>0) | |
357 | - { | |
358 | - float vehicle_detect_res_score = result[b].info[c].vehicle_detect_res.score; | |
359 | - int x1=result[b].info[c].vehicle_detect_res.rect.left_; | |
360 | - int y1=result[b].info[c].vehicle_detect_res.rect.top_; | |
361 | - int x2=result[b].info[c].vehicle_detect_res.rect.left_+result[b].info[c].vehicle_detect_res.rect.width_; | |
362 | - int y2=result[b].info[c].vehicle_detect_res.rect.top_+result[b].info[c].vehicle_detect_res.rect.height_; | |
363 | - std::cout << " vehicle_detect_res_score:" <<vehicle_detect_res_score<<",car_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl; | |
364 | - | |
365 | - Point lt(x1, y1); | |
366 | - Point rb(x2, y2); | |
367 | - rectangle(cvImg, lt, rb, cv::Scalar(255, 0, 0), 4); | |
368 | - } | |
369 | - | |
370 | - //车窗 | |
371 | - //std::cout << "vwd output----"<< std::endl; | |
372 | - if(result[b].info[c].vehicle_win_detect_res.rect.width_>0) | |
373 | - { | |
374 | - float vehicle_win_detect_res_score = result[b].info[c].vehicle_win_detect_res.score; | |
375 | - int x1=result[b].info[c].vehicle_win_detect_res.rect.left_; | |
376 | - int y1=result[b].info[c].vehicle_win_detect_res.rect.top_; | |
377 | - int x2=result[b].info[c].vehicle_win_detect_res.rect.left_+result[b].info[c].vehicle_win_detect_res.rect.width_; | |
378 | - int y2=result[b].info[c].vehicle_win_detect_res.rect.top_+result[b].info[c].vehicle_win_detect_res.rect.height_; | |
379 | - std::cout << " vehicle_win_detect_res_score:" <<vehicle_win_detect_res_score<<",win_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl; | |
380 | - | |
381 | - Point lt(x1, y1); | |
382 | - Point rb(x2, y2); | |
383 | - rectangle(cvImg, lt, rb, cv::Scalar(0, 255, 0), 4); | |
384 | - } | |
385 | - } | |
386 | - | |
387 | - | |
388 | - //3.车颜色 | |
389 | - if(param.vehicle_color_config==SY_CONFIG_OPEN&& (vehicle_type==0 || vehicle_type==1 || vehicle_type==4)) | |
390 | - { | |
391 | - //std::cout << "vc output----"<< std::endl; | |
392 | - int index=result[b].info[c].vehicle_color_res.index; | |
393 | - float score=result[b].info[c].vehicle_color_res.score; | |
394 | - | |
395 | - if(score>0.5) | |
396 | - { | |
397 | - std::cout << " car color info:"<< endl; | |
398 | - std::cout << " index:"<< index<<" score:"<< score<< std::endl; | |
399 | - | |
400 | - std::string str_i = CARCOLOR1[index]; | |
401 | - cv::putText(cvImg, str_i, | |
402 | - cv::Point(result[b].info[c].vehicle_body_detect_res.rect.left_+5, result[b].info[c].vehicle_body_detect_res.rect.top_+50), | |
403 | - cv::FONT_HERSHEY_COMPLEX_SMALL, | |
404 | - 1.3, | |
405 | - cv::Scalar(0, 0, 255), | |
406 | - 2); | |
407 | - } | |
408 | - } | |
409 | - | |
410 | - | |
411 | - //4.VR车型识别 | |
412 | - if(param.vehicle_recg_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1 || vehicle_type==4 )) | |
413 | - { | |
414 | - //std::cout << "vr output----"<< std::endl; | |
415 | - | |
416 | - char *vehicle_brand=result[b].info[c].vehicle_recg_res.vehicle_brand;//车辆品牌 | |
417 | - char* vehicle_subbrand=result[b].info[c].vehicle_recg_res.vehicle_subbrand; //车辆子品牌 | |
418 | - char* vehicle_issue_year=result[b].info[c].vehicle_recg_res.vehicle_issue_year; //车辆年款 | |
419 | - char* vehicle_type_=result[b].info[c].vehicle_recg_res.vehicle_type; //车辆类型 | |
420 | - char* freight_ton=result[b].info[c].vehicle_recg_res.freight_ton; //货车吨级 | |
421 | - float name_score=result[b].info[c].vehicle_recg_res.name_score; //识别置信度 | |
422 | - | |
423 | - float name_score_thre = 0; | |
424 | - //if(vehicle_type==0)name_score_thre=0.7;//车头车型识别建议阈值0.7 | |
425 | - //if(vehicle_type==1)name_score_thre=0.8;//车尾车型识别建议阈值0.8 | |
426 | - if(name_score > name_score_thre) | |
427 | - { | |
428 | - cout << " vehicle_recg info: " << endl; | |
429 | - std::cout << " name_score: " << name_score << std::endl; | |
430 | - std::cout << " vehicle_brand: " << vehicle_brand << std::endl; | |
431 | - std::cout << " vehicle_subbrand: " << vehicle_subbrand << std::endl; | |
432 | - std::cout << " vehicle_issue_year: " << vehicle_issue_year << std::endl; | |
433 | - std::cout << " vehicle_type_: " << vehicle_type_ << std::endl; | |
434 | - std::cout << " freight_ton: " << freight_ton << std::endl; | |
435 | - | |
436 | - //printf("name_score:%f\n", name_score); | |
437 | - //printf("vehicle_brand:%s\n", vehicle_brand); | |
438 | - //printf("vehicle_subbrand:%s\n", vehicle_subbrand); | |
439 | - //printf("vehicle_issue_year:%s\n", vehicle_issue_year); | |
440 | - //printf("vehicle_type_:%s\n", vehicle_type_); | |
441 | - //printf("freight_ton:%s\n", freight_ton); | |
442 | - } | |
443 | - | |
444 | - } | |
445 | - | |
446 | - | |
447 | - //5.VP车牌检测识别 | |
448 | - if(param.vehicle_plate_det_recg_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1)) | |
449 | - { | |
450 | - std::cout << " car plate info:"<< endl; | |
451 | - int special_type=result[b].info[c].vehicle_plate_det_recg_res.special_type;//常规车牌、临时车牌、低速车牌。0-common,1-temporary_license_plate,2-low_speed_license_plate. | |
452 | - std::cout << " special_type:" << special_type<< std::endl; | |
453 | - | |
454 | - float detect_score=result[b].info[c].vehicle_plate_det_recg_res.detect_score; | |
455 | - //std::cout << "detect_score:" << detect_score<< std::endl; | |
456 | - if(detect_score>0.3) | |
457 | - { | |
458 | - int type=result[b].info[c].vehicle_plate_det_recg_res.type; | |
459 | - sy_rect rect=result[b].info[c].vehicle_plate_det_recg_res.rect; | |
460 | - | |
461 | - int x1=rect.left_; | |
462 | - int y1=rect.top_; | |
463 | - int x2=rect.left_+rect.width_; | |
464 | - int y2=rect.top_+rect.height_; | |
465 | - std::cout << " vp_type:"<<type<<",vp_det_score:" <<detect_score <<",vp_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<< std::endl; | |
466 | - | |
467 | - Point lt(x1, y1); | |
468 | - Point rb(x2, y2); | |
469 | - rectangle(cvImg, lt, rb, cv::Scalar(0, 0, 255), 4); | |
470 | - | |
471 | - | |
472 | - | |
473 | - //车牌识别结果 | |
474 | - float num_score=result[b].info[c].vehicle_plate_det_recg_res.num_score; | |
475 | - std::string plate_recg=""; | |
476 | - //if(num_score>0.99)//车牌识别建议置信度阈值0.99 | |
477 | - { | |
478 | - | |
479 | - //printf("plate: "); | |
480 | - for (int m = 0; m < PLATENUM; m++) | |
481 | - { | |
482 | - //printf("%s", result[b].info[c].vehicle_plate_det_recg_res.recg[m].character); | |
483 | - plate_recg=plate_recg + result[b].info[c].vehicle_plate_det_recg_res.recg[m].character; | |
484 | - } | |
485 | - //printf("\n"); | |
486 | - | |
487 | - //printf("maxprob: "); | |
488 | - //for (int m = 0; m < PLATENUM; m++) | |
489 | - //{ | |
490 | - // printf("%f ", result[b].info[c].vehicle_plate_det_recg_res.vehicle_plate_infos[0].recg[m].maxprob); | |
491 | - //} | |
492 | - //printf("\n"); | |
493 | - | |
494 | - | |
495 | - //std::cout << "type:" << type<<" num_score:" <<num_score<<" " << std::endl; | |
496 | - std::cout <<" "<<plate_recg<< ",vp_num_score:" << num_score<< std::endl; | |
497 | - | |
498 | - } | |
499 | - | |
500 | - | |
501 | - char str_cc[100]; | |
502 | - memset(str_cc, 0, sizeof(str_cc)); | |
503 | - cv::Point2f p1; | |
504 | - p1.x = x1; | |
505 | - p1.y = y1-60; | |
506 | - //sprintf(str_cc, "det_%.2f_recg_%.2f_%s",detectScore,numScore,plate_recg.c_str()); | |
507 | - sprintf(str_cc, "det_%.2f",detect_score); | |
508 | - cv::putText(cvImg, str_cc, | |
509 | - p1, | |
510 | - cv::FONT_HERSHEY_COMPLEX_SMALL, | |
511 | - 1.3, | |
512 | - cv::Scalar(0, 0, 255), | |
513 | - 2); | |
514 | - | |
515 | - memset(str_cc, 0, sizeof(str_cc)); | |
516 | - p1.x = x1; | |
517 | - p1.y = y1-30; | |
518 | - sprintf(str_cc, "recg_%.2f",num_score); | |
519 | - cv::putText(cvImg, str_cc, | |
520 | - p1, | |
521 | - cv::FONT_HERSHEY_COMPLEX_SMALL, | |
522 | - 1.3, | |
523 | - cv::Scalar(0, 0, 255), | |
524 | - 2); | |
525 | - | |
526 | - memset(str_cc, 0, sizeof(str_cc)); | |
527 | - p1.x = x1; | |
528 | - p1.y = y1; | |
529 | - sprintf(str_cc, "%s",plate_recg.c_str()); | |
530 | - cv::putText(cvImg, str_cc, | |
531 | - p1, | |
532 | - cv::FONT_HERSHEY_COMPLEX_SMALL, | |
533 | - 1.3, | |
534 | - cv::Scalar(0, 0, 255), | |
535 | - 2); | |
536 | - | |
537 | - } | |
538 | - | |
539 | - } | |
540 | - | |
541 | - //6.车属性结果: | |
542 | - if(param.vehicle_pendant_det_config==SY_CONFIG_OPEN && (vehicle_type==0|| vehicle_type==4)) | |
543 | - { | |
544 | - std::cout << " vehicle_pendant_det_res info:"<< endl; | |
545 | - int vpd_num = result[b].info[c].vehicle_pendant_det_res.count; | |
546 | - //std::cout << vpd_num<< std::endl; | |
547 | - std::cout << " vpd_num:"<<vpd_num<< endl; | |
548 | - for(int p=0; p<vpd_num; p++) | |
549 | - { | |
550 | - int index = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].index; | |
551 | - float detect_score = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].confidence; | |
552 | - int driver_copilot_info = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].driver_copilot_info; | |
553 | - int x1=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.left_; | |
554 | - int y1=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.top_; | |
555 | - int x2=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.left_+result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.width_; | |
556 | - int y2=result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.top_+result[b].info[c].vehicle_pendant_det_res.vpd_res[p].rect.height_; | |
557 | - | |
558 | - //std::cout <<p<<" ["<<x1<<" "<<y1<<" "<<x2-x1<<" "<<y2-y1<<"] "<<detectScore<<" "<<index<<" "<<driver_copilot_info<< std::endl; | |
559 | - std::cout << " vpd id:"<<p<<" index:"<<index<<",vpd_det_score:" <<detect_score <<",vpd_rect:[" <<x1<<"," <<y1<<"," <<x2-x1<<"," <<y2-y1<<"]"<<" driver_copilot_info:"<<driver_copilot_info<< std::endl; | |
560 | - | |
561 | - | |
562 | - Point lt(x1, y1); | |
563 | - Point rb(x2, y2); | |
564 | - rectangle(cvImg, lt, rb, cv::Scalar(255, 255, 0), 4); | |
565 | - | |
566 | - //车属性人脸特征 | |
567 | - //f(index ==1)//人脸 | |
568 | - //{ | |
569 | - // std::cout << " vpd face feature:["; | |
570 | - // /*for(int f=0;f<VPD_FACE_FEATURESIZE;f++) | |
571 | - // { | |
572 | - // float fea = result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[f]; | |
573 | - // //std::cout << "feature "<<f<<":"<<fea<<std::endl; | |
574 | - // std::cout <<fea<< " "; | |
575 | - // }*/ | |
576 | - // std::cout << "]"<< std::endl; | |
577 | - // //std::cout << "face feature:"<<result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[0]<<" "<<result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[1]<<" "<<result[b].info[c].vehicle_pendant_det_res.vpd_res[p].feature[2]<<std::endl; | |
578 | - //} | |
579 | - } | |
580 | - } | |
581 | - | |
582 | - //7.VID车违规结果----------- | |
583 | - if(param.vehicle_illegal_config==SY_CONFIG_OPEN && vehicle_type==0) | |
584 | - { | |
585 | - std::cout << " vehicle_illegal_det_res info:"<< endl; | |
586 | - vid_result cur_result = result[b].info[c].vehicle_illegal_det_res; | |
587 | - //副驾驶copilot | |
588 | - { | |
589 | - //有人没人判断,阈值0.6 | |
590 | - std::string str_person="UNCERTAINTY"; | |
591 | - if(cur_result.copilot.person.status==SOMEBODY) | |
592 | - str_person ="PERSON"; | |
593 | - else if(cur_result.copilot.person.status==NOBODY) | |
594 | - str_person ="NOPERSON"; | |
595 | - //cv::putText(batch_mat[b], str_person, | |
596 | - // cv::Point(5, 25), | |
597 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
598 | - // 1.3, | |
599 | - // cv::Scalar(255, 0, 0), | |
600 | - // 2); | |
601 | - | |
602 | - //打电话,阈值0.9 | |
603 | - std::string str_call="UNCERTAINTY"; | |
604 | - if(cur_result.copilot.call.status==lEGAL) | |
605 | - str_call ="lEGAL";//str_call ="NOCALL"; | |
606 | - else if(cur_result.copilot.call.status==ILLEGAL) | |
607 | - str_call ="ILLEGAL";//str_call ="CALL"; | |
608 | - //cv::putText(batch_mat[b], str_call, | |
609 | - // cv::Point(5, 50), | |
610 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
611 | - // 1.3, | |
612 | - // cv::Scalar(255, 0, 0), | |
613 | - // 2); | |
614 | - | |
615 | - //使用电话、阈值0.89 | |
616 | - std::string str_phone="UNCERTAINTY"; | |
617 | - if(cur_result.copilot.phone.status==lEGAL) | |
618 | - str_phone ="lEGAL";//str_phone ="NOPHONE"; | |
619 | - else if(cur_result.copilot.phone.status==ILLEGAL) | |
620 | - str_phone ="ILLEGAL";//str_phone ="USEPHONE"; | |
621 | - //cv::putText(batch_mat[b], str_phone, | |
622 | - // cv::Point(5, 75), | |
623 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
624 | - // 1.3, | |
625 | - // cv::Scalar(255, 0, 0), | |
626 | - // 2); | |
627 | - | |
628 | - //系安全带,阈值0.5 | |
629 | - std::string str_belt="UNCERTAINTY"; | |
630 | - if(cur_result.copilot.belt.status==lEGAL) | |
631 | - str_belt ="lEGAL";//str_belt ="SAFETYBELT"; | |
632 | - else if(cur_result.copilot.belt.status==ILLEGAL) | |
633 | - str_belt ="ILLEGAL"; | |
634 | - | |
635 | - //cv::putText(batch_mat[b], str_belt, | |
636 | - // cv::Point(5, 75), | |
637 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
638 | - // 1.3, | |
639 | - // cv::Scalar(255, 0, 0), | |
640 | - // 2); | |
641 | - | |
642 | - //抽烟,阈值0.9 | |
643 | - std::string str_smoke="UNCERTAINTY"; | |
644 | - if(cur_result.copilot.smoke.status==ILLEGAL) | |
645 | - str_smoke ="ILLEGAL";//str_smoke ="SMOKE"; | |
646 | - else if(cur_result.copilot.smoke.status==lEGAL) | |
647 | - str_smoke ="lEGAL";//str_smoke ="NOSMOKE"; | |
648 | - //cv::putText(batch_mat[b], str_smoke, | |
649 | - // cv::Point(5, 100), | |
650 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
651 | - // 1.3, | |
652 | - // cv::Scalar(255, 0, 0), | |
653 | - // 2); | |
654 | - | |
655 | - //std::cout << "copilot: "<<str_person<< " "<<str_call<< " "<<str_phone<< " "<<str_belt<< " "<<str_smoke<< std::endl; | |
656 | - //std::cout << "copilot confidence: "<<cur_result.copilot.person.confidence<< " "<<cur_result.copilot.call.confidence<< " "<<cur_result.copilot.phone.confidence<< " "<<cur_result.copilot.belt.confidence<< " "<<cur_result.copilot.smoke.confidence<< std::endl; | |
657 | - std::cout << " copilot: "<<"person:"<<str_person<< " call:"<<str_call<< " phone:"<<str_phone<< " belt:"<<str_belt<< " smoke:"<<str_smoke<< std::endl; | |
658 | - std::cout << " copilot confidence: "<<"person:"<<cur_result.copilot.person.confidence<< " call:"<<cur_result.copilot.call.confidence<< " phone:"<<cur_result.copilot.phone.confidence<< " belt:"<<cur_result.copilot.belt.confidence<< " smoke:"<<cur_result.copilot.smoke.confidence<< std::endl; | |
659 | - | |
660 | - } | |
661 | - | |
662 | - //驾驶driver | |
663 | - { | |
664 | - //有人没人判断,阈值0.6 | |
665 | - std::string str_person="UNCERTAINTY"; | |
666 | - if(cur_result.driver.person.status==SOMEBODY) | |
667 | - str_person ="PERSON"; | |
668 | - else if(cur_result.driver.person.status==NOBODY) | |
669 | - str_person ="NOPERSON"; | |
670 | - //cv::putText(batch_mat[b], str_person, | |
671 | - // cv::Point(5, 150), | |
672 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
673 | - // 1.3, | |
674 | - // cv::Scalar(255, 0, 0), | |
675 | - // 2); | |
676 | - | |
677 | - //打电话,阈值0.9 | |
678 | - std::string str_call="UNCERTAINTY"; | |
679 | - if(cur_result.driver.call.status==lEGAL) | |
680 | - str_call ="lEGAL";//str_call ="NOCALL"; | |
681 | - else if(cur_result.driver.call.status==ILLEGAL) | |
682 | - str_call ="ILLEGAL";//str_call ="CALL"; | |
683 | - //cv::putText(batch_mat[b], str_call, | |
684 | - // cv::Point(5, 175), | |
685 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
686 | - // 1.3, | |
687 | - // cv::Scalar(255, 0, 0), | |
688 | - // 2); | |
689 | - | |
690 | - //使用电话,阈值0.89 | |
691 | - std::string str_phone="UNCERTAINTY"; | |
692 | - if(cur_result.driver.phone.status==lEGAL) | |
693 | - str_phone ="lEGAL";//str_phone ="NOPHONE"; | |
694 | - else if(cur_result.driver.phone.status==ILLEGAL) | |
695 | - str_phone ="ILLEGAL";//str_phone ="USEPHONE"; | |
696 | - //cv::putText(batch_mat[b], str_phone, | |
697 | - // cv::Point(5, 200), | |
698 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
699 | - // 1.3, | |
700 | - // cv::Scalar(255, 0, 0), | |
701 | - // 2); | |
702 | - | |
703 | - //系安全带,阈值0.5 | |
704 | - std::string str_belt="UNCERTAINTY"; | |
705 | - if(cur_result.driver.belt.status==lEGAL) | |
706 | - str_belt ="lEGAL";//str_belt ="SAFETYBELT"; | |
707 | - else if(cur_result.driver.belt.status==ILLEGAL) | |
708 | - str_belt ="ILLEGAL";//str_belt ="NOSAFETYBELT"; | |
709 | - | |
710 | - //cv::putText(batch_mat[b], str_belt, | |
711 | - // cv::Point(5, 200), | |
712 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
713 | - // 1.3, | |
714 | - // cv::Scalar(255, 0, 0), | |
715 | - // 2); | |
716 | - | |
717 | - //抽烟,阈值0.9 | |
718 | - std::string str_smoke="UNCERTAINTY"; | |
719 | - if(cur_result.driver.smoke.status==ILLEGAL) | |
720 | - str_smoke ="ILLEGAL";//str_smoke ="SMOKE"; | |
721 | - else if(cur_result.driver.smoke.status==lEGAL) | |
722 | - str_smoke ="lEGAL";//str_smoke ="NOSMOKE"; | |
723 | - //cv::putText(batch_mat[b], str_smoke, | |
724 | - // cv::Point(5, 225), | |
725 | - // cv::FONT_HERSHEY_COMPLEX_SMALL, | |
726 | - // 1.3, | |
727 | - // cv::Scalar(255, 0, 0), | |
728 | - // 2); | |
729 | - | |
730 | - //std::cout << "driver: "<<str_person<< " "<<str_call<< " "<<str_phone<< " "<<str_belt<< " "<<str_smoke<< std::endl; | |
731 | - //std::cout << "driver confidence: "<<cur_result.driver.person.confidence<< " "<<cur_result.driver.call.confidence<< " "<<cur_result.driver.phone.confidence<< " "<<cur_result.driver.belt.confidence<< " "<<cur_result.driver.smoke.confidence<< std::endl; | |
732 | - std::cout << " driver: person:"<<str_person<< " call:"<<str_call<< " phone:"<<str_phone<< " belt:"<<str_belt<< " smoke:"<<str_smoke<< std::endl; | |
733 | - std::cout << " driver confidence: person:"<<cur_result.driver.person.confidence<< " call:"<<cur_result.driver.call.confidence<< " phone:"<<cur_result.driver.phone.confidence<< " belt:"<<cur_result.driver.belt.confidence<< " smoke:"<<cur_result.driver.smoke.confidence<< std::endl; | |
734 | - | |
735 | - } | |
736 | - } | |
737 | - | |
738 | - | |
739 | - | |
740 | - | |
741 | - //8.车特征 | |
742 | - if(param.vehicle_feature_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1)) | |
743 | - { | |
744 | - std::cout << " vehicle_fea_res info: "<<std::endl; | |
745 | - std::cout << " ["; | |
746 | - for(int f=0;f<VA_FEATURESIZE;f++) | |
747 | - { | |
748 | - float fea=result[b].info[c].vehicle_fea_res.feature[f]; | |
749 | - //std::cout << "feature "<<f<<":"<<fea<<std::endl; | |
750 | - std::cout <<fea<<" "; | |
751 | - } | |
752 | - std::cout <<"]"<<std::endl; | |
753 | - //std::cout << "feature 0 :"<<result[b].info[c].vehicle_fea_res.feature[0]<<std::endl; | |
754 | - //std::cout << "feature 1 :"<<result[b].info[c].vehicle_fea_res.feature[1]<<std::endl; | |
755 | - //std::cout << "feature 2 :"<<result[b].info[c].vehicle_fea_res.feature[2]<<std::endl; | |
756 | - //std::cout << "feature 3 :"<<result[b].info[c].vehicle_fea_res.feature[3]<<std::endl; | |
757 | - //std::cout << "feature 4 :"<<result[b].info[c].vehicle_fea_res.feature[4]<<std::endl; | |
758 | - //std::cout << "feature 5 :"<<result[b].info[c].vehicle_fea_res.feature[5]<<std::endl; | |
759 | - | |
760 | - //test | |
761 | - //for(int f=0;f<10;f++) | |
762 | - //{ | |
763 | - // float fea=result[b].info[c].vehicle_fea_res.feature[f]; | |
764 | - // std::cout << "feature "<<f<<":"<<fea<<std::endl; | |
765 | - //} | |
766 | - } | |
767 | - | |
768 | - //11.摩托车三轮车分析 | |
769 | - if(param.vehicle_motor_tricycle_analysis_config==SY_CONFIG_OPEN && (vehicle_type==2 || vehicle_type==3)) | |
770 | - { | |
771 | - //std::cout << "mta output----"<< std::endl; | |
772 | - | |
773 | - if(vehicle_type==2)//摩托车 | |
774 | - { | |
775 | - //摩托车载人 | |
776 | - //int status=result[b].info[c].mta_res.motor_manned.status; | |
777 | - //float score=result[b].info[c].mta_res.motor_manned.confidence; | |
778 | - //if(status == MOTOR_MANNED) | |
779 | - // std::cout << "motor info: MOTOR_MANNED, prob: " << score << std::endl; | |
780 | - //else if(status == MOTOR_NOT_MANNED) | |
781 | - // std::cout << "motor info: MOTOR_NOT_MANNED, prob: " << score << std::endl; | |
782 | - | |
783 | - //摩托车驾驶人是否戴安全帽 | |
784 | - int status=result[b].info[c].mta_res.motor_driver_helmeted.status; | |
785 | - float score=result[b].info[c].mta_res.motor_driver_helmeted.confidence; | |
786 | - if(status == MOTOR_DRIVER_HELMETED) | |
787 | - std::cout << " motor info: MOTOR_DRIVER_HELMETED, prob: " << score << std::endl; | |
788 | - else if(status == MOTOR_DRIVER_NOT_HELMETED) | |
789 | - std::cout << " motor info: MOTOR_DRIVER_NOT_HELMETED, prob: " << score << std::endl; | |
790 | - | |
791 | - } | |
792 | - } | |
793 | - //载人输出 | |
794 | - //if(param.vehicle_manned_config==SY_CONFIG_OPEN && (vehicle_type==0 || vehicle_type==1 || vehicle_type==3)) | |
795 | - if(param.vehicle_manned_config==SY_CONFIG_OPEN && vehicle_type!=5) | |
796 | - { | |
797 | - std::cout << "----------------------manned output----"<< std::endl; | |
798 | - int hs_count = result[b].info[c].manned_res.hs_count; | |
799 | - std::cout <<"manned_hs_count:"<< hs_count << std::endl; | |
800 | - for(int lo=0;lo<hs_count;lo++) | |
801 | - { | |
802 | - int x1=result[b].info[c].manned_res.hs_rect[lo].rect.left_; | |
803 | - int y1=result[b].info[c].manned_res.hs_rect[lo].rect.top_; | |
804 | - int x2=result[b].info[c].manned_res.hs_rect[lo].rect.left_+result[b].info[c].manned_res.hs_rect[lo].rect.width_; | |
805 | - int y2=result[b].info[c].manned_res.hs_rect[lo].rect.top_+result[b].info[c].manned_res.hs_rect[lo].rect.height_; | |
806 | - | |
807 | - std::cout <<"manned_hs_rect:"<< x1 <<" "<< y1<<" " <<x2<<" " << y2<< std::endl; | |
808 | - | |
809 | - Point lt(x1, y1); | |
810 | - Point rb(x2, y2); | |
811 | - rectangle(cvImg, lt, rb, cv::Scalar(0, 255, 255), 4); | |
812 | - } | |
813 | - } | |
814 | - } | |
815 | - | |
816 | - //测试相似度比对函数,batch_size设为2 | |
817 | - //double similarity=va_compute_similarity(result[0].info[0].vehicle_fea_res.feature, result[1].info[0].vehicle_fea_res.feature, FEATURESIZE); | |
818 | - //std::cout << "similarity: "<<similarity<<std::endl; | |
819 | - | |
820 | - | |
821 | - | |
822 | - //cv::Mat showImg; | |
823 | - //showImg=batch_mat[b].clone(); | |
824 | - //cv::resize(batch_mat[b], showImg, cv::Size(batch_mat[b].cols/2,batch_mat[b].rows/2)); | |
825 | - //cv::imshow("image", showImg); | |
826 | - //cv::waitKey(0); | |
827 | - cv::imwrite((saveimagepath+file).c_str(),cvImg); | |
828 | - | |
829 | - } | |
830 | - | |
831 | - | |
832 | - | |
833 | - | |
834 | - | |
835 | - | |
836 | - //delete result | |
837 | - for(int b=0;b<batch_size;b++) | |
838 | - { | |
839 | - for(int c=0; c<100; c++) | |
840 | - { | |
841 | - if(result[b].info[c].vehicle_pendant_det_res.vpd_res!=NULL) | |
842 | - delete[] result[b].info[c].vehicle_pendant_det_res.vpd_res; | |
843 | - | |
844 | - } | |
845 | - if(result[b].info!=NULL) | |
846 | - delete[] result[b].info; | |
847 | - } | |
848 | - if(result!=NULL) | |
849 | - delete[] result; | |
850 | - | |
851 | - } | |
852 | -} | |
853 | - | |
854 | - std::cout << "va_release---------------------"<< std::endl; | |
855 | - va_release(&handle); | |
856 | - //va_release(&handle111); | |
857 | - va_acl_release(); | |
858 | - | |
859 | - printf("va_teat info:va_batch time: t3=%.2f\n", t3/count); | |
860 | - | |
861 | - //oFile.close(); | |
862 | - | |
863 | - return 0; | |
864 | -} |
src/demo/main.cpp
src/village_inc.h
... | ... | @@ -5,10 +5,13 @@ |
5 | 5 | #include <vector> |
6 | 6 | #include "vehicle_analysis.h" |
7 | 7 | |
8 | +#include "opencv2/opencv.hpp" | |
9 | +#include "opencv2/imgcodecs/legacy/constants_c.h" | |
10 | +#include "opencv2/imgproc/types_c.h" | |
11 | + | |
8 | 12 | struct VillageParam { |
9 | 13 | int dev_id; |
10 | - std::string db_path; | |
11 | - std::string model_path; | |
14 | + std::string sdk_path; | |
12 | 15 | }; |
13 | 16 | |
14 | 17 | typedef struct pendant_info |
... | ... | @@ -57,12 +60,12 @@ typedef struct VehicleInfo { |
57 | 60 | |
58 | 61 | struct LineInfo{ |
59 | 62 | int line_type; |
60 | - std::vector<sy_point> vec_pt; | |
63 | + std::vector<cv::Point> vec_pt; | |
61 | 64 | }; |
62 | 65 | |
63 | 66 | struct SegInfo { |
64 | 67 | int seg_type; |
65 | - std::vector<sy_point> vec_pt; | |
68 | + std::vector<cv::Point> vec_pt; | |
66 | 69 | }; |
67 | 70 | |
68 | 71 | typedef struct AnalysisResult { | ... | ... |