MRPT  1.9.9
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-2018, 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/math/types_math.h> // Eigen
15 #include <mrpt/poses/CPose3D.h>
16 //#include <unsupported/Eigen/MatrixFunctions>
17 
18 namespace mrpt::vision
19 {
20 /** This abstract class implements a method called "Difodo" to perform Visual
21  *odometry with range cameras.
22  * It is based on the range flow equation and assumes that the scene is rigid.
23  * It can work with different image resolutions (640 x 480, 320 x 240 or 160 x
24  *120) and a different number of
25  * coarse-to-fine levels which can be adjusted with the member variables
26  *(rows,cols,ctf_levels).
27  *
28  * How to use:
29  * - A derived class must be created which defines the method
30  *"loadFrame(...)"
31  *according to the user application.
32  * This method has to load the depth image into the variable "depth_wf".
33  * - Call loadFrame();
34  * - Call odometryCalculation();
35  *
36  * For further information have a look at the apps:
37  * -
38  *[DifOdometry-Camera](http://www.mrpt.org/list-of-mrpt-apps/application-difodometry-camera/)
39  * -
40  *[DifOdometry-Datasets](http://www.mrpt.org/list-of-mrpt-apps/application-difodometry-datasets/)
41  *
42  * Please refer to the respective publication when using this method:
43  * title = {Fast Visual Odometry for {3-D} Range Sensors},
44  * author = {Jaimez, Mariano and Gonzalez-Jimenez, Javier},
45  * journal = {IEEE Transactions on Robotics},
46  * volume = {31},
47  * number = {4},
48  * pages = {809 - 822},
49  * year = {2015}
50  *
51  * - JUN/2013: First design.
52  * - JAN/2014: Integrated into MRPT library.
53  * - DIC/2014: Reformulated and improved. The class now needs Eigen version
54  *3.1.0 or above.
55  *
56  * \sa CDifodoCamera, CDifodoDatasets
57  * \ingroup mrpt_vision_grp
58  */
59 
60 class CDifodo
61 {
62  protected:
63  /** Matrix that stores the original depth frames with the image resolution
64  */
65  Eigen::MatrixXf depth_wf;
66 
67  /** Matrices that store the point coordinates after downsampling. */
68  std::vector<Eigen::MatrixXf> depth;
69  std::vector<Eigen::MatrixXf> depth_old;
70  std::vector<Eigen::MatrixXf> depth_inter;
71  std::vector<Eigen::MatrixXf> depth_warped;
72  std::vector<Eigen::MatrixXf> xx;
73  std::vector<Eigen::MatrixXf> xx_inter;
74  std::vector<Eigen::MatrixXf> xx_old;
75  std::vector<Eigen::MatrixXf> xx_warped;
76  std::vector<Eigen::MatrixXf> yy;
77  std::vector<Eigen::MatrixXf> yy_inter;
78  std::vector<Eigen::MatrixXf> yy_old;
79  std::vector<Eigen::MatrixXf> yy_warped;
80 
81  /** Matrices that store the depth derivatives */
82  Eigen::MatrixXf du;
83  Eigen::MatrixXf dv;
84  Eigen::MatrixXf dt;
85 
86  /** Weights for the range flow constraint equations in the least square
87  * solution */
88  Eigen::MatrixXf weights;
89 
90  /** Matrix which indicates whether the depth of a pixel is zero (null = 1)
91  * or not (null = 00).*/
92  Eigen::Matrix<bool, Eigen::Dynamic, Eigen::Dynamic> null;
93 
94  /** Least squares covariance matrix */
95  Eigen::Matrix<float, 6, 6> est_cov;
96 
97  /** Gaussian masks used to build the pyramid and flag to select accurate or
98  * fast pyramid*/
100  Eigen::Matrix4f f_mask;
101  float g_mask[5][5];
102 
103  /** Camera properties: */
104  /**Horizontal field of view (rad) */
105  float fovh;
106  /**Vertical field of view (rad) */
107  float fovv;
108 
109  /** The maximum resolution that will be considered by the visual odometry
110  * method.
111  * As a rule, the higher the resolution the slower but more accurate the
112  * method becomes.
113  * They always have to be less or equal to the size of the original depth
114  * image. */
115  unsigned int rows;
116  unsigned int cols;
117 
118  /** Aux variables: size from which the pyramid starts to be built */
119  unsigned int width;
120  unsigned int height;
121 
122  /** Aux variables: number of rows and cols at a given level */
123  unsigned int rows_i;
124  unsigned int cols_i;
125 
126  /** Number of coarse-to-fine levels. I has to be consistent with the number
127  * of rows and cols, because the
128  * coarsest level cannot be smaller than 15 x 20. */
129  unsigned int ctf_levels;
130 
131  /** Aux varibles: levels of the image pyramid and the solver, respectively
132  */
133  unsigned int image_level;
134  unsigned int level;
135 
136  /** Speed filter parameters:
137  * Previous_speed_const_weight - Directly weights the previous speed in
138  * order to calculate the filtered velocity. Recommended range - (0, 0.5)
139  * Previous_speed_eig_weight - Weights the product of the corresponding
140  * eigenvalue and the previous velocity to calculate the filtered velocity*/
141  /**Default 0.05 */
143  /**Default 0.5 */
145 
146  /** Transformations of the coarse-to-fine levels */
147  std::vector<Eigen::MatrixXf> transformations;
148 
149  /** Solution from the solver at a given level */
150  Eigen::Matrix<float, 6, 1> kai_loc_level;
151 
152  /** Last filtered velocity in absolute coordinates */
153  Eigen::Matrix<float, 6, 1> kai_abs;
154 
155  /** Filtered velocity in local coordinates */
156  Eigen::Matrix<float, 6, 1> kai_loc;
157  Eigen::Matrix<float, 6, 1> kai_loc_old;
158 
159  /** Create the gaussian image pyramid according to the number of
160  * coarse-to-fine levels */
163 
164  /** Warp the second depth image against the first one according to the 3D
165  * transformations accumulated up to a given level */
166  void performWarping();
167 
168  /** Calculate the "average" coordinates of the points observed by the camera
169  * between two consecutive frames and find the Null measurements */
170  void calculateCoord();
171 
172  /** Calculates the depth derivatives respect to u,v (rows and cols) and t
173  * (time) */
175 
176  /** This method computes the weighting fuction associated to measurement and
177  * linearization errors */
178  void computeWeights();
179 
180  /** The Solver. It buils the overdetermined system and gets the least-square
181  * solution.
182  * It also calculates the least-square covariance matrix */
183  void solveOneLevel();
184 
185  /** Method to filter the velocity at each level of the pyramid. */
186  void filterLevelSolution();
187 
188  /** Update camera pose and the velocities for the filter */
189  void poseUpdate();
190 
191  public:
192  /** Frames per second (Hz) */
193  float fps;
194 
195  /** Resolution of the images taken by the range camera */
196  unsigned int cam_mode; // (1 - 640 x 480, 2 - 320 x 240, 4 - 160 x 120)
197 
198  /** Downsample the image taken by the range camera. Useful to reduce the
199  computational burden,
200  * as this downsampling is applied before the gaussian pyramid is built. It
201  must be used when
202  the virtual method "loadFrame()" is implemented */
203  unsigned int downsample; // (1 - original size, 2 - res/2, 4 - res/4)
204 
205  /** Num of valid points after removing null pixels*/
206  unsigned int num_valid_points;
207 
208  /** Execution time (ms) */
210 
211  /** Camera poses */
212  /** Last camera pose */
214  /** Previous camera pose */
216 
217  /** This method performs all the necessary steps to estimate the camera
218  velocity once the new image is read,
219  and updates the camera pose */
220  void odometryCalculation();
221 
222  /** Get the rows and cols of the depth image that are considered by the
223  * visual odometry method. */
224  inline void getRowsAndCols(
225  unsigned int& num_rows, unsigned int& num_cols) const
226  {
227  num_rows = rows;
228  num_cols = cols;
229  }
230 
231  /** Get the number of coarse-to-fine levels that are considered by the
232  * visual odometry method. */
233  inline void getCTFLevels(unsigned int& levels) const
234  {
235  levels = ctf_levels;
236  }
237 
238  /** Set the horizontal and vertical field of vision (in degrees) */
239  inline void setFOV(float new_fovh, float new_fovv);
240 
241  /** Get the horizontal and vertical field of vision (in degrees) */
242  inline void getFOV(float& cur_fovh, float& cur_fovv) const
243  {
244  cur_fovh = 57.296 * fovh;
245  cur_fovv = 57.296 * fovv;
246  }
247 
248  /** Get the filter constant-weight of the velocity filter. */
249  inline float getSpeedFilterConstWeight() const
250  {
252  }
253 
254  /** Get the filter eigen-weight of the velocity filter. */
255  inline float getSpeedFilterEigWeight() const
256  {
258  }
259 
260  /** Set the filter constant-weight of the velocity filter. */
261  inline void setSpeedFilterConstWeight(float new_cweight)
262  {
263  previous_speed_const_weight = new_cweight;
264  }
265 
266  /** Set the filter eigen-weight of the velocity filter. */
267  inline void setSpeedFilterEigWeight(float new_eweight)
268  {
269  previous_speed_eig_weight = new_eweight;
270  }
271 
272  /** Get the coordinates of the points considered by the visual odometry
273  * method */
274  inline void getPointsCoord(
275  Eigen::MatrixXf& x, Eigen::MatrixXf& y, Eigen::MatrixXf& z);
276 
277  /** Get the depth derivatives (last level) respect to u,v and t respectively
278  */
279  inline void getDepthDerivatives(
280  Eigen::MatrixXf& cur_du, Eigen::MatrixXf& cur_dv,
281  Eigen::MatrixXf& cur_dt);
282 
283  /** Get the camera velocity (vx, vy, vz, wx, wy, wz) expressed in local
284  * reference frame estimated by the solver (before filtering) */
286  {
287  return kai_loc_level;
288  }
289 
290  /** Get the last camera velocity (vx, vy, vz, wx, wy, wz) expressed in the
291  * world reference frame, obtained after filtering */
293  {
294  return kai_abs;
295  }
296 
297  /** Get the least-square covariance matrix */
299  /** Get the matrix of weights */
300  inline void getWeights(Eigen::MatrixXf& we);
301 
302  /** Virtual method to be implemented in derived classes.
303  * It should be used to load a new depth image into the variable depth_wf
304  */
305  virtual void loadFrame() = 0;
306 
307  // Constructor. Initialize variables and matrix sizes
308  CDifodo();
309 };
310 }
311 #endif
312 
313 
unsigned int cols_i
Definition: CDifodo.h:124
float previous_speed_const_weight
Speed filter parameters: Previous_speed_const_weight - Directly weights the previous speed in order t...
Definition: CDifodo.h:142
unsigned int image_level
Aux varibles: levels of the image pyramid and the solver, respectively.
Definition: CDifodo.h:133
std::vector< Eigen::MatrixXf > xx
Definition: CDifodo.h:72
mrpt::poses::CPose3D cam_oldpose
Previous camera pose.
Definition: CDifodo.h:215
std::vector< Eigen::MatrixXf > depth_warped
Definition: CDifodo.h:71
std::vector< Eigen::MatrixXf > yy_warped
Definition: CDifodo.h:79
GLdouble GLdouble z
Definition: glext.h:3872
float fps
Frames per second (Hz)
Definition: CDifodo.h:193
unsigned int rows_i
Aux variables: number of rows and cols at a given level.
Definition: CDifodo.h:123
float previous_speed_eig_weight
Default 0.5.
Definition: CDifodo.h:144
unsigned int cols
Definition: CDifodo.h:116
std::vector< Eigen::MatrixXf > xx_old
Definition: CDifodo.h:74
std::vector< Eigen::MatrixXf > xx_warped
Definition: CDifodo.h:75
void buildCoordinatesPyramid()
Create the gaussian image pyramid according to the number of coarse-to-fine levels.
Definition: CDifodo.cpp:110
void calculateDepthDerivatives()
Calculates the depth derivatives respect to u,v (rows and cols) and t (time)
Definition: CDifodo.cpp:538
float getSpeedFilterConstWeight() const
Get the filter constant-weight of the velocity filter.
Definition: CDifodo.h:249
void getCTFLevels(unsigned int &levels) const
Get the number of coarse-to-fine levels that are considered by the visual odometry method...
Definition: CDifodo.h:233
mrpt::math::CMatrixFloat61 getSolverSolution() const
Get the camera velocity (vx, vy, vz, wx, wy, wz) expressed in local reference frame estimated by the ...
Definition: CDifodo.h:285
std::vector< Eigen::MatrixXf > transformations
Transformations of the coarse-to-fine levels.
Definition: CDifodo.h:147
unsigned int rows
The maximum resolution that will be considered by the visual odometry method.
Definition: CDifodo.h:115
virtual void loadFrame()=0
Virtual method to be implemented in derived classes.
Eigen::MatrixXf depth_wf
Matrix that stores the original depth frames with the image resolution.
Definition: CDifodo.h:65
mrpt::math::CMatrixFloat66 getCovariance() const
Get the least-square covariance matrix.
Definition: CDifodo.h:298
Eigen::MatrixXf dv
Definition: CDifodo.h:83
std::vector< Eigen::MatrixXf > yy_old
Definition: CDifodo.h:78
float getSpeedFilterEigWeight() const
Get the filter eigen-weight of the velocity filter.
Definition: CDifodo.h:255
Eigen::Matrix< float, 6, 1 > kai_abs
Last filtered velocity in absolute coordinates.
Definition: CDifodo.h:153
bool fast_pyramid
Gaussian masks used to build the pyramid and flag to select accurate or fast pyramid.
Definition: CDifodo.h:99
void computeWeights()
This method computes the weighting fuction associated to measurement and linearization errors...
Definition: CDifodo.cpp:618
void solveOneLevel()
The Solver.
Definition: CDifodo.cpp:756
float execution_time
Execution time (ms)
Definition: CDifodo.h:209
void setFOV(float new_fovh, float new_fovv)
Set the horizontal and vertical field of vision (in degrees)
Definition: CDifodo.cpp:997
void odometryCalculation()
This method performs all the necessary steps to estimate the camera velocity once the new image is re...
Definition: CDifodo.cpp:814
void calculateCoord()
Calculate the "average" coordinates of the points observed by the camera between two consecutive fram...
Definition: CDifodo.cpp:503
A numeric matrix of compile-time fixed size.
void getDepthDerivatives(Eigen::MatrixXf &cur_du, Eigen::MatrixXf &cur_dv, Eigen::MatrixXf &cur_dt)
Get the depth derivatives (last level) respect to u,v and t respectively.
Definition: CDifodo.cpp:1014
Eigen::MatrixXf weights
Weights for the range flow constraint equations in the least square solution.
Definition: CDifodo.h:88
unsigned int height
Definition: CDifodo.h:120
Eigen::Matrix4f f_mask
Definition: CDifodo.h:100
void getWeights(Eigen::MatrixXf &we)
Get the matrix of weights.
Definition: CDifodo.cpp:1026
void getFOV(float &cur_fovh, float &cur_fovv) const
Get the horizontal and vertical field of vision (in degrees)
Definition: CDifodo.h:242
mrpt::math::CMatrixFloat61 getLastSpeedAbs() const
Get the last camera velocity (vx, vy, vz, wx, wy, wz) expressed in the world reference frame...
Definition: CDifodo.h:292
Eigen::MatrixXf dt
Definition: CDifodo.h:84
std::vector< Eigen::MatrixXf > depth_inter
Definition: CDifodo.h:70
float g_mask[5][5]
Definition: CDifodo.h:101
Classes for computer vision, detectors, features, etc.
Definition: CCamModel.h:18
unsigned int width
Aux variables: size from which the pyramid starts to be built.
Definition: CDifodo.h:119
std::vector< Eigen::MatrixXf > depth_old
Definition: CDifodo.h:69
Eigen::Matrix< float, 6, 1 > kai_loc
Filtered velocity in local coordinates.
Definition: CDifodo.h:156
This abstract class implements a method called "Difodo" to perform Visual odometry with range cameras...
Definition: CDifodo.h:60
unsigned int ctf_levels
Number of coarse-to-fine levels.
Definition: CDifodo.h:129
void filterLevelSolution()
Method to filter the velocity at each level of the pyramid.
Definition: CDifodo.cpp:872
void poseUpdate()
Update camera pose and the velocities for the filter.
Definition: CDifodo.cpp:942
Eigen::Matrix< float, 6, 1 > kai_loc_level
Solution from the solver at a given level.
Definition: CDifodo.h:150
void getPointsCoord(Eigen::MatrixXf &x, Eigen::MatrixXf &y, Eigen::MatrixXf &z)
Get the coordinates of the points considered by the visual odometry method.
Definition: CDifodo.cpp:1003
Eigen::Matrix< float, 6, 1 > kai_loc_old
Definition: CDifodo.h:157
std::vector< Eigen::MatrixXf > yy
Definition: CDifodo.h:76
std::vector< Eigen::MatrixXf > yy_inter
Definition: CDifodo.h:77
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:86
unsigned int num_valid_points
Num of valid points after removing null pixels.
Definition: CDifodo.h:206
float fovh
Camera properties:
Definition: CDifodo.h:105
void setSpeedFilterConstWeight(float new_cweight)
Set the filter constant-weight of the velocity filter.
Definition: CDifodo.h:261
mrpt::poses::CPose3D cam_pose
Camera poses.
Definition: CDifodo.h:213
GLenum GLint GLint y
Definition: glext.h:3538
void setSpeedFilterEigWeight(float new_eweight)
Set the filter eigen-weight of the velocity filter.
Definition: CDifodo.h:267
Eigen::Matrix< bool, Eigen::Dynamic, Eigen::Dynamic > null
Matrix which indicates whether the depth of a pixel is zero (null = 1) or not (null = 00)...
Definition: CDifodo.h:92
Eigen::Matrix< float, 6, 6 > est_cov
Least squares covariance matrix.
Definition: CDifodo.h:95
std::vector< Eigen::MatrixXf > depth
Matrices that store the point coordinates after downsampling.
Definition: CDifodo.h:68
float fovv
Vertical field of view (rad)
Definition: CDifodo.h:107
GLenum GLint x
Definition: glext.h:3538
unsigned int downsample
Downsample the image taken by the range camera.
Definition: CDifodo.h:203
std::vector< Eigen::MatrixXf > xx_inter
Definition: CDifodo.h:73
void getRowsAndCols(unsigned int &num_rows, unsigned int &num_cols) const
Get the rows and cols of the depth image that are considered by the visual odometry method...
Definition: CDifodo.h:224
unsigned int level
Definition: CDifodo.h:134
void buildCoordinatesPyramidFast()
Definition: CDifodo.cpp:269
unsigned int cam_mode
Resolution of the images taken by the range camera.
Definition: CDifodo.h:196
Eigen::MatrixXf du
Matrices that store the depth derivatives.
Definition: CDifodo.h:82
void performWarping()
Warp the second depth image against the first one according to the 3D transformations accumulated up ...
Definition: CDifodo.cpp:386



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020