viso2
StereoOdometer.hpp
Go to the documentation of this file.
1 /* Generated from orogen/lib/orogen/templates/tasks/Task.hpp */
2 
3 #ifndef VISO2_STEREOODOMETER_TASK_HPP
4 #define VISO2_STEREOODOMETER_TASK_HPP
5 
6 #include "viso2/StereoOdometerBase.hpp"
7 
9 #include <opencv/cv.h>
10 #include <opencv2/core/core.hpp>
11 #include <opencv2/core/eigen.hpp>
12 #include <opencv/highgui.h>
13 
15 #include "frame_helper/FrameHelper.h"
16 #include "frame_helper/FrameHelperTypes.h"
17 #include "frame_helper/Calibration.h"
18 #include "frame_helper/CalibrationCv.h"
21 #include <base/samples/RigidBodyState.hpp>
22 #include <base/samples/DistanceImage.hpp>
23 
25 #include <vector>
26 #include <map>
27 
29 #include <boost/shared_ptr.hpp>
30 #include <boost/circular_buffer.hpp>
31 #include <boost/unordered_map.hpp>
32 
34 #include <viso2/matrix.h>
35 #include <viso2/viso_stereo.h>
36 #include <ctime>
37 
39 #include<Eigen/StdVector>
40 
41 namespace viso2 {
42 
43 
44  struct HashPoint
45  {
46  size_t idx; /* Index in the point cloud **/
47  base::Vector3d point;
48  base::Vector4d color;
49  base::Matrix3d cov;
50  base::Vector3d jacobian;
51  };
52 
53 
68  class StereoOdometer : public StereoOdometerBase
69  {
70  friend class StereoOdometerBase;
71 
72  public:
73  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
74 
75  protected:
76  static const int DEFAULT_CIRCULAR_BUFFER_SIZE = 2;
77 
78  protected:
79 
80  /**************************/
81  /*** Property Variables ***/
82  /**************************/
83  // set most important visual odometry parameters
84  // for a full parameter list, look at: viso2/viso_stereo.h
85  VisualOdometryStereo::parameters viso2param;
86 
87  //Intrinsic and extrinsic parameters for the pinhole camera model
88  frame_helper::StereoCalibration cameracalib;
89 
91  frame_helper::StereoCalibrationCv cameracalibCv;
92 
93  /******************************************/
94  /*** General Internal Storage Variables ***/
95  /******************************************/
96  boost::shared_ptr<VisualOdometryStereo> viso;
97  boost::circular_buffer<base::samples::frame::FramePair> imagePair;
98  frame_helper::FrameHelper frameHelperLeft, frameHelperRight;
99  Eigen::Matrix4d Q;
100  ::base::samples::frame::Frame leftColorImage;
101  ::base::Matrix2d pxleftVar, pxrightVar;
102  boost::unordered_map< int32_t, int32_t > hashIdx;
103  boost::circular_buffer< std::map < int32_t, HashPoint, std::less<int32_t>,
104  Eigen::aligned_allocator< std::pair < const int32_t, HashPoint > > > > hashPointcloud;
106  /***************************/
108  /***************************/
109  Eigen::Affine3d pose;
110  base::samples::RigidBodyState poseOut;
111  RTT::extras::ReadOnlyPointer<base::samples::frame::Frame> frame_out;
113  protected:
114 
115  virtual void left_frameTransformerCallback(const base::Time &ts, const ::RTT::extras::ReadOnlyPointer< ::base::samples::frame::Frame > &left_frame_sample);
116  virtual void right_frameTransformerCallback(const base::Time &ts, const ::RTT::extras::ReadOnlyPointer< ::base::samples::frame::Frame > &right_frame_sample);
117 
118  public:
123  StereoOdometer(std::string const& name = "viso2::StereoOdometer");
124 
130  StereoOdometer(std::string const& name, RTT::ExecutionEngine* engine);
131 
134  ~StereoOdometer();
135 
150  bool configureHook();
151 
157  bool startHook();
158 
173  void updateHook();
174 
181  void errorHook();
182 
186  void stopHook();
187 
192  void cleanupHook();
193 
196  viso2::Viso2Info computeStereoOdometer(const base::Time &ts, const Eigen::Affine3d &tf);
197 
198  void drawMatches(const base::samples::frame::Frame &image1, const base::samples::frame::Frame &image2,
199  const std::vector<Matcher::p_match> &matches, const std::vector<int32_t>& inlier_indices, base::samples::frame::Frame &imageOutput);
200 
201  void createDistanceImage(const base::samples::frame::Frame &image1, const base::samples::frame::Frame &image2,
202  const std::vector<Matcher::p_match> &matches, const VisualOdometryStereo::parameters &viso2param,
203  base::samples::DistanceImage &distImage);
204 
205  void createPointCloud(const Eigen::Affine3d &tf,
206  const base::samples::frame::Frame &image1,
207  const std::vector<Matcher::p_match> &matches,
208  const std::vector<int32_t>& inlier_indices,
209  const Eigen::Matrix4d &Q,
210  const Eigen::Affine3d &deltaPose,
211  boost::unordered_map< int32_t, int32_t > &hashIdx,
212  boost::circular_buffer< std::map < int32_t, HashPoint, std::less<int32_t>,
213  Eigen::aligned_allocator< std::pair < const int32_t, HashPoint > > > > &hashPointcloud);
214 
215  base::Vector3d computeFeaturesJacobian (const Eigen::Affine3d &deltaPose,
216  const base::Vector3d &point);
217 
218  void postProcessPointCloud (boost::unordered_map< int32_t, int32_t > & hashIdx,
219  boost::circular_buffer< std::map < int32_t, HashPoint, std::less<int32_t>,
220  Eigen::aligned_allocator< std::pair < const int32_t, HashPoint > > > > &hashPointcloud,
221  base::samples::Pointcloud &pointcloud,
222  std::vector<base::Matrix3d> &pointsVar,
223  std::vector<unsigned int> &pointsIdx,
224  base::MatrixXd &deltaJacobCurr,
225  base::MatrixXd &deltaJacobPrev);
226 
227  };
228 }
229 
230 #endif
231 
boost::unordered_map< int32_t, int32_t > hashIdx
Definition: StereoOdometer.hpp:102
The task context provides and requires services. It uses an ExecutionEngine to perform its functions...
Definition: StereoOdometer.hpp:68
frame_helper::FrameHelper frameHelperRight
Definition: StereoOdometer.hpp:98
base::Vector4d color
Definition: StereoOdometer.hpp:48
::base::Matrix2d pxrightVar
Definition: StereoOdometer.hpp:101
Eigen::Matrix4d Q
Definition: StereoOdometer.hpp:99
frame_helper::StereoCalibration cameracalib
Definition: StereoOdometer.hpp:88
base::samples::RigidBodyState poseOut
Definition: StereoOdometer.hpp:110
size_t idx
Definition: StereoOdometer.hpp:46
RTT::extras::ReadOnlyPointer< base::samples::frame::Frame > frame_out
Definition: StereoOdometer.hpp:111
Definition: StereoOdometer.hpp:41
base::Vector3d jacobian
Definition: StereoOdometer.hpp:50
::base::samples::frame::Frame leftColorImage
Definition: StereoOdometer.hpp:100
frame_helper::StereoCalibrationCv cameracalibCv
Definition: StereoOdometer.hpp:91
Definition: StereoOdometer.hpp:44
boost::circular_buffer< base::samples::frame::FramePair > imagePair
Definition: StereoOdometer.hpp:97
boost::shared_ptr< VisualOdometryStereo > viso
Definition: StereoOdometer.hpp:96
Eigen::Affine3d pose
Definition: StereoOdometer.hpp:109
Definition: viso2Types.hpp:43
base::Matrix3d cov
Definition: StereoOdometer.hpp:49
boost::circular_buffer< std::map< int32_t, HashPoint, std::less< int32_t >, Eigen::aligned_allocator< std::pair< const int32_t, HashPoint > > > > hashPointcloud
Definition: StereoOdometer.hpp:104
VisualOdometryStereo::parameters viso2param
Definition: StereoOdometer.hpp:85
base::Vector3d point
Definition: StereoOdometer.hpp:47