PnPsolver.h
Go to the documentation of this file.
1 
51 #ifndef PNPSOLVER_H
52 #define PNPSOLVER_H
53 
54 #include <opencv2/core/core.hpp>
55 #include <opencv2/core/core_c.h>
56 #include "MapPoint.h"
57 #include "Frame.h"
58 
59 namespace ORB_SLAM2
60 {
61 
62 class PnPsolver {
63  public:
64  PnPsolver(const Frame &F, const vector<MapPoint*> &vpMapPointMatches);
65 
66  ~PnPsolver();
67 
68  void SetRansacParameters(double probability = 0.99, int minInliers = 8 , int maxIterations = 300, int minSet = 4, float epsilon = 0.4,
69  float th2 = 5.991);
70 
71  cv::Mat find(vector<bool> &vbInliers, int &nInliers);
72 
73  cv::Mat iterate(int nIterations, bool &bNoMore, vector<bool> &vbInliers, int &nInliers);
74 
75  private:
76 
77  void CheckInliers();
78  bool Refine();
79 
80  // Functions from the original EPnP code
81  void set_maximum_number_of_correspondences(const int n);
82  void reset_correspondences(void);
83  void add_correspondence(const double X, const double Y, const double Z,
84  const double u, const double v);
85 
86  double compute_pose(double R[3][3], double T[3]);
87 
88  void relative_error(double & rot_err, double & transl_err,
89  const double Rtrue[3][3], const double ttrue[3],
90  const double Rest[3][3], const double test[3]);
91 
92  void print_pose(const double R[3][3], const double t[3]);
93  double reprojection_error(const double R[3][3], const double t[3]);
94 
95  void choose_control_points(void);
97  void fill_M(CvMat * M, const int row, const double * alphas, const double u, const double v);
98  void compute_ccs(const double * betas, const double * ut);
99  void compute_pcs(void);
100 
101  void solve_for_sign(void);
102 
103  void find_betas_approx_1(const CvMat * L_6x10, const CvMat * Rho, double * betas);
104  void find_betas_approx_2(const CvMat * L_6x10, const CvMat * Rho, double * betas);
105  void find_betas_approx_3(const CvMat * L_6x10, const CvMat * Rho, double * betas);
106  void qr_solve(CvMat * A, CvMat * b, CvMat * X);
107 
108  double dot(const double * v1, const double * v2);
109  double dist2(const double * p1, const double * p2);
110 
111  void compute_rho(double * rho);
112  void compute_L_6x10(const double * ut, double * l_6x10);
113 
114  void gauss_newton(const CvMat * L_6x10, const CvMat * Rho, double current_betas[4]);
115  void compute_A_and_b_gauss_newton(const double * l_6x10, const double * rho,
116  double cb[4], CvMat * A, CvMat * b);
117 
118  double compute_R_and_t(const double * ut, const double * betas,
119  double R[3][3], double t[3]);
120 
121  void estimate_R_and_t(double R[3][3], double t[3]);
122 
123  void copy_R_and_t(const double R_dst[3][3], const double t_dst[3],
124  double R_src[3][3], double t_src[3]);
125 
126  void mat_to_quat(const double R[3][3], double q[4]);
127 
128 
129  double uc, vc, fu, fv;
130 
131  double * pws, * us, * alphas, * pcs;
134 
135  double cws[4][3], ccs[4][3];
137 
138  vector<MapPoint*> mvpMapPointMatches;
139 
140  // 2D Points
141  vector<cv::Point2f> mvP2D;
142  vector<float> mvSigma2;
143 
144  // 3D Points
145  vector<cv::Point3f> mvP3Dw;
146 
147  // Index in Frame
148  vector<size_t> mvKeyPointIndices;
149 
150  // Current Estimation
151  double mRi[3][3];
152  double mti[3];
153  cv::Mat mTcwi;
154  vector<bool> mvbInliersi;
156 
157  // Current Ransac State
159  vector<bool> mvbBestInliers;
161  cv::Mat mBestTcw;
162 
163  // Refined
164  cv::Mat mRefinedTcw;
165  vector<bool> mvbRefinedInliers;
167 
168  // Number of Correspondences
169  int N;
170 
171  // Indices for random selection [0 .. N-1]
172  vector<size_t> mvAllIndices;
173 
174  // RANSAC probability
175  double mRansacProb;
176 
177  // RANSAC min inliers
179 
180  // RANSAC max iterations
182 
183  // RANSAC expected inliers/total ratio
185 
186  // RANSAC Threshold inlier/outlier. Max error e = dist(P1,T_12*P2)^2
187  float mRansacTh;
188 
189  // RANSAC Minimun Set used at each iteration
191 
192  // Max square error associated with scale level. Max error = th*th*sigma(level)*sigma(level)
193  vector<float> mvMaxError;
194 
195 };
196 
197 } //namespace ORB_SLAM
198 
199 #endif //PNPSOLVER_H
void estimate_R_and_t(double R[3][3], double t[3])
Definition: PnPsolver.cc:569
void compute_L_6x10(const double *ut, double *l_6x10)
Definition: PnPsolver.cc:760
double epsilon
void find_betas_approx_3(const CvMat *L_6x10, const CvMat *Rho, double *betas)
Definition: PnPsolver.cc:731
vector< bool > mvbBestInliers
Definition: PnPsolver.h:159
vector< float > mvSigma2
Definition: PnPsolver.h:142
void print_pose(const double R[3][3], const double t[3])
Definition: PnPsolver.cc:629
void compute_rho(double *rho)
Definition: PnPsolver.cc:802
double mRi[3][3]
Definition: PnPsolver.h:151
double compute_R_and_t(const double *ut, const double *betas, double R[3][3], double t[3])
Definition: PnPsolver.cc:651
void gauss_newton(const CvMat *L_6x10, const CvMat *Rho, double current_betas[4])
Definition: PnPsolver.cc:840
double cws[4][3]
Definition: PnPsolver.h:135
void compute_barycentric_coordinates(void)
Definition: PnPsolver.cc:411
cv::Mat iterate(int nIterations, bool &bNoMore, vector< bool > &vbInliers, int &nInliers)
Definition: PnPsolver.cc:165
cv::Mat find(vector< bool > &vbInliers, int &nInliers)
Definition: PnPsolver.cc:159
vector< cv::Point2f > mvP2D
Definition: PnPsolver.h:141
void set_maximum_number_of_correspondences(const int n)
Definition: PnPsolver.cc:342
double dist2(const double *p1, const double *p2)
Definition: PnPsolver.cc:537
int maximum_number_of_correspondences
Definition: PnPsolver.h:132
double compute_pose(double R[3][3], double T[3])
Definition: PnPsolver.cc:477
void find_betas_approx_1(const CvMat *L_6x10, const CvMat *Rho, double *betas)
Definition: PnPsolver.cc:667
vector< float > mvMaxError
Definition: PnPsolver.h:193
PnPsolver(const Frame &F, const vector< MapPoint * > &vpMapPointMatches)
Definition: PnPsolver.cc:67
double reprojection_error(const double R[3][3], const double t[3])
Definition: PnPsolver.cc:550
void relative_error(double &rot_err, double &transl_err, const double Rtrue[3][3], const double ttrue[3], const double Rest[3][3], const double test[3])
Definition: PnPsolver.cc:954
vector< cv::Point3f > mvP3Dw
Definition: PnPsolver.h:145
void SetRansacParameters(double probability=0.99, int minInliers=8, int maxIterations=300, int minSet=4, float epsilon=0.4, float th2=5.991)
Definition: PnPsolver.cc:121
vector< bool > mvbInliersi
Definition: PnPsolver.h:154
void reset_correspondences(void)
Definition: PnPsolver.cc:358
double dot(const double *v1, const double *v2)
Definition: PnPsolver.cc:545
void compute_A_and_b_gauss_newton(const double *l_6x10, const double *rho, double cb[4], CvMat *A, CvMat *b)
Definition: PnPsolver.cc:812
vector< MapPoint * > mvpMapPointMatches
Definition: PnPsolver.h:138
void copy_R_and_t(const double R_dst[3][3], const double t_dst[3], double R_src[3][3], double t_src[3])
Definition: PnPsolver.cc:527
vector< size_t > mvAllIndices
Definition: PnPsolver.h:172
void compute_pcs(void)
Definition: PnPsolver.cc:466
vector< bool > mvbRefinedInliers
Definition: PnPsolver.h:165
void compute_ccs(const double *betas, const double *ut)
Definition: PnPsolver.cc:453
void find_betas_approx_2(const CvMat *L_6x10, const CvMat *Rho, double *betas)
Definition: PnPsolver.cc:699
void solve_for_sign(void)
Definition: PnPsolver.cc:636
void mat_to_quat(const double R[3][3], double q[4])
Definition: PnPsolver.cc:984
void add_correspondence(const double X, const double Y, const double Z, const double u, const double v)
Definition: PnPsolver.cc:363
void qr_solve(CvMat *A, CvMat *b, CvMat *X)
Definition: PnPsolver.cc:860
vector< size_t > mvKeyPointIndices
Definition: PnPsolver.h:148
double ccs[4][3]
Definition: PnPsolver.h:135
void choose_control_points(void)
Definition: PnPsolver.cc:375
void fill_M(CvMat *M, const int row, const double *alphas, const double u, const double v)
Definition: PnPsolver.cc:436


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05