Skip to content

Commit 4090c64

Browse files
lianglia-apollostartcode
authored andcommitted
Perception: used proto for multi_camera_projection. (ApolloAuto#4132)
1 parent 62a292c commit 4090c64

13 files changed

+131
-111
lines changed

modules/perception/common/perception_gflags.cc

+4
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,7 @@ DEFINE_string(hdmap_roi_filter_config,
178178
DEFINE_string(low_object_filter_config,
179179
"modules/perception/model/low_object_filter_config.pb.txt",
180180
"low object filter config filename.");
181+
DEFINE_string(traffic_light_multi_camera_projection_config,
182+
"modules/perception/model/traffic_light/"
183+
"multi_camera_projection_config.pb.txt",
184+
"traffic light multi camera projection config filename.");

modules/perception/common/perception_gflags.h

+1
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,6 @@ DECLARE_string(geometry_camera_converter_config);
124124
DECLARE_string(cnn_segmentation_config);
125125
DECLARE_string(hdmap_roi_filter_config);
126126
DECLARE_string(low_object_filter_config);
127+
DECLARE_string(traffic_light_multi_camera_projection_config);
127128

128129
#endif // MODULES_PERCEPTION_COMMON_PERCEPTION_GFLAGS_H_

modules/perception/conf/config_manager.config

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
model_config_path: "model/traffic_light/multi_camera_projection.config"
21
model_config_path: "model/traffic_light/recognizer.config"
32
model_config_path: "model/traffic_light/rectifier.config"
43
model_config_path: "model/traffic_light/reviser.config"

modules/perception/model/low_object_filter.config

-21
This file was deleted.

modules/perception/model/traffic_light/multi_camera_projection.config

-41
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
multi_camera_projection_config: {
2+
name: "MultiCamerasProjection"
3+
version: "1.0.0"
4+
single_projection: "BoundaryProjection"
5+
camera_focus_config: {
6+
name: "camera_25mm_focus"
7+
camera_extrinsic_file: "modules/perception/data/params/long_camera_extrinsics.yaml"
8+
camera_intrinsic_file: "modules/perception/data/params/long_camera_intrinsics.yaml"
9+
}
10+
camera_focus_config: {
11+
name: "camera_6mm_focus"
12+
camera_extrinsic_file: "modules/perception/data/params/short_camera_extrinsics.yaml"
13+
camera_intrinsic_file: "modules/perception/data/params/short_camera_intrinsics.yaml"
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
cc_proto_library(
4+
name = "multi_camera_projection_config_lib_proto",
5+
deps = [
6+
":multi_camera_projection_config_lib",
7+
],
8+
)
9+
10+
proto_library(
11+
name = "multi_camera_projection_config_lib",
12+
srcs = [
13+
"multi_camera_projection_config.proto",
14+
],
15+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
syntax = "proto2";
2+
3+
package apollo.perception.traffic_light.multi_camera_projection_config;
4+
5+
message CameraFocusConfig {
6+
optional string name = 1;
7+
optional string camera_extrinsic_file = 2;
8+
optional string camera_intrinsic_file = 3;
9+
}
10+
11+
message MultiCamerasProjectionConfig {
12+
optional string name = 1 [ default = "MultiCamerasProjection" ];
13+
optional string version = 2 [ default = "1.0.0" ];
14+
optional string single_projection = 3 [ default = "BoundaryProjection" ];
15+
repeated string camera_names = 4;
16+
repeated CameraFocusConfig camera_focus_config = 5;
17+
}
18+
19+
message ModelConfigs {
20+
optional MultiCamerasProjectionConfig multi_camera_projection_config = 1;
21+
}

modules/perception/traffic_light/projection/BUILD

+19
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,28 @@ cc_library(
1919
"//modules/map/proto:map_proto",
2020
"//modules/perception/lib/config_manager",
2121
"//modules/perception/proto:perception_proto",
22+
"//modules/perception/proto/traffic_light:multi_camera_projection_config_lib_proto",
2223
"//modules/perception/traffic_light/base",
2324
"//modules/perception/traffic_light/interface",
2425
],
2526
)
2627

28+
cc_test(
29+
name = "multi_camera_projection_test",
30+
size = "small",
31+
srcs = [
32+
"multi_camera_projection_test.cc",
33+
],
34+
data = [
35+
"//modules/perception:perception_data",
36+
"//modules/perception:perception_model",
37+
"//modules/perception/conf:perception_config",
38+
],
39+
deps = [
40+
"perception_traffic_light_projection",
41+
"//modules/perception/lib/base",
42+
"@gtest//:main",
43+
],
44+
)
45+
2746
cpplint()

modules/perception/traffic_light/projection/multi_camera_projection.cc

+17-46
Original file line numberDiff line numberDiff line change
@@ -20,69 +20,40 @@
2020
#include "Eigen/Core"
2121
#include "Eigen/Dense"
2222

23+
#include "modules/common/util/file.h"
2324
#include "modules/perception/traffic_light/base/tl_shared_data.h"
2425

2526
namespace apollo {
2627
namespace perception {
2728
namespace traffic_light {
2829

30+
using apollo::common::util::GetProtoFromFile;
31+
2932
bool MultiCamerasProjection::Init() {
30-
ConfigManager *config_manager = ConfigManager::instance();
31-
std::string model_name = "MultiCamerasProjection";
32-
const ModelConfig *model_config = config_manager->GetModelConfig(model_name);
33-
if (model_config == nullptr) {
34-
AERROR << "not found model: " << model_name;
33+
if (!GetProtoFromFile(FLAGS_traffic_light_multi_camera_projection_config,
34+
&config_)) {
35+
AERROR << "Cannot get config proto from file: "
36+
<< FLAGS_traffic_light_multi_camera_projection_config;
3537
return false;
3638
}
37-
3839
// Read camera names from config file
39-
std::vector<std::string> camera_names;
40-
std::string single_projection_name;
41-
if (!model_config->GetValue("camera_names", &camera_names)) {
42-
AERROR << "camera_names not found." << name();
43-
return false;
44-
}
45-
if (!model_config->GetValue("SingleProjection", &single_projection_name)) {
46-
AERROR << "SingleProjection not found." << name();
47-
return false;
48-
}
49-
50-
AINFO << "number of camera_names: " << camera_names.size();
51-
AINFO << "SingleProjection name: " << single_projection_name;
40+
const std::string &single_projection_name =
41+
config_.multi_camera_projection_config().single_projection();
5242

5343
// Read each camera's config
54-
std::string camera_extrinsic_file;
55-
std::string camera_intrinsic_file;
5644
std::unordered_map<std::string, CameraCoeffient> camera_coeffients;
57-
for (size_t i = 0; i < camera_names.size(); ++i) {
58-
const auto &camera_model_name = camera_names[i];
59-
const ModelConfig *camera_model_config =
60-
config_manager->GetModelConfig(camera_model_name);
61-
if (camera_model_config == nullptr) {
62-
AERROR << "not found camera model: " << camera_model_name;
63-
return false;
64-
}
65-
66-
if (!camera_model_config->GetValue("camera_extrinsic_file",
67-
&camera_extrinsic_file)) {
68-
AERROR << "camera_extrinsic_file not found." << name();
69-
return false;
70-
}
71-
if (!camera_model_config->GetValue("camera_intrinsic_file",
72-
&camera_intrinsic_file)) {
73-
AERROR << "camera_intrinsic_file not found." << name();
74-
return false;
75-
}
76-
45+
for (const auto &camera_focus_config :
46+
config_.multi_camera_projection_config().camera_focus_config()) {
47+
const auto &camera_model_name = camera_focus_config.name();
7748
CameraCoeffient camera_coeffient;
78-
if (!camera_coeffient.init(camera_model_name, camera_extrinsic_file,
79-
camera_intrinsic_file)) {
49+
if (!camera_coeffient.init(camera_model_name,
50+
camera_focus_config.camera_extrinsic_file(),
51+
camera_focus_config.camera_intrinsic_file())) {
8052
AERROR << camera_model_name << " Projection init failed.";
8153
return false;
8254
}
83-
AINFO << "init " << camera_names[i] << " coeffient succeeded.";
84-
camera_coeffients[camera_names[i]] = camera_coeffient;
85-
camera_names_.push_back(camera_names[i]);
55+
camera_coeffients[camera_model_name] = camera_coeffient;
56+
camera_names_.push_back(camera_model_name);
8657
}
8758

8859
projection_.reset(

modules/perception/traffic_light/projection/multi_camera_projection.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
#include <string>
2222
#include <vector>
2323

24-
#include "modules/perception/lib/config_manager/config_manager.h"
24+
#include "modules/perception/proto/traffic_light/multi_camera_projection_config.pb.h"
25+
2526
#include "modules/perception/traffic_light/interface/base_projection.h"
2627

2728
namespace apollo {
@@ -42,6 +43,8 @@ class MultiCamerasProjection {
4243
std::vector<CameraCoeffient> camera_coeffient_;
4344
std::vector<std::string> camera_names_;
4445
std::unique_ptr<BaseProjection> projection_;
46+
47+
traffic_light::multi_camera_projection_config::ModelConfigs config_;
4548
};
4649

4750
} // namespace traffic_light
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/******************************************************************************
2+
* Copyright 2018 The Apollo Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*****************************************************************************/
16+
#include "modules/perception/traffic_light/projection/multi_camera_projection.h"
17+
18+
#include "gtest/gtest.h"
19+
20+
#include "modules/perception/traffic_light/projection/projection.h"
21+
22+
namespace apollo {
23+
namespace perception {
24+
namespace traffic_light {
25+
26+
TEST(MultiCameraProjectionTest, load_proto) {
27+
RegisterFactoryBoundaryProjection();
28+
MultiCamerasProjection mc_projection;
29+
EXPECT_TRUE(mc_projection.Init());
30+
}
31+
32+
} // namespace traffic_light
33+
} // namespace perception
34+
} // namespace apollo

modules/perception/traffic_light/reviser/color_decision_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DecisionTest : public ::testing::Test {
2525
protected:
2626
virtual void SetUp() {
2727
reviser_ = new ColorReviser;
28-
ASSERT_TRUE(reviser_->Init());
28+
EXPECT_TRUE(reviser_->Init());
2929
AINFO << "Setup";
3030
}
3131
~DecisionTest() { delete reviser_; }

0 commit comments

Comments
 (0)