Apollo  6.0
Open source self driving car software
online_calibration_service.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 <string>
21 #include <vector>
22 
25 
26 namespace apollo {
27 namespace perception {
28 namespace camera {
29 
30 struct CameraStatus {
31  float camera_ground_height = -1.f;
32  float pitch_angle = 0.f;
33  float pitch_angle_diff = 0.f;
34  std::vector<double> k_matrix = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
35  std::vector<double> ground_plane = {0.0, 0.0, 0.0, 0.0};
36 };
37 
39  public:
41 
43 
44  bool Init(const CalibrationServiceInitOptions &options =
46 
47  bool BuildIndex() override;
48 
49  // @brief query depth on ground plane given pixel coordinate
50  bool QueryDepthOnGroundPlane(int x, int y, double *depth) const override;
51 
52  // @brief query 3d point on ground plane given pixel coordinate
53  bool QueryPoint3dOnGroundPlane(int x, int y,
54  Eigen::Vector3d *point3d) const override;
55 
56  // @brief query ground plane in camera frame, parameterized as
57  // [n^T, d] with n^T*x+d=0
58  bool QueryGroundPlaneInCameraFrame(
59  Eigen::Vector4d *plane_param) const override;
60 
61  // @brief query camera to ground height and pitch angle
62  bool QueryCameraToGroundHeightAndPitchAngle(float *height,
63  float *pitch) const override;
64 
65  float QueryCameraToGroundHeight() const override {
66  if (is_service_ready_) {
67  auto iter = name_camera_status_map_.find(sensor_name_);
68  return (iter->second).camera_ground_height;
69  }
70  return -1.f;
71  }
72 
73  float QueryPitchAngle() const override {
74  if (is_service_ready_) {
75  auto iter = name_camera_status_map_.find(sensor_name_);
76  return (iter->second).pitch_angle;
77  }
78  return -1.f;
79  }
80 
81  // @brief using calibrator to update pitch angle
82  void Update(CameraFrame *frame) override;
83 
84  // @brief set camera height and pitch
85  void SetCameraHeightAndPitch(
86  const std::map<std::string, float> &name_camera_ground_height_map,
87  const std::map<std::string, float> &name_camera_pitch_angle_diff_map,
88  const float &pitch_angle_master_sensor) override;
89 
90  std::string Name() const override;
91 
92  private:
93  bool HasSetIntrinsics() const {
94  return name_camera_status_map_.find(sensor_name_) !=
95  name_camera_status_map_.end();
96  }
97 
98  bool HasSetGroundPlane() {
99  bool has_set_ground_plane =
100  name_camera_status_map_.find(sensor_name_) !=
101  name_camera_status_map_.end() &&
102  name_camera_status_map_[sensor_name_].camera_ground_height > 0.0;
103  return has_set_ground_plane;
104  }
105 
106  bool is_service_ready_ = false;
107  std::string sensor_name_ = "";
108  std::string master_sensor_name_ = "";
109  std::map<std::string, CameraStatus> name_camera_status_map_;
110  std::shared_ptr<BaseCalibrator> calibrator_;
111 };
112 
113 } // namespace camera
114 } // namespace perception
115 } // namespace apollo
Definition: camera_frame.h:33
Definition: online_calibration_service.h:30
float QueryCameraToGroundHeight() const override
Definition: online_calibration_service.h:65
std::vector< double > ground_plane
Definition: online_calibration_service.h:35
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Eigen::Vector3d Vector3d
Definition: frame_transform.h:27
float QueryPitchAngle() const override
Definition: online_calibration_service.h:73
float pitch_angle_diff
Definition: online_calibration_service.h:33
virtual ~OnlineCalibrationService()
Definition: online_calibration_service.h:42
OnlineCalibrationService()
Definition: online_calibration_service.h:40
Definition: base_calibration_service.h:40
float pitch_angle
Definition: online_calibration_service.h:32
bool Init(const char *binary_name)
std::vector< double > k_matrix
Definition: online_calibration_service.h:34
Definition: base_calibration_service.h:29
float camera_ground_height
Definition: online_calibration_service.h:31
Definition: online_calibration_service.h:38