Apollo  6.0
Open source self driving car software
lane_detection_component.h
Go to the documentation of this file.
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 #pragma once
17 
18 #include <map>
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
24 #include "Eigen/Core"
25 #include "Eigen/Dense"
26 #include "Eigen/StdVector"
27 
31 #include "modules/drivers/proto/sensor_image.pb.h"
36 #include "modules/perception/camera/app/proto/perception.pb.h"
43 #include "modules/perception/onboard/proto/lane_perception_component.pb.h"
45 #include "modules/perception/proto/motion_service.pb.h"
46 #include "modules/perception/proto/perception_lane.pb.h"
47 
50 typedef std::shared_ptr<apollo::perception::Motion_Service>
52 
53 namespace apollo {
54 namespace perception {
55 namespace onboard {
56 
58 
62  public:
63  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
64 
65  public:
66  LaneDetectionComponent() : seq_num_(0) {}
68 
71 
72  bool Init() override;
73 
74  template <typename T>
75  friend class FunctionInfo;
76 
77  private:
78  void OnReceiveImage(const std::shared_ptr<apollo::drivers::Image>& in_message,
79  const std::string& camera_name);
80  void OnMotionService(const MotionServiceMsgType& in_message);
81  int InitConfig();
82  int InitSensorInfo();
83  int InitAlgorithmPlugin();
84  int InitCameraFrames();
85  int InitProjectMatrix();
86  int InitMotionService();
87  int InitCameraListeners();
88  void SetCameraHeightAndPitch();
89 
90  int InternalProc(
91  const std::shared_ptr<apollo::drivers::Image const>& in_message,
92  const std::string& camera_name, apollo::common::ErrorCode* error_code,
93  SensorFrameMessage* prefused_message,
94  apollo::perception::PerceptionLanes* out_message);
95 
96  int ConvertLaneToCameraLaneline(
97  const base::LaneLine& lane_line,
98  apollo::perception::camera::CameraLaneLine* camera_laneline);
99 
100  int MakeProtobufMsg(double msg_timestamp, const std::string& camera_name,
101  const camera::CameraFrame& camera_frame,
102  apollo::perception::PerceptionLanes* lanes_msg);
103 
104  private:
105  std::mutex mutex_;
106  uint32_t seq_num_;
107 
108  std::vector<std::shared_ptr<cyber::Node>> camera_listener_nodes_;
109 
110  std::vector<std::string> camera_names_; // camera sensor names
111  std::vector<std::string> input_camera_channel_names_;
112 
113  // camera name -> SensorInfo
114  std::map<std::string, base::SensorInfo> sensor_info_map_;
115 
116  // camera_height
117  std::map<std::string, float> camera_height_map_;
118 
119  // camera_pitch_angle_diff
120  std::map<std::string, float> name_camera_pitch_angle_diff_map_;
121 
122  // TF stuff
123  std::map<std::string, std::string> tf_camera_frame_id_map_;
124  std::map<std::string, std::shared_ptr<TransformWrapper>>
125  camera2world_trans_wrapper_map_;
126 
127  // pre-allocaated-mem data_provider;
128  std::map<std::string, std::shared_ptr<camera::DataProvider>>
129  data_providers_map_;
130 
131  // map for store params
132  EigenMap<std::string, Eigen::Matrix4d> extrinsic_map_;
133  EigenMap<std::string, Eigen::Matrix3f> intrinsic_map_;
134  Eigen::Matrix3d homography_image2ground_;
135 
136  // camera lane pipeline
137  camera::CameraPerceptionInitOptions camera_perception_init_options_;
138  camera::CameraPerceptionOptions camera_perception_options_;
139  std::unique_ptr<camera::LaneCameraPerception> camera_lane_pipeline_;
140 
141  // fixed size camera frames
142  int frame_capacity_ = 20;
143  int frame_id_ = 0;
144  EigenVector<camera::CameraFrame> camera_frames_;
145 
146  // image info.
147  int image_width_ = 1920;
148  int image_height_ = 1080;
149  int image_channel_num_ = 3;
150  int image_data_size_ = -1;
151 
152  // default camera pitch angle & height
153  float default_camera_pitch_ = 0.f;
154  float default_camera_height_ = 1.6f;
155 
156  // options for DataProvider
157  bool enable_undistortion_ = false;
158 
159  double timestamp_offset_ = 0.0;
160 
161  bool enable_visualization_ = false;
162  std::string visual_debug_folder_;
163  std::string visual_camera_;
164 
165  std::string output_lanes_channel_name_;
166 
167  Eigen::Matrix3d project_matrix_;
168  double pitch_diff_ = 0.0;
169 
170  double last_timestamp_ = 0.0;
171  double ts_diff_ = 1.0;
172 
173  std::shared_ptr<apollo::cyber::Writer<apollo::perception::PerceptionLanes>>
174  writer_;
175 
176  base::MotionBufferPtr mot_buffer_;
177  const int motion_buffer_size_ = 100;
178 
179  camera::Visualizer visualize_;
180  bool write_visual_img_;
181  static FunInfoType init_func_arry_[];
182 };
183 
185 
186 } // namespace onboard
187 } // namespace perception
188 } // namespace apollo
Definition: lane_struct.h:69
std::vector< EigenType, Eigen::aligned_allocator< EigenType > > EigenVector
Definition: eigen_defs.h:32
Definition: camera_frame.h:33
LaneDetectionComponent()
Definition: lane_detection_component.h:66
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: base_camera_perception.h:28
Eigen::Matrix4d Matrix4d
Definition: base_map_fwd.h:32
std::map< T, EigenType, std::less< T >, Eigen::aligned_allocator< std::pair< const T, EigenType > >> EigenMap
Definition: eigen_defs.h:36
Definition: inner_component_messages.h:49
Definition: visualizer.h:39
Definition: lane_detection_component.h:61
Eigen::Matrix4d MotionType
Definition: lane_detection_component.h:57
std::shared_ptr< MotionBuffer > MotionBufferPtr
Definition: object_supplement.h:203
FunctionInfo< LaneDetectionComponent > FunInfoType
Definition: lane_detection_component.h:59
Definition: util.h:136
std::shared_ptr< apollo::perception::Motion_Service > MotionServiceMsgType
Definition: camera_obstacle_detection_component.h:45
Some util functions.
Eigen::Matrix3d Matrix3d
Definition: base_map_fwd.h:33
Definition: base_camera_perception.h:34
The Component can process up to four channels of messages. The message type is specified when the com...
Definition: component.h:58
CYBER_REGISTER_COMPONENT(CameraObstacleDetectionComponent)
LaneDetectionComponent & operator=(const LaneDetectionComponent &)=delete
std::shared_ptr< apollo::perception::Motion_Service > MotionServiceMsgType
Definition: lane_detection_component.h:51