45 landmark_points.clear();
49 it != observations.end(); ++it)
54 frame_poses[frame_ID] =
CPose3D(0, 0, 0, 0, 0, 0);
55 landmark_points[feat_ID] =
TPoint3D(0, 0, 1);
73 landmark_points.clear();
75 if (observations.empty())
return;
83 it != observations.end(); ++it)
92 frame_poses.assign(max_fr_id + 1,
CPose3D(0, 0, 0, 0, 0, 0));
93 landmark_points.assign(max_pt_id + 1,
TPoint3D(0, 0, 1));
102 template <
bool POSES_INVERSE>
105 std::array<double, 2>& out_residual,
106 const TFramePosesVec::value_type& frame,
107 const TLandmarkLocationsVec::value_type& point,
double&
sum,
108 const bool use_robust_kernel,
const double kernel_param,
109 double* out_kernel_1st_deriv)
112 mrpt::vision::pinhole::projectPoint_no_distortion<POSES_INVERSE>(
113 camera_params, frame, point);
116 out_residual[0] = z_meas.x - z_pred.
x;
117 out_residual[1] = z_meas.y - z_pred.
y;
119 const double sum_2 =
square(out_residual[0]) +
square(out_residual[1]);
121 if (use_robust_kernel)
124 kernel.param_sq =
square(kernel_param);
125 double kernel_1st_deriv, kernel_2nd_deriv;
127 sum += kernel.eval(sum_2, kernel_1st_deriv, kernel_2nd_deriv);
128 if (out_kernel_1st_deriv) *out_kernel_1st_deriv = kernel_1st_deriv;
146 std::vector<std::array<double, 2>>& out_residuals,
147 const bool frame_poses_are_inverse,
const bool use_robust_kernel,
148 const double kernel_param, std::vector<double>* out_kernel_1st_deriv)
154 const size_t N = observations.size();
155 out_residuals.resize(N);
156 if (out_kernel_1st_deriv) out_kernel_1st_deriv->resize(N);
158 for (
size_t i = 0; i < N; i++)
167 ASSERTMSG_(itF != frame_poses.end(),
"Frame ID is not in list!")
168 ASSERTMSG_(itP != landmark_points.end(),
"Landmark ID is not in list!")
170 const TFramePosesMap::mapped_type& frame = itF->second;
171 const TLandmarkLocationsMap::mapped_type& point = itP->second;
173 double* ptr_1st_deriv =
174 out_kernel_1st_deriv ? &((*out_kernel_1st_deriv)[i]) :
nullptr;
176 if (frame_poses_are_inverse)
177 reprojectionResidualsElement<true>(
178 camera_params, OBS, out_residuals[i], frame, point,
sum,
179 use_robust_kernel, kernel_param, ptr_1st_deriv);
181 reprojectionResidualsElement<false>(
182 camera_params, OBS, out_residuals[i], frame, point,
sum,
183 use_robust_kernel, kernel_param, ptr_1st_deriv);
195 std::vector<std::array<double, 2>>& out_residuals,
196 const bool frame_poses_are_inverse,
const bool use_robust_kernel,
197 const double kernel_param, std::vector<double>* out_kernel_1st_deriv)
203 const size_t N = observations.size();
204 out_residuals.resize(N);
205 if (out_kernel_1st_deriv) out_kernel_1st_deriv->resize(N);
207 for (
size_t i = 0; i < N; i++)
217 const TFramePosesVec::value_type& frame = frame_poses[i_f];
218 const TLandmarkLocationsVec::value_type& point = landmark_points[i_p];
220 double* ptr_1st_deriv =
221 out_kernel_1st_deriv ? &((*out_kernel_1st_deriv)[i]) :
nullptr;
223 if (frame_poses_are_inverse)
224 reprojectionResidualsElement<true>(
225 camera_params, OBS, out_residuals[i], frame, point,
sum,
226 use_robust_kernel, kernel_param, ptr_1st_deriv);
228 reprojectionResidualsElement<false>(
229 camera_params, OBS, out_residuals[i], frame, point,
sum,
230 use_robust_kernel, kernel_param, ptr_1st_deriv);
240 const vector<std::array<double, 2>>& residual_vec,
246 const size_t num_fix_frames,
const size_t num_fix_points,
247 const vector<double>* kernel_1st_deriv)
251 const size_t N = observations.size();
252 const bool use_robust_kernel = (kernel_1st_deriv !=
nullptr);
254 for (
size_t i = 0; i < N; i++)
261 const Eigen::Matrix<double, 2, 1> RESID(&residual_vec[i][0]);
265 if (i_f >= num_fix_frames)
267 const size_t frame_id = i_f - num_fix_frames;
272 JtJ.multiply_AtA(JACOB.
J_frame);
277 if (!use_robust_kernel)
279 eps_frame[frame_id] += eps_delta;
283 const double rho_1st_der = (*kernel_1st_deriv)[i];
284 eps_frame[frame_id] += eps_delta * rho_1st_der;
288 if (i_p >= num_fix_points)
290 const size_t point_id = i_p - num_fix_points;
295 JtJ.multiply_AtA(JACOB.
J_point);
300 if (!use_robust_kernel)
302 eps_point[point_id] += eps_delta;
306 const double rho_1st_der = (*kernel_1st_deriv)[i];
307 eps_point[point_id] += eps_delta * rho_1st_der;
319 const size_t delta_first_idx,
const size_t delta_num_vals,
324 new_frame_poses.resize(frame_poses.size());
326 for (
size_t i = 0; i < num_fix_frames; ++i)
327 new_frame_poses[i] = frame_poses[i];
329 size_t delta_used_vals = 0;
330 const double* delta_val = &delta[delta_first_idx];
332 for (
size_t i = num_fix_frames; i < frame_poses.size(); i++)
334 const CPose3D& old_pose = frame_poses[i];
335 CPose3D& new_pose = new_frame_poses[i];
339 const CPose3D incrPose = CPose3D::exp(incr);
347 delta_used_vals += 6;
350 ASSERT_(delta_used_vals == delta_num_vals)
356 const size_t delta_first_idx,
const size_t delta_num_vals,
361 new_landmark_points.resize(landmark_points.size());
363 for (
size_t i = 0; i < num_fix_points; ++i)
364 new_landmark_points[i] = landmark_points[i];
366 size_t delta_used_vals = 0;
367 const double* delta_val = &delta[delta_first_idx];
369 for (
size_t i = num_fix_points; i < landmark_points.size(); i++)
371 const TPoint3D& old_point = landmark_points[i];
372 TPoint3D& new_point = new_landmark_points[i];
374 for (
size_t j = 0; j < 3; j++)
375 new_point[j] = old_point[j] + delta_val[j];
379 delta_used_vals += 3;
382 ASSERT_(delta_used_vals == delta_num_vals)
A pair (x,y) of pixel coordinates (subpixel resolution).
mrpt::math::CMatrixFixedNumeric< double, ObsDim, PointDof > J_point
TLandmarkID id_feature
A unique ID of this feature.
void reprojectionResidualsElement(const TCamera &camera_params, const TFeatureObservation &OBS, std::array< double, 2 > &out_residual, const TFramePosesVec::value_type &frame, const TLandmarkLocationsVec::value_type &point, double &sum, const bool use_robust_kernel, const double kernel_param, double *out_kernel_1st_deriv)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
mrpt::aligned_containers< TCameraPoseID, mrpt::poses::CPose3D >::map_t TFramePosesMap
A list of camera frames (6D poses) indexed by unique IDs.
#define ASSERT_BELOW_(__A, __B)
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
One feature observation entry, used within sequences with TSequenceFeatureObservations.
const Scalar * const_iterator
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:
mrpt::utils::TPixelCoordf px
The pixel coordinates of the observed feature.
Helper types for STL containers with Eigen memory allocators.
A complete sequence of observations of features from different camera frames (poses).
T square(const T x)
Inline function for the square of a number.
mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t TFramePosesVec
A list of camera frames (6D poses), which assumes indexes are unique, consecutive IDs...
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
void composeFrom(const CPose3D &A, const CPose3D &B)
Makes "this = A (+) B"; this method is slightly more efficient than "this= A + B;" since it avoids th...
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:
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
Classes for computer vision, detectors, features, etc.
uint64_t TFeatureID
Definition of a feature ID.
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
uint64_t TCameraPoseID
Unique IDs for camera frames (poses)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void ba_build_gradient_Hessians(const TSequenceFeatureObservations &observations, const std::vector< std::array< double, 2 >> &residual_vec, const mrpt::aligned_containers< JacData< 6, 3, 2 >>::vector_t &jac_data_vec, mrpt::aligned_containers< mrpt::math::CMatrixFixedNumeric< double, 6, 6 >>::vector_t &U, mrpt::aligned_containers< CArrayDouble< 6 >>::vector_t &eps_frame, mrpt::aligned_containers< mrpt::math::CMatrixFixedNumeric< double, 3, 3 >>::vector_t &V, mrpt::aligned_containers< CArrayDouble< 3 >>::vector_t &eps_point, const size_t num_fix_frames, const size_t num_fix_points, const vector< double > *kernel_1st_deriv)
Construct the BA linear system.
std::vector< mrpt::math::TPoint3D > TLandmarkLocationsVec
A list of landmarks (3D points), which assumes indexes are unique, consecutive IDs.
A partial specialization of CArrayNumeric for double numbers.
mrpt::math::CMatrixFixedNumeric< double, ObsDim, FrameDof > J_frame
double 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< 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...
TCameraPoseID id_frame
A unique ID of a "frame" (camera position) from where the feature was observed.
std::map< TLandmarkID, mrpt::math::TPoint3D > TLandmarkLocationsMap
A list of landmarks (3D points) indexed by unique IDs.
void 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...
#define ASSERTMSG_(f, __ERROR_MSG)
Structure to hold the parameters of a pinhole camera model.