Main MRPT website > C++ reference
MRPT logo
CDifodo.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #ifndef CDifodo_H
11 #define CDifodo_H
12 
13 #include <mrpt/utils/types_math.h> // Eigen
15 #include <mrpt/poses/CPose3D.h>
17 
18 //class CDeflodo Acronim for "Depth Flow odometry" -> otra opción de nombre...
19 namespace mrpt
20 {
21  namespace vision
22  {
24  using Eigen::MatrixXf;
25  using Eigen::MatrixXi;
26 
27  /** This abstract class implements a method called "Difodo" to perform Visual odometry with range cameras.
28  * It is based on the range flow equation and assumes that the scene is rigid.
29  * It can work with different image resolutions (640 x 480, 320 x 240 or 160 x 120).
30  * Independently of the initial resolution chosen, the method normally makes use of a smaller amount of points
31  * which can be adjusted with the member variables (rows,cols).
32  *
33  * How to use:
34  * - A derived class must be created which defines the method "loadFrame(...)" according to the user application.
35  * This method has to load the depth image into the variable "depth_wf".
36  * - Call loadFrame();
37  * - Call OdometryCalculation();
38  * - Call filterSpeedAndPoseUpdate();
39  *
40  * For further information have a look at the apps:
41  * - [Difodometry-Camera](http://www.mrpt.org/list-of-mrpt-apps/application-difodometry-camera/)
42  * - [Difodometry-Datasets](http://www.mrpt.org/list-of-mrpt-apps/application-difodometry-datasets/)
43  *
44  * Please refer to the respective publication when using this method: *************************
45  *
46  * - JUN/2013: First design.
47  * - JAN/2014: Integrated into MRPT library.
48  *
49  * \sa *********************
50  * \ingroup mrpt_vision_grp
51  */
52 
54 
55  protected:
56 
57  /** Matrices that store the original and filtered depth frames with the image resolution */
58  MatrixXf depth_ft;
59  MatrixXf depth_wf;
60 
61  /** Matrices that store the point coordinates after downsampling. */
62  MatrixXf depth;
63  MatrixXf depth_old;
64  MatrixXf depth_inter;
65  MatrixXf xx;
66  MatrixXf xx_inter;
67  MatrixXf xx_old;
68  MatrixXf yy;
69  MatrixXf yy_inter;
70  MatrixXf yy_old;
71 
72  /** Matrices that store the depth derivatives */
73  MatrixXf du;
74  MatrixXf dv;
75  MatrixXf dt;
76 
77  /** Weights used to ponder equations in the least square solution */
78  MatrixXf weights;
79 
80  /** Matrix which indicates wheter the depth of a pixel is zero (null = 1) or not (null = 00). and border and noisy points */
81  MatrixXi null;
82 
83  /** Matrix which indicates wheter a point is in a border or has an inaccurate depth (border =1, border = 0 otherwise) */
84  MatrixXi border;
85 
86  /** Least squares covariance matrix */
88 
89  /** Camera properties: */
90  float f_dist; //!<Focal lenght (meters)
91  float x_incr; //!<Separation between pixels (cols) in the sensor array (meters)
92  float y_incr; //!<Separation between pixels (rows) in the sensor array (meters)
93  float fovh; //!<Horizontal field of view (rad)
94  float fovv; //!<Vertical field of view (rad)
95 
96  /** Number of rows and cols of the depth image that will be considered by the visual odometry method.
97  * As a rule, the more rows and cols the slower and more accurate the method becomes.
98  * They always have to be less or equal to the size of the original depth image. */
99  unsigned int rows;
100  unsigned int cols;
101 
102  /** Size (rows) of the gaussian kernel used to filter the depth image */
103  unsigned int gaussian_mask_size;
104 
105  /** Speed filter parameters:
106  * Previous_speed_const_weight directly ponders the previous speed in order to calculate the filtered speed. Recommended range - (0, 0.5)
107  * Previous_speed_eig_weight ponders the product of the corresponding eigenvalue and the previous speed in order to calculate the filtered speed*/
108  float previous_speed_const_weight; //!<Default 0.2
109  float previous_speed_eig_weight; //!<Default 300
110 
111  /** Solution from the solver: kai before applying the filter in local coordinates */
113 
114  /** Last filtered speed in absolute coordinates */
116 
117  /** It filters the depth image with a gaussian kernel and downsample this filtered image according to the values of "rows" and "cols" */
118  void filterAndDownsample();
119 
120  /** It calculates the "average" coordinates of the points observed by the camera between two consecutive frames */
121  void calculateCoord();
122 
123  /** It calculates the depth derivatives respect to u,v (rows and cols) and t (time) */
124  void calculateDepthDerivatives();
125 
126  /** This method finds pixels whose depth is zero to subsequently discard them */
127  void findNullPoints();
128 
129  /** This method finds pixels which are not in planar or smooth surfaces, and also inaccurate (noisy) pixels */
130  void findBorders();
131 
132  /** This method discards the pixels found by 'findNullPoints()' and 'findBorders()' */
133  void findValidPoints();
134 
135  /** The Solver. It buils the overdetermined system and gets the least-square solution.
136  * It also calculates the least-square covariance matrix */
137  void solveDepthSystem();
138 
139  /** Virtual method to filter the speed and update the camera pose. */
140  virtual void filterSpeedAndPoseUpdate();
141 
142  public:
143 
144  /** Camera properties */
145  float lens_disp; //Lateral displacement of the lens with respect to the center of the camera (meters)
146 
147  /** Frames per second (Hz) */
148  float fps;
149 
150  /** Resolution of the images taken by the range camera */
151  unsigned int cam_mode; // (1 - 640 x 480, 2 - 320 x 240, 4 - 160 x 120)
152 
153  /** Downsample the image taken by the range camera. Useful to reduce the computational burden,
154  * as this downsampling is applied before the gaussian filter */
155  unsigned int downsample; // (1 - original size, 2 - res/2, 4 - res/4)
156 
157  /** Num of valid points after removing null pixels and borders */
158  unsigned int num_valid_points;
159 
160  /** Thresholds used to remove borders and noisy points */
161  float duv_threshold; //!< Threshold to du*du + dv*dv
162  float dt_threshold; //!< Threshold to dt
163  float dif_threshold; //!< Threshold to [abs(final_dx-ini_dx) + abs(final_dy-ini_dy)]
164  float difuv_surroundings; //!< Threshold to the difference of (du,dv) at a pixel and the values of (du,dv) at its surroundings
165  float dift_surroundings; //!< Threshold to the difference of dt at a pixel and the value of dt at its surroundings
166 
167  /** Execution time (ms) */
169 
170  /** Camera poses */
171  CPose3D cam_pose; //!< Last camera pose
172  CPose3D cam_oldpose; //!< Previous camera pose
173 
174  /** This method performs the necessary steps to estimate the camera speed in local coordinates once the depth image has been loaded */
175  void OdometryCalculation();
176 
177  /** It sets the camera focal lenght */
178  inline void setCameraFocalLenght(float new_f);
179 
180  /** It gets the camera focal lenght */
181  inline float getCameraFocalLenght() const {return f_dist;}
182 
183  /** It sets the number of rows and cols of the depth image that will be considered by the visual odometry method. */
184  inline void setNumberOfRowsAndCols(unsigned int num_rows, unsigned int num_cols);
185 
186  /** It gets the rows and cols of the depth image that are considered by the visual odometry method. */
187  inline void getRowsAndCols(unsigned int &num_rows, unsigned int &num_cols) const {num_rows = rows; num_cols = cols;}
188 
189  /** It sets the horizontal and vertical field of vision (in degrees) */
190  inline void setFOV(float new_fovh, float new_fovv);
191 
192  /** It gets the horizontal and vertical field of vision (in degrees) */
193  inline void getFOV(float &cur_fovh, float &cur_fovv) const {cur_fovh = 57.296*fovh; cur_fovv = 57.296*fovv;}
194 
195  /** It gets the weight that ponders the previous speed in order to calculate the filtered speed. */
196  inline float getSpeedFilterConstWeight() const {return previous_speed_const_weight;}
197 
198  /** It gets the weight that ponders the product of the corresponding eigenvalue and the previous speed in order to calculate the filtered speed */
199  inline float getSpeedFilterEigWeight() const {return previous_speed_eig_weight;}
200 
201  /** It sets the weight that ponders the previous speed in order to calculate the filtered speed. */
202  inline void setSpeedFilterConstWeight(float new_cweight) { previous_speed_const_weight = new_cweight;}
203 
204  /** It sets the weight that ponders the product of the corresponding eigenvalue and the previous speed in order to calculate the filtered speed */
205  inline void setSpeedFilterEigWeight(float new_eweight) { previous_speed_eig_weight = new_eweight;}
206 
207  /** This method gets the coordinates of the points regarded by the visual odometry method */
208  inline void getPointsCoord(MatrixXf &x, MatrixXf &y, MatrixXf &z);
209 
210  /** This method gets the depth derivatives respect to u,v and t respectively */
211  inline void getDepthDerivatives(MatrixXf &cur_du, MatrixXf &cur_dv, MatrixXf &cur_dt);
212 
213  /** It gets the camera speed (vx, vy, vz, wx, wy, wz) expressed in local reference frame estimated by the solver (before filtering) */
214  inline mrpt::math::CMatrixFloat61 getSolverSolution() const {return kai_solver;}
215 
216  /** It gets the last camera speed (vx, vy, vz, wx, wy, wz) expressed in the world reference frame, obtained after filtering */
217  inline mrpt::math::CMatrixFloat61 getLastSpeedAbs() const {return kai_abs;}
218 
219  /** It gets the least-square covariance matrix */
220  inline mrpt::math::CMatrixFloat66 getCovariance() const {return est_cov;}
221 
222  /** It gets the matrix of weights */
223  inline void getWeights(MatrixXf &we);
224 
225  /** It resets the border thresholds to their default values */
226  void bordersThresholdToDefault();
227 
228  /** Virtual method to be implemented in derived classes.
229  * It should be used to load the last depth image into the variable depth_wf */
230  virtual void loadFrame() = 0;
231 
232  //Constructor. Initialize variables and matrix sizes
233  CDifodo();
234 
235  };
236  }
237 }
238 
239 
240 
241 #endif
float previous_speed_const_weight
Speed filter parameters: Previous_speed_const_weight directly ponders the previous speed in order to ...
Definition: CDifodo.h:108
float fps
Frames per second (Hz)
Definition: CDifodo.h:148
MatrixXf depth_old
Definition: CDifodo.h:63
MatrixXf depth_inter
Definition: CDifodo.h:64
unsigned int gaussian_mask_size
Size (rows) of the gaussian kernel used to filter the depth image.
Definition: CDifodo.h:103
float previous_speed_eig_weight
Default 300.
Definition: CDifodo.h:109
float y_incr
Separation between pixels (rows) in the sensor array (meters)
Definition: CDifodo.h:92
MatrixXf du
Matrices that store the depth derivatives.
Definition: CDifodo.h:73
mrpt::math::CMatrixFloat66 getCovariance() const
It gets the least-square covariance matrix.
Definition: CDifodo.h:220
unsigned int cols
Definition: CDifodo.h:100
MatrixXf xx_inter
Definition: CDifodo.h:66
mrpt::math::CMatrixFloat61 getLastSpeedAbs() const
It gets the last camera speed (vx, vy, vz, wx, wy, wz) expressed in the world reference frame...
Definition: CDifodo.h:217
unsigned int rows
Number of rows and cols of the depth image that will be considered by the visual odometry method...
Definition: CDifodo.h:99
float lens_disp
Camera properties.
Definition: CDifodo.h:145
MatrixXf depth_wf
Definition: CDifodo.h:59
MatrixXi null
Matrix which indicates wheter the depth of a pixel is zero (null = 1) or not (null = 00)...
Definition: CDifodo.h:81
MatrixXi border
Matrix which indicates wheter a point is in a border or has an inaccurate depth (border =1...
Definition: CDifodo.h:84
float getCameraFocalLenght() const
It gets the camera focal lenght.
Definition: CDifodo.h:181
float difuv_surroundings
Threshold to the difference of (du,dv) at a pixel and the values of (du,dv) at its surroundings...
Definition: CDifodo.h:164
CPose3D cam_pose
Camera poses.
Definition: CDifodo.h:171
float execution_time
Execution time (ms)
Definition: CDifodo.h:168
float dif_threshold
Threshold to [abs(final_dx-ini_dx) + abs(final_dy-ini_dy)].
Definition: CDifodo.h:163
void getRowsAndCols(unsigned int &num_rows, unsigned int &num_cols) const
It gets the rows and cols of the depth image that are considered by the visual odometry method...
Definition: CDifodo.h:187
A numeric matrix of compile-time fixed size.
math::CMatrixFloat66 est_cov
Least squares covariance matrix.
Definition: CDifodo.h:87
math::CMatrixFloat61 kai_abs
Last filtered speed in absolute coordinates.
Definition: CDifodo.h:115
mrpt::math::CMatrixFloat61 getSolverSolution() const
It gets the camera speed (vx, vy, vz, wx, wy, wz) expressed in local reference frame estimated by the...
Definition: CDifodo.h:214
This abstract class implements a method called "Difodo" to perform Visual odometry with range cameras...
Definition: CDifodo.h:53
void getFOV(float &cur_fovh, float &cur_fovv) const
It gets the horizontal and vertical field of vision (in degrees)
Definition: CDifodo.h:193
float x_incr
Separation between pixels (cols) in the sensor array (meters)
Definition: CDifodo.h:91
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
MatrixXf depth
Matrices that store the point coordinates after downsampling.
Definition: CDifodo.h:62
MatrixXf weights
Weights used to ponder equations in the least square solution.
Definition: CDifodo.h:78
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
unsigned int num_valid_points
Num of valid points after removing null pixels and borders.
Definition: CDifodo.h:158
CPose3D cam_oldpose
Previous camera pose.
Definition: CDifodo.h:172
float dt_threshold
Threshold to dt.
Definition: CDifodo.h:162
float dift_surroundings
Threshold to the difference of dt at a pixel and the value of dt at its surroundings.
Definition: CDifodo.h:165
float fovh
Horizontal field of view (rad)
Definition: CDifodo.h:93
void setSpeedFilterConstWeight(float new_cweight)
It sets the weight that ponders the previous speed in order to calculate the filtered speed...
Definition: CDifodo.h:202
void setSpeedFilterEigWeight(float new_eweight)
It sets the weight that ponders the product of the corresponding eigenvalue and the previous speed in...
Definition: CDifodo.h:205
MatrixXf yy_inter
Definition: CDifodo.h:69
float getSpeedFilterConstWeight() const
It gets the weight that ponders the previous speed in order to calculate the filtered speed...
Definition: CDifodo.h:196
float fovv
Vertical field of view (rad)
Definition: CDifodo.h:94
unsigned int downsample
Downsample the image taken by the range camera.
Definition: CDifodo.h:155
float duv_threshold
Thresholds used to remove borders and noisy points.
Definition: CDifodo.h:161
math::CMatrixFloat61 kai_solver
Solution from the solver: kai before applying the filter in local coordinates.
Definition: CDifodo.h:112
MatrixXf depth_ft
Matrices that store the original and filtered depth frames with the image resolution.
Definition: CDifodo.h:58
float getSpeedFilterEigWeight() const
It gets the weight that ponders the product of the corresponding eigenvalue and the previous speed in...
Definition: CDifodo.h:199
unsigned int cam_mode
Resolution of the images taken by the range camera.
Definition: CDifodo.h:151
float f_dist
Camera properties:
Definition: CDifodo.h:90



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014