MRPT  1.9.9
bundle_adjustment.h
Go to the documentation of this file.
1 /**
2  * Copyright (C) 2010 Hauke Strasdat
3  * Imperial College London
4  * Copyright (c) 2005-2018, Individual contributors, see AUTHORS file
5  * See: http://www.mrpt.org/Authors - All rights reserved.
6  *
7  * bundle_adjuster.h is part of RobotVision.
8  *
9  * RobotVision is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation, either version 3 of the
12  * License, or any later version.
13  *
14  * RobotVision is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * and the GNU Lesser General Public License along with this program.
21  * If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef mrpt_vision_ba_H
25 #define mrpt_vision_ba_H
26 
27 #include <mrpt/vision/types.h>
28 #include <mrpt/img/TCamera.h>
31 
32 #include <array>
33 #include <functional>
34 
35 // The methods declared in this file are implemented in separate files in:
36 // vision/src/ba_*.cpp
37 namespace mrpt::vision
38 {
39 /** \defgroup bundle_adj Bundle-Adjustment methods
40  * \ingroup mrpt_vision_grp
41  */
42 
43 /** @name Bundle-Adjustment methods
44  @{ */
45 
46 /** A functor type for BA methods \sa bundle_adj_full */
47 using TBundleAdjustmentFeedbackFunctor = std::function<void(
48  const size_t cur_iter, const double cur_total_sq_error,
49  const size_t max_iters,
50  const mrpt::vision::TSequenceFeatureObservations& input_observations,
51  const mrpt::vision::TFramePosesVec& current_frame_estimate,
52  const mrpt::vision::TLandmarkLocationsVec& current_landmark_estimate)>;
53 
54 /** Sparse Levenberg-Marquart solution to bundle adjustment - optimizes all the
55  *camera frames & the landmark locations.
56  * At input a gross estimation of the frame poses & the landmark points must be
57  *supplied. If you don't have such a
58  * starting point, use mrpt::vision::ba_initial_estimate() to compute it.
59  *
60  * At output the best found solution will be returned in the variables.
61  *Optionally, a functor can be passed for having
62  * feedback on the progress at each iteration (you can use it to refresh a
63  *GUI, display a progress bar, etc...).
64  *
65  * This implementation is almost entirely an adapted version from RobotVision
66  *(at OpenSLAM.org) (C) by Hauke Strasdat (Imperial College London), licensed
67  *under GNU LGPL.
68  * See the related paper: H. Strasdat, J.M.M. Montiel, A.J. Davison: "Scale
69  *Drift-Aware Large Scale Monocular SLAM", RSS2010,
70  *http://www.roboticsproceedings.org/rss06/p10.html
71  *
72  * List of optional parameters in "extra_params":
73  * - "verbose" : Verbose output (default=0)
74  * - "max_iterations": Maximum number of iterations to run (default=50)
75  * - "robust_kernel": If !=0, use a robust kernel against outliers
76  *(default=1)
77  * - "kernel_param": The pseudo-huber kernel parameter (default=3)
78  * - "mu": Initial mu for LevMarq (default=-1 -> autoguess)
79  * - "num_fix_frames": Number of first frame poses to don't optimize (keep
80  *unmodified as they come in) (default=1: the first pose is the reference and
81  *is not modified)
82  * - "num_fix_points": Idem, for the landmarks positions (default=0:
83  *optimize
84  *all)
85  * - "profiler": If !=0, displays profiling information to the console at
86  *return.
87  *
88  * \note In this function, all coordinates are absolute. Camera frames are such
89  *that +Z points forward from the focal point (see the figure in
90  *mrpt::obs::CObservationImage).
91  * \note The first frame pose will be not updated since at least one frame must
92  *remain fixed.
93  *
94  * \param observations [IN] All the feature observations (WITHOUT distortion),
95  *indexed by feature ID as lists of <frame_ID, (x,y)>. See
96  *TSequenceFeatureObservations.
97  * \param camera_params [IN] The camera parameters, mainly used for the
98  *intrinsic 3x3 matrix. Distortion params are ignored since it's assumed that
99  *\a observations are already undistorted pixels.
100  * \param frame_poses [IN/OUT] Input: Gross estimation of each frame poses.
101  *Output: The found optimal solution.
102  * \param landmark_points [IN/OUT] Input: Gross estimation of each landmark
103  *point. Output: The found optimal solution.
104  * \param extra_params [IN] Optional extra parameters. Read above.
105  * \param user_feedback [IN] If provided, this functor will be called at each
106  *iteration to provide a feedback to the user.
107  *
108  * \return The final overall squared error.
109  * \ingroup bundle_adj
110  */
111 double bundle_adj_full(
112  const mrpt::vision::TSequenceFeatureObservations& observations,
113  const mrpt::img::TCamera& camera_params,
114  mrpt::vision::TFramePosesVec& frame_poses,
115  mrpt::vision::TLandmarkLocationsVec& landmark_points,
116  const mrpt::system::TParametersDouble& extra_params =
120 
121 /** @} */
122 
123 /** @name Bundle-Adjustment Auxiliary methods
124  @{ */
125 
126 /** Fills the frames & landmark points maps with an initial gross estimate from
127  * the sequence \a observations, so they can be fed to bundle adjustment
128  * methods.
129  * \sa bundle_adj_full
130  * \ingroup bundle_adj
131  */
133  const mrpt::vision::TSequenceFeatureObservations& observations,
134  const mrpt::img::TCamera& camera_params,
135  mrpt::vision::TFramePosesVec& frame_poses,
136  mrpt::vision::TLandmarkLocationsVec& landmark_points);
137 
138 //! \overload
140  const mrpt::vision::TSequenceFeatureObservations& observations,
141  const mrpt::img::TCamera& camera_params,
142  mrpt::vision::TFramePosesMap& frame_poses,
143  mrpt::vision::TLandmarkLocationsMap& landmark_points);
144 
145 /** Compute reprojection error vector (used from within Bundle Adjustment
146  * methods, but can be used in general)
147  * See mrpt::vision::bundle_adj_full for a description of most parameters.
148  * \param frame_poses_are_inverse If set to true, global camera poses are \f$
149  * \ominus F \f$ instead of \f$ F \f$, for each F in frame_poses.
150  *
151  * \return Overall squared reprojection error.
152  * \ingroup bundle_adj
153  */
154 double reprojectionResiduals(
155  const mrpt::vision::TSequenceFeatureObservations& observations,
156  const mrpt::img::TCamera& camera_params,
157  const mrpt::vision::TFramePosesVec& frame_poses,
158  const mrpt::vision::TLandmarkLocationsVec& landmark_points,
159  std::vector<std::array<double, 2>>& out_residuals,
160  const bool frame_poses_are_inverse, const bool use_robust_kernel = true,
161  const double kernel_param = 3.0,
162  std::vector<double>* out_kernel_1st_deriv = nullptr);
163 
164 //! \overload
165 double reprojectionResiduals(
166  const mrpt::vision::TSequenceFeatureObservations& observations,
167  const mrpt::img::TCamera& camera_params,
168  const mrpt::vision::TFramePosesMap& frame_poses,
169  const mrpt::vision::TLandmarkLocationsMap& landmark_points,
170  std::vector<std::array<double, 2>>& out_residuals,
171  const bool frame_poses_are_inverse, const bool use_robust_kernel = true,
172  const double kernel_param = 3.0,
173  std::vector<double>* out_kernel_1st_deriv = nullptr);
174 
175 /** For each pose in the vector \a frame_poses, adds a "delta" increment to the
176  * manifold, with the "delta" given in the se(3) Lie algebra:
177  *
178  * new_frame_poses[i] = frame_poses[i] [+]
179  * delta[(first_idx+6*i):(first_idx+6*i+5)] , for every pose in \a
180  * frame_poses
181  *
182  * With the left-multiplication convention of the manifold exp(delta)
183  * operator, that is:
184  *
185  * p <-- p [+] delta ==> p <-- exp(delta) * p
186  *
187  * \param delta_num_vals Used just for sanity check, must be equal to
188  * "frame_poses.size() * 6"
189  * \ingroup bundle_adj
190  */
192  const mrpt::vision::TFramePosesVec& frame_poses,
193  const mrpt::math::CVectorDouble& delta, const size_t delta_first_idx,
194  const size_t delta_num_vals, mrpt::vision::TFramePosesVec& new_frame_poses,
195  const size_t num_fix_frames);
196 
197 /** For each pose in the vector \a frame_poses, adds a "delta" increment to the
198  * manifold, with the "delta" given in the se(3) Lie algebra:
199  *
200  * new_landmark_points[i] = landmark_points[i] +
201  * delta[(first_idx+3*i):(first_idx+3*i+2)] , for every pose in \a
202  * landmark_points
203  *
204  * \param delta_num_vals Used just for sanity check, must be equal to
205  * "landmark_points.size() * 3"
206  * \ingroup bundle_adj
207  */
209  const mrpt::vision::TLandmarkLocationsVec& landmark_points,
210  const mrpt::math::CVectorDouble& delta, const size_t delta_first_idx,
211  const size_t delta_num_vals,
212  mrpt::vision::TLandmarkLocationsVec& new_landmark_points,
213  const size_t num_fix_points);
214 
215 /** @} */
216 }
217 #endif
218 
219 
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:44
void ba_initial_estimate(const mrpt::vision::TSequenceFeatureObservations &observations, const mrpt::img::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...
Definition: ba_common.cpp:74
void 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:
Definition: ba_common.cpp:328
A complete sequence of observations of features from different camera frames (poses).
void 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:
Definition: ba_common.cpp:364
std::map< TLandmarkID, mrpt::math::TPoint3D > TLandmarkLocationsMap
A list of landmarks (3D points) indexed by unique IDs.
Classes for computer vision, detectors, features, etc.
Definition: CCamModel.h:18
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:27
double reprojectionResiduals(const mrpt::vision::TSequenceFeatureObservations &observations, const mrpt::img::TCamera &camera_params, const mrpt::vision::TFramePosesVec &frame_poses, const mrpt::vision::TLandmarkLocationsVec &landmark_points, std::vector< std::array< 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=nullptr)
Compute reprojection error vector (used from within Bundle Adjustment methods, but can be used in gen...
Definition: ba_common.cpp:205
mrpt::aligned_std_vector< mrpt::poses::CPose3D > TFramePosesVec
A list of camera frames (6D poses), which assumes indexes are unique, consecutive IDs...
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
mrpt::aligned_std_map< TCameraPoseID, mrpt::poses::CPose3D > TFramePosesMap
A list of camera frames (6D poses) indexed by unique IDs.
double bundle_adj_full(const mrpt::vision::TSequenceFeatureObservations &observations, const mrpt::img::TCamera &camera_params, mrpt::vision::TFramePosesVec &frame_poses, mrpt::vision::TLandmarkLocationsVec &landmark_points, const mrpt::system::TParametersDouble &extra_params=mrpt::system::TParametersDouble(), const mrpt::vision::TBundleAdjustmentFeedbackFunctor user_feedback=mrpt::vision::TBundleAdjustmentFeedbackFunctor())
Sparse Levenberg-Marquart solution to bundle adjustment - optimizes all the camera frames & the landm...
Definition: ba_full.cpp:51
std::function< void(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)> TBundleAdjustmentFeedbackFunctor
A functor type for BA methods.
std::vector< mrpt::math::TPoint3D > TLandmarkLocationsVec
A list of landmarks (3D points), which assumes indexes are unique, consecutive IDs.



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