Skip to content

Commit 4265e73

Browse files
author
wangfanghao
committed
feat(perception): add traffic light offline tool
Change-Id: I818ff10ea44cbd22d3730745eda6ab5ae2c997bb
1 parent 55d3282 commit 4265e73

File tree

12 files changed

+309
-13
lines changed

12 files changed

+309
-13
lines changed

modules/perception/camera/tools/common/util.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ bool GetFileListFromFile(
9999
return true;
100100
}
101101

102-
bool SaveResult(CameraFrame* frame, const std::string& file_name) {
102+
bool SaveCameraDetectionResult(
103+
CameraFrame* frame, const std::string& file_name) {
103104
FILE *fp = fopen(file_name.c_str(), "w");
104105
if (fp == nullptr) {
105106
AERROR << "Failed to open result file: " << file_name;
@@ -128,6 +129,14 @@ bool SaveResult(CameraFrame* frame, const std::string& file_name) {
128129
return true;
129130
}
130131

132+
bool SaveTfDetectionResult(CameraFrame* frame, const std::string& file_name) {
133+
return true;
134+
}
135+
136+
bool SaveLaneDetectionResult(CameraFrame* frame, const std::string& file_name) {
137+
return true;
138+
}
139+
131140
} // namespace camera
132141
} // namespace perception
133142
} // namespace apollo

modules/perception/camera/tools/common/util.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ bool GetFileListFromFile(
9090
* @return true
9191
* @return false
9292
*/
93-
bool SaveResult(CameraFrame* frame, const std::string& file_name);
93+
bool SaveCameraDetectionResult(CameraFrame* frame, const std::string& file_name);
94+
95+
bool SaveTfDetectionResult(CameraFrame* frame, const std::string& file_name);
96+
97+
bool SaveLaneDetectionResult(CameraFrame* frame, const std::string& file_name);
9498

9599
} // namespace camera
96100
} // namespace perception

modules/perception/camera/tools/common/visualizer.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static const cv::Scalar kFaceColors[] = {
3535
cv::Scalar(0, 0, 255), // red
3636
};
3737

38-
bool Visualization(CameraFrame* frame, const std::string& file_name) {
38+
bool CameraVisualization(CameraFrame* frame, const std::string& file_name) {
3939
cv::Mat cv_img(frame->data_provider->src_height(),
4040
frame->data_provider->src_width(),
4141
CV_8UC3, cv::Scalar(0, 0, 0));
@@ -109,6 +109,14 @@ bool Visualization(CameraFrame* frame, const std::string& file_name) {
109109
return true;
110110
}
111111

112+
bool TfVisualization(CameraFrame* frame, const std::string& file_name) {
113+
return true;
114+
}
115+
116+
bool LaneVisualization(CameraFrame* frame, const std::string& file_name) {
117+
return true;
118+
}
119+
112120
} // namespace camera
113121
} // namespace perception
114122
} // namespace apollo

modules/perception/camera/tools/common/visualizer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ namespace camera {
3232
* @return true
3333
* @return false
3434
*/
35-
bool Visualization(CameraFrame* frame, const std::string& file_name);
35+
bool CameraVisualization(CameraFrame* frame, const std::string& file_name);
36+
37+
bool TfVisualization(CameraFrame* frame, const std::string& file_name);
38+
39+
bool LaneVisualization(CameraFrame* frame, const std::string& file_name);
3640

3741
} // namespace camera
3842
} // namespace perception

modules/perception/camera/tools/lane_detection/lane_denseline_eval.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ bool SaveLaneCCS(
5454
std::vector<unsigned char> lane_map;
5555
std::vector<ConnectedComponent> lane_ccs;
5656
std::vector<ConnectedComponent> select_lane_ccs;
57-
lane_postprocessor->GetLaneCCs(&lane_map, &lane_map_width, &lane_map_height,
58-
&lane_ccs, &select_lane_ccs);
57+
// Todo(daohu527): need fix, denseline only
58+
// lane_postprocessor->GetLaneCCs(&lane_map, &lane_map_width, &lane_map_height,
59+
// &lane_ccs, &select_lane_ccs);
5960
std::string save_img_path = absl::StrCat(FLAGS_save_dir, "/",
6061
FLAGS_file_title, "_2_",
6162
FLAGS_file_ext_name, ".jpg");
@@ -70,14 +71,18 @@ bool SaveDetectPointSet(
7071
std::string save_img_path = absl::StrCat(FLAGS_save_dir, "/",
7172
FLAGS_file_title, "_0_",
7273
FLAGS_file_ext_name, ".jpg");
73-
const std::vector<LanePointInfo>& infer_point_set =
74-
lane_postprocessor->GetAllInferLinePointSet();
74+
// Todo(daohu527): need fix, denseline only
75+
const std::vector<LanePointInfo> infer_point_set;
76+
// const std::vector<LanePointInfo>& infer_point_set =
77+
// lane_postprocessor->GetAllInferLinePointSet();
7578
show_all_infer_point_set(img, infer_point_set, save_img_path);
7679

7780
save_img_path = absl::StrCat(FLAGS_save_dir, "/", FLAGS_file_title, "_1_",
7881
FLAGS_file_ext_name, ".jpg");
79-
const std::vector<std::vector<LanePointInfo>>& detect_laneline_point_set =
80-
lane_postprocessor->GetLanelinePointSet();
82+
// Todo(daohu527): need fix, denseline only
83+
const std::vector<std::vector<LanePointInfo>> detect_laneline_point_set;
84+
// const std::vector<std::vector<LanePointInfo>>& detect_laneline_point_set =
85+
// lane_postprocessor->GetLanelinePointSet();
8186
show_detect_point_set(img, detect_laneline_point_set, save_img_path);
8287
AINFO << "detect_laneline_point_set num: "
8388
<< detect_laneline_point_set.size();

modules/perception/camera/tools/obstacle_detection/obstacle_detection.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ DEFINE_string(root_dir, "/apollo/modules/perception/camera/tools/obstacle_detect
3939
DEFINE_string(image_ext, ".jpg", "extension of image name");
4040
DEFINE_string(test_list, "/apollo/modules/perception/camera/tools/obstacle_detection/images/image_test_list.txt", "test image list");
4141
DEFINE_string(obstacle_detection_conf_file, "/apollo/modules/perception/camera/tools/obstacle_detection/conf/camera_detection_pipeline.pb.txt", "Camera perception config file");
42-
DEFINE_string(camera_intrinsics, "/apollo/modules/perception/camera/tools/obstacle_detection/params/onsemi_narrow_intrinsics.yaml", "Camera intrinsic file");
42+
DEFINE_string(camera_intrinsics, "/apollo/modules/perception/camera/tools/obstacle_detection/params/onsemi_obstacle_intrinsics.yaml", "Camera intrinsic file");
4343

4444
namespace apollo {
4545
namespace perception {
@@ -101,10 +101,10 @@ void TestDetection() {
101101

102102
// Results visualization
103103
std::string result_path = FLAGS_dest_dir + "/" + image_name + ".txt";
104-
ACHECK(SaveResult(&camera_frame, result_path));
104+
ACHECK(SaveCameraDetectionResult(&camera_frame, result_path));
105105

106106
result_path = FLAGS_dest_dir + "/" + image_name + ".jpg";
107-
ACHECK(Visualization(&camera_frame, result_path));
107+
ACHECK(CameraVisualization(&camera_frame, result_path));
108108
}
109109
}
110110

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary")
2+
load("//tools:cpplint.bzl", "cpplint")
3+
4+
package(default_visibility = ["//visibility:public"])
5+
6+
cc_binary(
7+
name = "traffic_light_detection",
8+
srcs = ["traffic_light_detection.cc"],
9+
deps = [
10+
"//cyber",
11+
"//modules/perception/camera/app:traffic_light_camera_perception",
12+
"//modules/perception/camera/tools/common",
13+
"//modules/perception/common:perception_gflags",
14+
"//modules/perception/pipeline/proto:pipeline_config_cc_proto",
15+
"@com_github_gflags_gflags//:gflags",
16+
],
17+
)
18+
19+
cpplint()

modules/perception/camera/tools/traffic_light_detection/README.md

Whitespace-only changes.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
stage_type: TRAFFIC_LIGHT_DETECTION
2+
stage_type: TRAFFIC_LIGHT_RECOGNITION
3+
stage_type: SEMANTIC_REVISER
4+
5+
stage_config: {
6+
stage_type: TRAFFIC_LIGHT_DETECTION
7+
enabled: true
8+
9+
traffic_light_detection_config: {
10+
min_crop_size: 270
11+
crop_method: 0
12+
mean_r: 122.7717
13+
mean_g: 115.9465
14+
mean_b: 102.9801
15+
is_bgr:true
16+
crop_scale: 2.5
17+
input_blob_name : "img"
18+
im_param_blob_name : "im_info"
19+
output_blob_name : "bboxes"
20+
model_name: "./"
21+
model_type: "RTNet"
22+
proto_file:"deploy.prototxt"
23+
weight_file: "baidu_iter_140000.caffemodel"
24+
max_batch_size: 1 # only support 1 so far
25+
traffic_light_detection_root_dir: "/apollo/modules/perception/production/data/perception/camera/models/traffic_light_detection/tl_detection_caffe"
26+
gpu_id: 0
27+
}
28+
}
29+
30+
stage_config: {
31+
stage_type: TRAFFIC_LIGHT_RECOGNITION
32+
enabled: true
33+
34+
traffic_light_recognition_config: {
35+
vertical_model{
36+
model_name: "./";
37+
model_type: "RTNet";
38+
input_blob: "data_org";
39+
output_blob: "prob";
40+
weight_file: "vertical_caffe/baidu_iter_250000.caffemodel";
41+
proto_file: "vertical_caffe/deploy.prototxt";
42+
classify_threshold: 0.5;
43+
classify_resize_width: 32;
44+
classify_resize_height: 96;
45+
mean_r: 69.06;
46+
mean_g: 66.58;
47+
mean_b: 66.56;
48+
is_bgr: true;
49+
scale: 0.01
50+
traffic_light_recognition_root_dir: "/apollo/modules/perception/production/data/perception/camera/models/traffic_light_recognition"
51+
gpu_id: 0
52+
}
53+
54+
quadrate_model{
55+
model_name: "./";
56+
model_type: "RTNet";
57+
input_blob: "data_org";
58+
output_blob: "prob";
59+
weight_file: "quadrate_caffe/baidu_iter_200000.caffemodel";
60+
proto_file: "quadrate_caffe/deploy.prototxt";
61+
classify_threshold: 0.5;
62+
classify_resize_width: 64;
63+
classify_resize_height: 64;
64+
mean_r: 69.06;
65+
mean_g: 66.58;
66+
mean_b: 66.56;
67+
is_bgr: true;
68+
scale: 0.01
69+
traffic_light_recognition_root_dir: "/apollo/modules/perception/production/data/perception/camera/models/traffic_light_recognition"
70+
gpu_id: 0
71+
}
72+
73+
horizontal_model{
74+
model_name: "./";
75+
model_type: "RTNet";
76+
input_blob: "data_org";
77+
output_blob: "prob";
78+
weight_file: "horizontal_caffe/baidu_iter_200000.caffemodel";
79+
proto_file: "horizontal_caffe/deploy.prototxt";
80+
classify_threshold: 0.5;
81+
classify_resize_width: 96;
82+
classify_resize_height: 32;
83+
mean_r: 69.06;
84+
mean_g: 66.58;
85+
mean_b: 66.56;
86+
is_bgr: true;
87+
scale: 0.01
88+
traffic_light_recognition_root_dir: "/apollo/modules/perception/production/data/perception/camera/models/traffic_light_recognition"
89+
gpu_id: 0
90+
}
91+
}
92+
}
93+
94+
stage_config: {
95+
stage_type: SEMANTIC_REVISER
96+
enabled: true
97+
98+
semantic_reviser_config: {
99+
revise_time_second: 1.5
100+
blink_threshold_second: 0.55
101+
hysteretic_threshold_count: 1
102+
#yellow_blink_threshold_second: 10.0
103+
traffic_light_semantic_root_dir: "/apollo/modules/perception/production/data/perception/camera/models/traffic_light_tracker"
104+
}
105+
}
106+
107+
traffic_light_config: {
108+
trafficlights_perception_config: {
109+
gpu_id: 0
110+
}
111+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
red

0 commit comments

Comments
 (0)