NDEVR
API Documentation
MLPnPsolver.h
1#pragma once
2#include "GraphOptimization/Headers/DLLInfo.h"
3#include "OrbSLAM/Headers/MapPoint.h"
4#include "OrbSLAM/Headers/Frame.h"
5
6#include <Eigen/Dense>
7#include <Eigen/SparseCore>
8
9namespace NDEVR{
16 {
17 public:
22 MLPnPsolver(const Frame &F, const Buffer<MapPoint*> &vpMapPointMatches);
23
32 void SetRansacParameters(g_type probability = 0.99, uint04 minInliers = 8, uint04 maxIterations = 300, uint04 minSet = 6, float epsilon = 0.4, float th2 = 5.991f);
33
42 bool iterate(uint04 nIterations, bool &bNoMore, Buffer<bool> &vbInliers, uint04 &nInliers, Eigen::Matrix4f &Tout);
43
44 //Type definitions needed by the original code
45
49 typedef Eigen::Vector3<g_type> bearingVector_t;
50
53
56 typedef Eigen::Matrix2<g_type> cov2_mat_t;
57
59 typedef Eigen::Matrix3<g_type> cov3_mat_t;
60
63
65 typedef Eigen::Vector3<g_type> point_t;
66
69
71 typedef Eigen::Vector4<g_type> point4_t;
72
75
77 typedef Eigen::Vector3<g_type> rodrigues_t;
78
80 typedef Eigen::Matrix3<g_type> rotation_t;
81
86 typedef Eigen::Matrix<g_type,3,4> transformation_t;
87
89 typedef Eigen::Vector3<g_type> translation_t;
90
91
92
93 private:
94 void CheckInliers();
95 bool Refine();
96
97 //Functions from de original MLPnP code
98
99 /*
100 * Computes the camera pose given 3D points coordinates (in the camera reference
101 * system), the camera rays and (optionally) the covariance matrix of those camera rays.
102 * Result is stored in solution
103 */
104 void computePose(
105 const bearingVectors_t & f,
106 const points_t & p,
107 const cov3_mats_t & covMats,
108 const Buffer<uint04>& indices,
109 transformation_t & result);
110
111 void mlpnp_gn(Eigen::VectorX<g_type>& x,
112 const points_t& pts,
113 const Buffer<Eigen::MatrixX<g_type>>& nullspaces,
114 const Eigen::SparseMatrix<g_type> Kll,
115 bool use_cov);
116
117 void mlpnp_residuals_and_jacs(
118 const Eigen::VectorX<g_type>& x,
119 const points_t& pts,
120 const Buffer<Eigen::MatrixX<g_type>>& nullspaces,
121 Eigen::VectorX<g_type>& r,
122 Eigen::MatrixX<g_type>& fjac,
123 bool getJacs);
124
125 void mlpnpJacs(
126 const point_t& pt,
127 const Eigen::Vector3<g_type>& nullspace_r,
128 const Eigen::Vector3<g_type>& nullspace_s,
129 const rodrigues_t& w,
130 const translation_t& t,
131 Eigen::MatrixX<g_type>& jacs);
132
133 //Auxiliar methods
134
141 Eigen::Matrix3<g_type> rodrigues2rot(const Eigen::Vector3<g_type>& omega);
142
149 Eigen::Vector3<g_type> rot2rodrigues(const Eigen::Matrix3<g_type>& R);
150
151 //----------------------------------------------------
152 //Fields of the solver
153 //----------------------------------------------------
154 Buffer<MapPoint*> mvpMapPointMatches;
155
156 // 2D Points
158 //Substitued by bearing Buffers
159 bearingVectors_t mvBearingVecs;
160
161 Buffer<float> mvSigma2;
162
163 // 3D Points
164 //vector<cv::Point3f> mvP3Dw;
165 points_t mvP3Dw;
166
167 // Index in Frame
168 Buffer<uint04> mvKeyPointIndices;
169
170 // Current Estimation
171 g_type mRi[3][3];
172 g_type mti[3];
173 Eigen::Matrix4f mTcwi;
174 Buffer<bool> mvbInliersi;
175 uint04 mnInliersi = 0;
176
177 // Current Ransac State
178 uint04 mnIterations = 0;
179 Buffer<bool> mvbBestInliers;
180 uint04 mnBestInliers = 0;
181 Eigen::Matrix4f mBestTcw;
182
183 // Refined
184 Eigen::Matrix4f mRefinedTcw;
185 Buffer<bool> mvbRefinedInliers;
186 uint04 mnRefinedInliers = 0;
187
188 // Number of Correspondences
189 uint04 N = 0;
190
191 // Indices for random selection [0 .. N-1]
192 Buffer<uint04> mvAllIndices;
193
194 // RANSAC probability
195 g_type mRansacProb;
196
197 // RANSAC min inliers
198 uint04 mRansacMinInliers = 0;
199
200 // RANSAC max iterations
201 uint04 mRansacMaxIts = 0;
202
203 // RANSAC expected inliers/total ratio
204 float mRansacEpsilon = 0.0f;
205
206 // RANSAC Minimun Set used at each iteration
207 uint04 mRansacMinSet = 0;
208
209 // Max square error associated with scale level. Max error = th*th*sigma(level)*sigma(level)
210 Buffer<float> mvMaxError;
211
212 GeometricCamera* mpCamera = nullptr;
213 };
214
215}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Represents a single image frame with extracted features and pose information.
Definition Frame.h:111
Abstract interface for geometric camera models (pinhole, fisheye, etc.).
MLPnPsolver(const Frame &F, const Buffer< MapPoint * > &vpMapPointMatches)
Constructs the solver from a frame and map point matches.
Eigen::Matrix2< g_type > cov2_mat_t
A 2-matrix containing the 2D covariance information of a bearing Buffer.
Definition MLPnPsolver.h:56
Eigen::Vector3< g_type > point_t
A 3-vector describing a point in 3D-space.
Definition MLPnPsolver.h:65
Buffer< point_t > points_t
An array of 3D-points.
Definition MLPnPsolver.h:68
Eigen::Matrix< g_type, 3, 4 > transformation_t
A 3x4 transformation matrix containing rotation and translation as follows: .
Definition MLPnPsolver.h:86
Eigen::Vector3< g_type > rodrigues_t
A 3-vector containing the rodrigues parameters of a rotation matrix.
Definition MLPnPsolver.h:77
Eigen::Vector3< g_type > bearingVector_t
A 3-vector of unit length used to describe landmark observations/bearings in camera frames (always ex...
Definition MLPnPsolver.h:49
Eigen::Vector4< g_type > point4_t
A homogeneous 3-vector describing a point in 3D-space.
Definition MLPnPsolver.h:71
Buffer< cov3_mat_t > cov3_mats_t
An array of 3D covariance matrices.
Definition MLPnPsolver.h:62
void SetRansacParameters(g_type probability=0.99, uint04 minInliers=8, uint04 maxIterations=300, uint04 minSet=6, float epsilon=0.4, float th2=5.991f)
Sets RANSAC parameters.
Eigen::Matrix3< g_type > rotation_t
A rotation matrix.
Definition MLPnPsolver.h:80
Eigen::Vector3< g_type > translation_t
A 3-vector describing a translation/camera position.
Definition MLPnPsolver.h:89
Buffer< point4_t > points4_t
An array of homogeneous 3D-points.
Definition MLPnPsolver.h:74
Eigen::Matrix3< g_type > cov3_mat_t
A 3-matrix containing the 3D covariance information of a bearing Buffer.
Definition MLPnPsolver.h:59
bool iterate(uint04 nIterations, bool &bNoMore, Buffer< bool > &vbInliers, uint04 &nInliers, Eigen::Matrix4f &Tout)
Runs RANSAC iterations to estimate the camera pose.
Buffer< bearingVector_t > bearingVectors_t
An array of bearing-vectors.
Definition MLPnPsolver.h:52
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...