Main MRPT website > C++ reference
MRPT logo
bundle_adjustment.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 mrpt_vision_ba_H
11 #define mrpt_vision_ba_H
12 
13 #include <mrpt/vision/types.h>
14 #include <mrpt/utils/TCamera.h>
15 #include <mrpt/utils/TParameters.h>
17 #include <mrpt/math/CArray.h>
18 
19 // The methods declared in this file are implemented in separate files in: vision/src/ba_*.cpp
20 namespace mrpt
21 {
22  namespace vision
23  {
24  using mrpt::math::CArray;
25  using mrpt::math::TPose3D;
28 
29  /** \defgroup bundle_adj Bundle-Adjustment methods
30  * \ingroup mrpt_vision_grp
31  */
32 
33 
34  /** @name Bundle-Adjustment methods
35  @{ */
36 
37  /** A functor type for BA methods \sa bundle_adj_full */
39  const size_t cur_iter,
40  const double cur_total_sq_error,
41  const size_t max_iters,
42  const mrpt::vision::TSequenceFeatureObservations & input_observations,
43  const mrpt::vision::TFramePosesVec & current_frame_estimate,
44  const mrpt::vision::TLandmarkLocationsVec & current_landmark_estimate );
45 
46 
47  /** Sparse Levenberg-Marquart solution to bundle adjustment - optimizes all the camera frames & the landmark locations.
48  * At input a gross estimation of the frame poses & the landmark points must be supplied. If you don't have such a
49  * starting point, use mrpt::vision::ba_initial_estimate() to compute it.
50  *
51  * At output the best found solution will be returned in the variables. Optionally, a functor can be passed for having
52  * feedback on the progress at each iteration (you can use it to refresh a GUI, display a progress bar, etc...).
53  *
54  * This implementation is almost entirely an adapted version from RobotVision (at OpenSLAM.org) (C) by Hauke Strasdat (Imperial College London), licensed under GNU LGPL.
55  * See the related paper: H. Strasdat, J.M.M. Montiel, A.J. Davison: "Scale Drift-Aware Large Scale Monocular SLAM", RSS2010, http://www.roboticsproceedings.org/rss06/p10.html
56  *
57  * List of optional parameters in "extra_params":
58  * - "verbose" : Verbose output (default=0)
59  * - "max_iterations": Maximum number of iterations to run (default=50)
60  * - "robust_kernel": If !=0, use a robust kernel against outliers (default=1)
61  * - "kernel_param": The pseudo-huber kernel parameter (default=3)
62  * - "mu": Initial mu for LevMarq (default=-1 -> autoguess)
63  * - "num_fix_frames": Number of first frame poses to don't optimize (keep unmodified as they come in) (default=1: the first pose is the reference and is not modified)
64  * - "num_fix_points": Idem, for the landmarks positions (default=0: optimize all)
65  * - "profiler": If !=0, displays profiling information to the console at return.
66  *
67  * \note In this function, all coordinates are absolute. Camera frames are such that +Z points forward from the focal point (see the figure in mrpt::slam::CObservationImage).
68  * \note The first frame pose will be not updated since at least one frame must remain fixed.
69  *
70  * \param observations [IN] All the feature observations (WITHOUT distortion), indexed by feature ID as lists of <frame_ID, (x,y)>. See TSequenceFeatureObservations.
71  * \param camera_params [IN] The camera parameters, mainly used for the intrinsic 3x3 matrix. Distortion params are ignored since it's assumed that \a observations are already undistorted pixels.
72  * \param frame_poses [IN/OUT] Input: Gross estimation of each frame poses. Output: The found optimal solution.
73  * \param landmark_points [IN/OUT] Input: Gross estimation of each landmark point. Output: The found optimal solution.
74  * \param extra_params [IN] Optional extra parameters. Read above.
75  * \param user_feedback [IN] If provided, this functor will be called at each iteration to provide a feedback to the user.
76  *
77  * \return The final overall squared error.
78  * \ingroup bundle_adj
79  */
81  const mrpt::vision::TSequenceFeatureObservations & observations,
82  const mrpt::utils::TCamera & camera_params,
83  mrpt::vision::TFramePosesVec & frame_poses,
84  mrpt::vision::TLandmarkLocationsVec & landmark_points,
86  const mrpt::vision::TBundleAdjustmentFeedbackFunctor user_feedback = NULL
87  );
88 
89 
90  /** @} */
91 
92 
93  /** @name Bundle-Adjustment Auxiliary methods
94  @{ */
95 
96  /** Fills the frames & landmark points maps with an initial gross estimate from the sequence \a observations, so they can be fed to bundle adjustment methods.
97  * \sa bundle_adj_full
98  * \ingroup bundle_adj
99  */
101  const mrpt::vision::TSequenceFeatureObservations & observations,
102  const mrpt::utils::TCamera & camera_params,
103  mrpt::vision::TFramePosesVec & frame_poses,
104  mrpt::vision::TLandmarkLocationsVec & landmark_points );
105 
106  //! \overload
108  const mrpt::vision::TSequenceFeatureObservations & observations,
109  const mrpt::utils::TCamera & camera_params,
110  mrpt::vision::TFramePosesMap & frame_poses,
111  mrpt::vision::TLandmarkLocationsMap & landmark_points );
112 
113 
114  /** Compute reprojection error vector (used from within Bundle Adjustment methods, but can be used in general)
115  * See mrpt::vision::bundle_adj_full for a description of most parameters.
116  * \param frame_poses_are_inverse If set to true, global camera poses are \f$ \ominus F \f$ instead of \f$ F \f$, for each F in frame_poses.
117  *
118  * \return Overall squared reprojection error.
119  * \ingroup bundle_adj
120  */
122  const mrpt::vision::TSequenceFeatureObservations & observations,
123  const mrpt::utils::TCamera & camera_params,
124  const mrpt::vision::TFramePosesVec & frame_poses,
125  const mrpt::vision::TLandmarkLocationsVec & landmark_points,
126  std::vector<CArray<double,2> > & out_residuals,
127  const bool frame_poses_are_inverse,
128  const bool use_robust_kernel = true,
129  const double kernel_param = 3.0,
130  std::vector<double> * out_kernel_1st_deriv = NULL
131  );
132 
133  //! \overload
135  const mrpt::vision::TSequenceFeatureObservations & observations,
136  const mrpt::utils::TCamera & camera_params,
137  const mrpt::vision::TFramePosesMap & frame_poses,
138  const mrpt::vision::TLandmarkLocationsMap & landmark_points,
139  std::vector<CArray<double,2> > & out_residuals,
140  const bool frame_poses_are_inverse,
141  const bool use_robust_kernel = true,
142  const double kernel_param = 3.0,
143  std::vector<double> * out_kernel_1st_deriv = NULL
144  );
145 
146 
147  /** For each pose in the vector \a frame_poses, adds a "delta" increment to the manifold, with the "delta" given in the se(3) Lie algebra:
148  *
149  * new_frame_poses[i] = frame_poses[i] [+] delta[(first_idx+6*i):(first_idx+6*i+5)] , for every pose in \a frame_poses
150  *
151  * With the left-multiplication convention of the manifold exp(delta) operator, that is:
152  *
153  * p <-- p [+] delta ==> p <-- exp(delta) * p
154  *
155  * \param delta_num_vals Used just for sanity check, must be equal to "frame_poses.size() * 6"
156  * \ingroup bundle_adj
157  */
159  const mrpt::vision::TFramePosesVec & frame_poses,
160  const mrpt::math::CVectorDouble &delta,
161  const size_t delta_first_idx,
162  const size_t delta_num_vals,
163  mrpt::vision::TFramePosesVec & new_frame_poses,
164  const size_t num_fix_frames );
165 
166  /** For each pose in the vector \a frame_poses, adds a "delta" increment to the manifold, with the "delta" given in the se(3) Lie algebra:
167  *
168  * new_landmark_points[i] = landmark_points[i] + delta[(first_idx+3*i):(first_idx+3*i+2)] , for every pose in \a landmark_points
169  *
170  * \param delta_num_vals Used just for sanity check, must be equal to "landmark_points.size() * 3"
171  * \ingroup bundle_adj
172  */
174  const mrpt::vision::TLandmarkLocationsVec & landmark_points,
175  const mrpt::math::CVectorDouble & delta,
176  const size_t delta_first_idx,
177  const size_t delta_num_vals,
178  mrpt::vision::TLandmarkLocationsVec & new_landmark_points,
179  const size_t num_fix_points );
180 
181  /** @} */
182  }
183 }
184 #endif
185 
double VISION_IMPEXP reprojectionResiduals(const mrpt::vision::TSequenceFeatureObservations &observations, const mrpt::utils::TCamera &camera_params, const mrpt::vision::TFramePosesVec &frame_poses, const mrpt::vision::TLandmarkLocationsVec &landmark_points, std::vector< CArray< double, 2 > > &out_residuals, const bool frame_poses_are_inverse, const bool use_robust_kernel=true, const double kernel_param=3.0, std::vector< double > *out_kernel_1st_deriv=NULL)
Compute reprojection error vector (used from within Bundle Adjustment methods, but can be used in gen...
double VISION_IMPEXP bundle_adj_full(const mrpt::vision::TSequenceFeatureObservations &observations, const mrpt::utils::TCamera &camera_params, mrpt::vision::TFramePosesVec &frame_poses, mrpt::vision::TLandmarkLocationsVec &landmark_points, const mrpt::utils::TParametersDouble &extra_params=mrpt::utils::TParametersDouble(), const mrpt::vision::TBundleAdjustmentFeedbackFunctor user_feedback=NULL)
Sparse Levenberg-Marquart solution to bundle adjustment - optimizes all the camera frames & the landm...
A complete sequence of observations of features from different camera frames (poses).
mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t TFramePosesVec
A list of camera frames (6D poses), which assumes indexes are unique, consecutive IDs...
void VISION_IMPEXP add_3d_deltas_to_points(const mrpt::vision::TLandmarkLocationsVec &landmark_points, const mrpt::math::CVectorDouble &delta, const size_t delta_first_idx, const size_t delta_num_vals, mrpt::vision::TLandmarkLocationsVec &new_landmark_points, const size_t num_fix_points)
For each pose in the vector frame_poses, adds a "delta" increment to the manifold, with the "delta" given in the se(3) Lie algebra:
void VISION_IMPEXP add_se3_deltas_to_frames(const mrpt::vision::TFramePosesVec &frame_poses, const mrpt::math::CVectorDouble &delta, const size_t delta_first_idx, const size_t delta_num_vals, mrpt::vision::TFramePosesVec &new_frame_poses, const size_t num_fix_frames)
For each pose in the vector frame_poses, adds a "delta" increment to the manifold, with the "delta" given in the se(3) Lie algebra:
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:51
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A STL container (as wrapper) for arrays of constant size defined at compile time - Users will most li...
Definition: CArray.h:55
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
std::vector< mrpt::math::TPoint3D > TLandmarkLocationsVec
A list of landmarks (3D points), which assumes indexes are unique, consecutive IDs.
std::map< TLandmarkID, mrpt::math::TPoint3D > TLandmarkLocationsMap
A list of landmarks (3D points) indexed by unique IDs.
Lightweight 3D point.
void(* TBundleAdjustmentFeedbackFunctor)(const size_t cur_iter, const double cur_total_sq_error, const size_t max_iters, const mrpt::vision::TSequenceFeatureObservations &input_observations, const mrpt::vision::TFramePosesVec &current_frame_estimate, const mrpt::vision::TLandmarkLocationsVec &current_landmark_estimate)
A functor type for BA methods.
mrpt::aligned_containers< TCameraPoseID, mrpt::poses::CPose3D >::map_t TFramePosesMap
A list of camera frames (6D poses) indexed by unique IDs.
void VISION_IMPEXP ba_initial_estimate(const mrpt::vision::TSequenceFeatureObservations &observations, const mrpt::utils::TCamera &camera_params, mrpt::vision::TFramePosesVec &frame_poses, mrpt::vision::TLandmarkLocationsVec &landmark_points)
Fills the frames & landmark points maps with an initial gross estimate from the sequence observations...
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:31



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