libfovis
visual_odometry.hpp
1 #ifndef __fovis_visual_odometry_hpp__
2 #define __fovis_visual_odometry_hpp__
3 
4 #include <stdint.h>
5 
6 #include <Eigen/Geometry>
7 
8 #include "keypoint.hpp"
9 #include "camera_intrinsics.hpp"
10 #include "frame.hpp"
11 #include "depth_source.hpp"
12 #include "motion_estimation.hpp"
13 #include "options.hpp"
14 
15 namespace fovis
16 {
17 
22 class VisualOdometryPriv
23 {
24  private:
25  friend class VisualOdometry;
26  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
27 
28  // best estimate for current position and orientation
29  Eigen::Isometry3d pose;
30 
31  // transformation relating reference frame and most recent frame
32  Eigen::Isometry3d ref_to_prev_frame;
33 
34  // best estimate of motion from current to previous frame
35  Eigen::Isometry3d motion_estimate;
36  // the 6x6 estimate of the covriance [x-y-z, roll-pitch-yaw];
37  Eigen::MatrixXd motion_estimate_covariance;
38 
39  Eigen::Matrix3d initial_homography_est;
40  Eigen::Isometry3d initial_motion_estimate;
41  Eigen::MatrixXd initial_motion_cov;
42 };
43 
68 {
69  public:
78  VisualOdometry(const Rectification* rectification,
79  const VisualOdometryOptions& options);
80 
81  ~VisualOdometry();
82 
97  void processFrame(const uint8_t* gray, DepthSource* depth_source);
98 
104  const Eigen::Isometry3d& getPose() {
105  return _p->pose;
106  }
107 
114  return _ref_frame;
115  }
116 
120  const OdometryFrame* getTargetFrame() const {
121  return _cur_frame;
122  }
123 
129  return _change_reference_frames;
130  }
131 
136  MotionEstimateStatusCode getMotionEstimateStatus() const {
137  return _estimator->getMotionEstimateStatus();
138  }
139 
144  const Eigen::Isometry3d& getMotionEstimate() const {
145  return _p->motion_estimate;
146  }
147 
152  const Eigen::MatrixXd& getMotionEstimateCov() const {
153  return _p->motion_estimate_covariance;
154  }
155 
160  return _estimator;
161  }
162 
166  int getFastThreshold() const {
167  return _fast_threshold;
168  }
169 
173  const Eigen::Matrix3d & getInitialHomography() const {
174  return _p->initial_homography_est;
175  }
176 
181  return _options;
182  }
183 
189 
194  void sanityCheck() const;
195 
196  private:
197  void prepareFrame(OdometryFrame* frame);
198 
199  Eigen::Quaterniond estimateInitialRotation(const OdometryFrame* prev,
200  const OdometryFrame* cur,
201  const Eigen::Isometry3d
202  &init_motion_estimate =
203  Eigen::Isometry3d::Identity());
204 
205  const Rectification* _rectification;
206 
207  OdometryFrame* _ref_frame;
208  OdometryFrame* _prev_frame;
209  OdometryFrame* _cur_frame;
210 
211  MotionEstimator* _estimator;
212 
213  VisualOdometryPriv* _p;
214 
215  bool _change_reference_frames;
216 
217  long _frame_count;
218 
219  // === tuning parameters ===
220 
221  int _feature_window_size;
222 
223  int _num_pyramid_levels;
224 
225  // initial feature detector threshold
226  int _fast_threshold;
227 
228  // params for adaptive feature detector threshold
229  int _fast_threshold_min;
230  int _fast_threshold_max;
231  int _target_pixels_per_feature;
232  float _fast_threshold_adaptive_gain;
233 
234  bool _use_adaptive_threshold;
235  bool _use_homography_initialization;
236 
237  // if there are least this many inliers in the previous motion estimate,
238  // don't change reference frames.
239  int _ref_frame_change_threshold;
240 
241  // Which level of the image pyramid to use for initial rotation estimation
242  int _initial_rotation_pyramid_level;
243 
244  VisualOdometryOptions _options;
245 };
246 
247 }
248 #endif
const VisualOdometryOptions & getOptions() const
Definition: visual_odometry.hpp:180
void processFrame(const uint8_t *gray, DepthSource *depth_source)
MotionEstimateStatusCode getMotionEstimateStatus() const
Definition: visual_odometry.hpp:136
Stores data specific to an input frame.
Definition: frame.hpp:33
const Eigen::Isometry3d & getPose()
Definition: visual_odometry.hpp:104
Provides depth estimates for input image pixels.
Definition: depth_source.hpp:29
VisualOdometry(const Rectification *rectification, const VisualOdometryOptions &options)
const MotionEstimator * getMotionEstimator() const
Definition: visual_odometry.hpp:159
static VisualOdometryOptions getDefaultOptions()
const OdometryFrame * getReferenceFrame() const
Definition: visual_odometry.hpp:113
Does the heavy lifting for frame-to-frame motion estimation.
Definition: motion_estimation.hpp:37
std::map< std::string, std::string > VisualOdometryOptions
Options.
Definition: options.hpp:106
const Eigen::MatrixXd & getMotionEstimateCov() const
Definition: visual_odometry.hpp:152
void sanityCheck() const
Maps image coordinates from an input image to image coordinates on a rectified camera.
Definition: rectification.hpp:41
quick and dirty profiling tool.inspired by the matlab tic/toc command
Definition: camera_intrinsics.hpp:6
const Eigen::Isometry3d & getMotionEstimate() const
Definition: visual_odometry.hpp:144
const Eigen::Matrix3d & getInitialHomography() const
Definition: visual_odometry.hpp:173
bool getChangeReferenceFrames() const
Definition: visual_odometry.hpp:128
int getFastThreshold() const
Definition: visual_odometry.hpp:166
const OdometryFrame * getTargetFrame() const
Definition: visual_odometry.hpp:120
Options.
Main visual odometry class.
Definition: visual_odometry.hpp:67