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