Apollo  6.0
Open source self driving car software
lane_based_calibrator.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 <deque>
19 #include <utility>
20 
24 
25 namespace apollo {
26 namespace perception {
27 namespace camera {
28 
29 const float kYawRateDefault = 0.0f;
30 const float kVelocityDefault = 8.333f; // m/s
31 const float kTimeDiffDefault = 0.067f; // in seconds, 15FPS
32 
33 void GetYawVelocityInfo(const float &time_diff, const double cam_coord_cur[3],
34  const double cam_coord_pre[3],
35  const double cam_coord_pre_pre[3], float *yaw_rate,
36  float *velocity);
37 
40 
41  void Init();
42 
44 
49 
51 
52  void operator=(const CalibratorParams &params) {
53  min_nr_pts_laneline = params.min_nr_pts_laneline;
54 
55  min_distance_to_update_calibration_in_meter =
57  min_distance_to_update_calibration_in_meter =
59  min_required_straight_driving_distance_in_meter =
61 
62  hist_estimator_params = params.hist_estimator_params;
63  }
64 };
65 
67  int image_width = 0;
68  int image_height = 0;
69  float focal_x = 0.0f;
70  float focal_y = 0.0f;
71  float cx = 0.0f;
72  float cy = 0.0f;
73 };
74 
76  public:
77  static const int kMaxNrHistoryFrames = 1000;
78 
79  LaneBasedCalibrator() { vp_buffer_.clear(); }
80 
81  ~LaneBasedCalibrator() { ClearUp(); }
82 
83  void Init(const LocalCalibratorInitOptions &options,
84  const CalibratorParams *params = nullptr);
85 
86  void ClearUp();
87 
88  // Main function. process every frame, return true if get valid
89  // estimation. suppose the points in lane are already sorted.
90  bool Process(const EgoLane &lane, const float &velocity,
91  const float &yaw_rate, const float &time_diff);
92 
93  float get_pitch_estimation() const { return pitch_estimation_; }
94 
95  // float get_pitch_cur() const {
96  // return pitch_cur_;
97  // }
98 
99  float get_vanishing_row() const { return vanishing_row_; }
100 
101  // float get_accumulated_straight_driving_in_meter() const {
102  // return accumulated_straight_driving_in_meter_;
103  // }
104 
105  private:
106  bool is_in_image(const Eigen::Vector2f &point) const {
107  int x = common::IRound(point(0));
108  int y = common::IRound(point(1));
109  bool is_in_image =
110  x >= 0 && x < image_width_ && y >= 0 && y < image_height_;
111  return (is_in_image);
112  }
113 
114  bool IsTravelingStraight(const float &vehicle_yaw_changed) const {
115  float abs_yaw = static_cast<float>(fabs(vehicle_yaw_changed));
116  return abs_yaw < params_.max_allowed_yaw_angle_in_radian;
117  }
118 
119  bool GetVanishingPoint(const EgoLane &lane, VanishingPoint *v_point);
120 
121  int GetCenterIndex(const Eigen::Vector2f *points, int nr_pts) const;
122 
123  bool SelectTwoPointsFromLineForVanishingPoint(const LaneLine &line,
124  float line_seg[4]);
125 
126  bool GetIntersectionFromTwoLineSegments(const float line_seg_l[4],
127  const float line_seg_r[4],
128  VanishingPoint *v_point);
129 
130  void PushVanishingPoint(const VanishingPoint &v_point);
131 
132  bool PopVanishingPoint(VanishingPoint *v_point);
133 
134  bool GetPitchFromVanishingPoint(const VanishingPoint &vp, float *pitch) const;
135 
136  bool AddPitchToHistogram(float pitch);
137 
138  private:
139  int image_width_ = 0;
140  int image_height_ = 0;
141  float k_mat_[9] = {0};
142  float pitch_cur_ = 0.0f;
143  float pitch_estimation_ = 0.0f;
144  float vanishing_row_ = 0.0f;
145  float accumulated_straight_driving_in_meter_ = 0.0f;
146 
147  // EgoLane lane_;
148  HistogramEstimator pitch_histogram_;
149  std::deque<VanishingPoint> vp_buffer_;
150  CalibratorParams params_;
151 };
152 
153 } // namespace camera
154 } // namespace perception
155 } // namespace apollo
float max_allowed_yaw_angle_in_radian
Definition: lane_based_calibrator.h:46
float min_required_straight_driving_distance_in_meter
Definition: lane_based_calibrator.h:48
float get_pitch_estimation() const
Definition: lane_based_calibrator.h:93
HistogramEstimatorParams hist_estimator_params
Definition: lane_based_calibrator.h:50
int IRound(int a)
Definition: i_basic.h:197
Definition: lane_struct_for_calib.h:51
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
~LaneBasedCalibrator()
Definition: lane_based_calibrator.h:81
void GetYawVelocityInfo(const float &time_diff, const double cam_coord_cur[3], const double cam_coord_pre[3], const double cam_coord_pre_pre[3], float *yaw_rate, float *velocity)
float get_vanishing_row() const
Definition: lane_based_calibrator.h:99
void operator=(const CalibratorParams &params)
Definition: lane_based_calibrator.h:52
Definition: histogram_estimator.h:78
float sampling_lane_point_rate
Definition: lane_based_calibrator.h:45
const float kVelocityDefault
Definition: lane_based_calibrator.h:30
Definition: lane_struct_for_calib.h:31
Definition: lane_based_calibrator.h:38
Definition: histogram_estimator.h:29
Eigen::Vector2f Vector2f
Definition: base_map_fwd.h:30
const float kTimeDiffDefault
Definition: lane_based_calibrator.h:31
int min_nr_pts_laneline
Definition: lane_based_calibrator.h:43
Definition: lane_based_calibrator.h:66
Definition: lane_struct_for_calib.h:26
const float kYawRateDefault
Definition: lane_based_calibrator.h:29
LaneBasedCalibrator()
Definition: lane_based_calibrator.h:79
Definition: lane_based_calibrator.h:75
float min_distance_to_update_calibration_in_meter
Definition: lane_based_calibrator.h:47
CalibratorParams()
Definition: lane_based_calibrator.h:39