Apollo  6.0
Open source self driving car software
camera_obstacle_detection_component.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2021 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 <string>
21 #include <vector>
22 
23 #include "modules/drivers/proto/sensor_image.pb.h"
24 #include "modules/perception/camera/app/proto/perception.pb.h"
25 #include "modules/perception/onboard/proto/fusion_camera_detection_component.pb.h"
26 #include "modules/perception/proto/motion_service.pb.h"
27 #include "modules/perception/proto/perception_camera.pb.h"
28 #include "modules/perception/proto/perception_obstacle.pb.h"
29 
43 
44 typedef std::shared_ptr<apollo::perception::Motion_Service>
48 
49 namespace apollo {
50 namespace perception {
51 namespace onboard {
52 
54  public:
55  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
56 
57  public:
60 
62  delete;
64  const CameraObstacleDetectionComponent&) = delete;
65 
66  bool Init() override;
67  void OnReceiveImage(const std::shared_ptr<apollo::drivers::Image>& in_message,
68  const std::string& camera_name);
69 
70  private:
71  int InitConfig();
72  int InitSensorInfo();
73  int InitAlgorithmPlugin();
74  int InitCameraFrames();
75  int InitProjectMatrix();
76  int InitCameraListeners();
77  int InitMotionService();
78  void SetCameraHeightAndPitch();
79  void OnMotionService(const MotionServiceMsgType& message);
80 
81  int InternalProc(
82  const std::shared_ptr<apollo::drivers::Image const>& in_message,
83  const std::string& camera_name, apollo::common::ErrorCode* error_code,
84  SensorFrameMessage* prefused_message,
85  apollo::perception::PerceptionObstacles* out_message);
86 
87  int MakeProtobufMsg(double msg_timestamp, int seq_num,
88  const std::vector<base::ObjectPtr>& objects,
89  const std::vector<base::LaneLine>& lane_objects,
90  const apollo::common::ErrorCode error_code,
91  apollo::perception::PerceptionObstacles* obstacles);
92 
93  int ConvertObjectToPb(const base::ObjectPtr& object_ptr,
94  apollo::perception::PerceptionObstacle* pb_msg);
95 
96  int ConvertObjectToCameraObstacle(
97  const base::ObjectPtr& object_ptr,
98  apollo::perception::camera::CameraObstacle* camera_obstacle);
99 
100  int ConvertLaneToCameraLaneline(
101  const base::LaneLine& lane_line,
102  apollo::perception::camera::CameraLaneLine* camera_laneline);
103 
104  int MakeCameraDebugMsg(
105  double msg_timestamp, const std::string& camera_name,
106  const camera::CameraFrame& camera_frame,
107  apollo::perception::camera::CameraDebug* camera_debug_msg);
108 
109  private:
110  std::mutex mutex_;
111  uint32_t seq_num_;
112 
113  std::vector<std::shared_ptr<cyber::Node>> camera_listener_nodes_;
114 
115  std::vector<std::string> camera_names_; // camera sensor names
116  std::vector<std::string> input_camera_channel_names_;
117 
118  // camera name -> SensorInfo
119  std::map<std::string, base::SensorInfo> sensor_info_map_;
120 
121  // camera_height
122  std::map<std::string, float> camera_height_map_;
123 
124  // camera_pitch_angle_diff
125  // the pitch_diff = pitch_narrow - pitch_obstacle
126  std::map<std::string, float> name_camera_pitch_angle_diff_map_;
127 
128  // TF stuff
129  std::map<std::string, std::string> tf_camera_frame_id_map_;
130  std::map<std::string, std::shared_ptr<TransformWrapper>>
131  camera2world_trans_wrapper_map_;
132 
133  // pre-allocaated-mem data_provider;
134  std::map<std::string, std::shared_ptr<camera::DataProvider>>
135  data_providers_map_;
136 
137  // map for store params
138  EigenMap<std::string, Eigen::Matrix4d> extrinsic_map_;
139  EigenMap<std::string, Eigen::Matrix3f> intrinsic_map_;
140  Eigen::Matrix3d homography_im2car_;
141 
142  // camera obstacle pipeline
143  camera::CameraPerceptionInitOptions camera_perception_init_options_;
144  camera::CameraPerceptionOptions camera_perception_options_;
145  std::unique_ptr<camera::ObstacleDetectionCamera> camera_obstacle_pipeline_;
146 
147  // fixed size camera frames
148  int frame_capacity_ = 20;
149  int frame_id_ = 0;
150  EigenVector<camera::CameraFrame> camera_frames_;
151 
152  // image info.
153  int image_width_ = 1920;
154  int image_height_ = 1080;
155  int image_channel_num_ = 3;
156  int image_data_size_ = -1;
157 
158  // default camera pitch angle & height
159  float default_camera_pitch_ = 0.f;
160  float default_camera_height_ = 1.6f;
161 
162  // options for DataProvider
163  bool enable_undistortion_ = false;
164 
165  double timestamp_offset_ = 0.0;
166 
167  std::string prefused_channel_name_;
168 
169  bool enable_visualization_ = false;
170  std::string camera_perception_viz_message_channel_name_;
171  std::string visual_debug_folder_;
172  std::string visual_camera_;
173 
174  bool output_final_obstacles_ = false;
175  std::string output_obstacles_channel_name_;
176 
177  bool output_camera_debug_msg_ = false;
178  std::string camera_debug_channel_name_;
179 
180  Eigen::Matrix3d project_matrix_;
181  double pitch_diff_ = 0.0;
182 
183  double last_timestamp_ = 0.0;
184  double ts_diff_ = 1.0;
185 
186  std::shared_ptr<
188  writer_;
189 
190  std::shared_ptr<apollo::cyber::Writer<SensorFrameMessage>>
191  sensorframe_writer_;
192 
193  std::shared_ptr<apollo::cyber::Writer<CameraPerceptionVizMessage>>
194  camera_viz_writer_;
195 
196  std::shared_ptr<
198  camera_debug_writer_;
199 
200  // variable for motion service
201  base::MotionBufferPtr motion_buffer_;
202  const int motion_buffer_size_ = 100;
203 
204  // // variables for CIPV
205  bool enable_cipv_ = false;
206  std::unique_ptr<camera::BaseCipv> cipv_;
207  camera::CipvInitOptions cipv_init_options_;
208  std::string cipv_name_;
209 
210  // variables for visualization
211  camera::Visualizer visualize_;
212  bool write_visual_img_;
213 };
214 
216 
217 } // namespace onboard
218 } // namespace perception
219 } // namespace apollo
Definition: lane_struct.h:69
CameraObstacleDetectionComponent & operator=(const CameraObstacleDetectionComponent &)=delete
std::vector< EigenType, Eigen::aligned_allocator< EigenType > > EigenVector
Definition: eigen_defs.h:32
Definition: camera_frame.h:33
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
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: camera_obstacle_detection_component.h:53
Definition: writer.h:42
Definition: visualizer.h:39
CameraObstacleDetectionComponent()
Definition: camera_obstacle_detection_component.h:58
void OnReceiveImage(const std::shared_ptr< apollo::drivers::Image > &in_message, const std::string &camera_name)
std::shared_ptr< MotionBuffer > MotionBufferPtr
Definition: object_supplement.h:203
std::shared_ptr< apollo::perception::Motion_Service > MotionServiceMsgType
Definition: camera_obstacle_detection_component.h:45
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)
std::shared_ptr< Object > ObjectPtr
Definition: object.h:123