Apollo  6.0
Open source self driving car software
visualizer.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 <string>
20 #include <vector>
21 
22 #include <opencv2/highgui/highgui.hpp>
23 #include <opencv2/imgproc/imgproc.hpp>
24 #include <opencv2/opencv.hpp>
25 
31 #include "modules/perception/proto/motion_service.pb.h"
32 
34 
35 namespace apollo {
36 namespace perception {
37 namespace camera {
38 
39 class Visualizer {
40  public:
41  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
42 
43  public:
44  bool Init(const std::vector<std::string> &camera_names,
45  TransformServer *tf_server);
47  const std::vector<std::string> &camera_names,
48  const std::string &visual_camera,
49  const EigenMap<std::string, Eigen::Matrix3f> &intrinsic_map,
50  const EigenMap<std::string, Eigen::Matrix4d> &extrinsic_map,
51  const Eigen::Matrix4d &ex_lidar2imu, const double pitch_adj,
52  const double yaw_adj, const double roll_adj, const int image_height,
53  const int image_width);
54  bool adjust_angles(const std::string &camera_name, const double pitch_adj,
55  const double yaw_adj, const double roll_adj);
56  bool SetDirectory(const std::string &path);
57  void ShowResult(const cv::Mat &img, const CameraFrame &frame);
58  void Draw2Dand3D(const cv::Mat &img, const CameraFrame &frame);
60  const cv::Mat &img, const CameraFrame &frame,
61  const base::MotionBufferPtr motion_buffer,
62  const Eigen::Affine3d &world2camera);
64  const std::string &camera_name, const cv::Mat &img,
65  const CameraFrame &frame, const Eigen::Matrix3d &intrinsic,
66  const Eigen::Matrix4d &extrinsic, const Eigen::Affine3d &world2camera,
67  const base::MotionBufferPtr motion_buffer);
68  bool DrawTrajectories(const base::ObjectPtr &object,
69  const base::MotionBufferPtr motion_buffer);
71  cv::Point world_point_to_bigimg(const Eigen::Vector4f &p);
72  Eigen::Vector2d image2ground(const std::string &camera_name, cv::Point p_img);
73  cv::Point ground2image(const std::string &camera_name,
74  Eigen::Vector2d p_ground);
76  std::string sub_type_to_string(
78  Eigen::Matrix3d homography_im2car(std::string camera_name) {
79  return homography_image2ground_[camera_name];
80  }
81  void Set_ROI(int input_offset_y, int crop_height, int crop_width) {
82  roi_start_ = input_offset_y;
83  roi_height_ = crop_height;
84  roi_width_ = crop_width;
85  }
86  bool euler_to_quaternion(Eigen::Vector4d *quaternion,
87  const double pitch_radian, const double yaw_radian,
88  const double roll_radian);
89  bool save_manual_calibration_parameter(const std::string &camera_name,
90  const double pitch_adj_degree,
91  const double yaw_adj_degree,
92  const double roll_adj_degree);
93  bool save_extrinsic_in_yaml(const std::string &camera_name,
94  const Eigen::Matrix4d &extrinsic,
95  const Eigen::Vector4d &quaternion,
96  const double pitch_radian,
97  const double yaw_radian,
98  const double roll_radian);
99  double regularize_angle(const double angle);
100  bool copy_backup_file(const std::string &filename);
101  bool key_handler(const std::string &camera_name, const int key);
102  bool reset_key();
103  void draw_range_circle();
104  void draw_selected_image_boundary(const int width, int const height,
105  cv::Mat *image);
106 
107  bool write_out_img_ = false;
108  bool cv_imshow_img_ = true;
109  // homograph between image and ground plane
110  std::map<std::string, Eigen::Matrix3d> homography_image2ground_;
111  std::map<std::string, Eigen::Matrix3d> homography_ground2image_;
112 
113  private:
114  std::map<std::string, cv::Mat> camera_image_;
115  cv::Mat world_image_;
116  TransformServer *tf_server_;
117  std::string path_;
118  double last_timestamp_ = 0.0;
119  int image_width_ = 1920;
120  int image_height_ = 1080;
121  int wide_pixel_ = 800;
122  double scale_ratio_ = 0.6;
123  int small_h_ = 0;
124  int small_w_ = 0;
125  int world_h_ = 0;
126  int m2pixel_ = 15; // 6;
127  double fov_cut_ratio_ = 0.55;
128  double degree_to_radian_factor_ = M_PI / 180.0;
129  double radian_to_degree_factor_ = 180.0 / M_PI;
130 
131  std::map<std::string, double> pitch_adj_degree_;
132  std::map<std::string, double> yaw_adj_degree_;
133  std::map<std::string, double> roll_adj_degree_;
134 
135  double max_pitch_degree_ = 5.0;
136  double min_pitch_degree_ = -5.0;
137  double max_yaw_degree_ = 5.0;
138  double min_yaw_degree_ = -5.0;
139  double max_roll_degree_ = 5.0;
140  double min_roll_degree_ = -5.0;
141 
142  cv::Point p_fov_1_;
143  cv::Point p_fov_2_;
144  cv::Point p_fov_3_;
145  cv::Point p_fov_4_;
146  int roi_height_ = 768;
147  int roi_start_ = 312;
148  int roi_width_ = 1920;
149 
150  std::map<std::string, Eigen::Vector2d> vp1_;
151  std::map<std::string, Eigen::Vector2d> vp2_;
152 
153  std::vector<std::string> camera_names_;
154  std::string visual_camera_ = "front_6mm";
155  // map for store params
156  EigenMap<std::string, Eigen::Matrix3f> intrinsic_map_;
157  EigenMap<std::string, Eigen::Matrix4d> extrinsic_map_;
158  Eigen::Matrix4d ex_lidar2imu_;
159  EigenMap<std::string, Eigen::Matrix4d> ex_camera2lidar_;
160  Eigen::Matrix4d ex_camera2imu_;
161  Eigen::Matrix4d ex_imu2camera_;
162  Eigen::Matrix4d ex_car2camera_;
163  Eigen::Matrix4d ex_camera2car_;
164  Eigen::Matrix4d ex_imu2car_;
165  Eigen::Matrix4d adjusted_camera2car_ = Eigen::Matrix4d::Identity();
166 
167  Eigen::Matrix4d projection_matrix_;
168  EigenMap<std::string, Eigen::Matrix3d> K_;
169 
170  // Visualization related variables
171  bool use_class_color_ = true;
172  bool capture_screen_ = false;
173  bool capture_video_ = false;
174  bool show_camera_box2d_ = true;
175  bool show_camera_box3d_ = true;
176  bool show_camera_bdv_ = true;
177  bool show_virtual_egolane_ = true;
178  bool show_radar_pc_ = true;
179  bool show_fusion_ = false;
180  bool show_associate_color_ = false;
181  bool show_type_id_label_ = true;
182  bool show_verbose_ = false;
183  bool show_trajectory_ = true;
184  bool show_vp_grid_ = true; // show vanishing point and ground plane grid
185  bool draw_lane_objects_ = true;
186  bool show_box_ = true;
187  bool show_velocity_ = false;
188  bool show_polygon_ = true;
189  bool show_text_ = false;
190  bool show_help_text_ = false;
191  bool manual_calibration_mode_ = false;
192  bool show_homography_object_ = false;
193  unsigned int show_lane_count_ = 1;
194  std::string help_str_;
195  // color
196  cv::Scalar color_cipv_ = cv::Scalar(255, 255, 255);
197  cv::Scalar virtual_lane_color_ = cv::Scalar(0, 0, 255);
198  int line_thickness_ = 2;
199  int cipv_line_thickness_ = 6;
200  int trajectory_line_thickness_ = 1;
201  double speed_limit_ = 1.0; // in m/s
202  unsigned int lane_step_num_ = 20;
203  Cipv cipv_;
204  unsigned int all_camera_recieved_ = 0;
205 };
206 
207 } // namespace camera
208 } // namespace perception
209 } // namespace apollo
bool write_out_img_
Definition: visualizer.h:107
void draw_selected_image_boundary(const int width, int const height, cv::Mat *image)
Definition: camera_frame.h:33
void Draw2Dand3D_all_info_single_camera(const std::string &camera_name, const cv::Mat &img, const CameraFrame &frame, const Eigen::Matrix3d &intrinsic, const Eigen::Matrix4d &extrinsic, const Eigen::Affine3d &world2camera, const base::MotionBufferPtr motion_buffer)
bool euler_to_quaternion(Eigen::Vector4d *quaternion, const double pitch_radian, const double yaw_radian, const double roll_radian)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: cipv_camera.h:52
std::string type_to_string(const apollo::perception::base::ObjectType type)
Eigen::Vector2d image2ground(const std::string &camera_name, cv::Point p_img)
Eigen::Vector2d Vector2d
Definition: base_map_fwd.h:36
bool Init(const std::vector< std::string > &camera_names, TransformServer *tf_server)
std::map< std::string, Eigen::Matrix3d > homography_ground2image_
Definition: visualizer.h:111
bool SetDirectory(const std::string &path)
Eigen::Matrix4d Matrix4d
Definition: base_map_fwd.h:32
bool key_handler(const std::string &camera_name, const int key)
bool DrawTrajectories(const base::ObjectPtr &object, const base::MotionBufferPtr motion_buffer)
cv::Point ground2image(const std::string &camera_name, Eigen::Vector2d p_ground)
std::map< T, EigenType, std::less< T >, Eigen::aligned_allocator< std::pair< const T, EigenType > >> EigenMap
Definition: eigen_defs.h:36
cv::Point world_point_to_bigimg(const Eigen::Vector2d &p)
bool Init_all_info_single_camera(const std::vector< std::string > &camera_names, const std::string &visual_camera, const EigenMap< std::string, Eigen::Matrix3f > &intrinsic_map, const EigenMap< std::string, Eigen::Matrix4d > &extrinsic_map, const Eigen::Matrix4d &ex_lidar2imu, const double pitch_adj, const double yaw_adj, const double roll_adj, const int image_height, const int image_width)
Definition: visualizer.h:39
bool save_extrinsic_in_yaml(const std::string &camera_name, const Eigen::Matrix4d &extrinsic, const Eigen::Vector4d &quaternion, const double pitch_radian, const double yaw_radian, const double roll_radian)
double regularize_angle(const double angle)
void Set_ROI(int input_offset_y, int crop_height, int crop_width)
Definition: visualizer.h:81
void ShowResult_all_info_single_camera(const cv::Mat &img, const CameraFrame &frame, const base::MotionBufferPtr motion_buffer, const Eigen::Affine3d &world2camera)
Definition: transform_server.h:40
std::map< std::string, Eigen::Matrix3d > homography_image2ground_
Definition: visualizer.h:110
bool cv_imshow_img_
Definition: visualizer.h:108
std::string sub_type_to_string(const apollo::perception::base::ObjectSubType type)
std::shared_ptr< MotionBuffer > MotionBufferPtr
Definition: object_supplement.h:203
bool save_manual_calibration_parameter(const std::string &camera_name, const double pitch_adj_degree, const double yaw_adj_degree, const double roll_adj_degree)
PointXYZIL Point
Definition: types.h:61
void ShowResult(const cv::Mat &img, const CameraFrame &frame)
Eigen::Matrix3d homography_im2car(std::string camera_name)
Definition: visualizer.h:78
bool adjust_angles(const std::string &camera_name, const double pitch_adj, const double yaw_adj, const double roll_adj)
ObjectType
Definition: object_types.h:26
Eigen::Affine3d Affine3d
Definition: base_map_fwd.h:34
Eigen::Matrix3d Matrix3d
Definition: base_map_fwd.h:33
ObjectSubType
Definition: object_types.h:63
void Draw2Dand3D(const cv::Mat &img, const CameraFrame &frame)
bool copy_backup_file(const std::string &filename)
std::shared_ptr< Object > ObjectPtr
Definition: object.h:123