在Tracking模块里,单目第一步流程为MonocularInitialization,而这个函数主要涉及到的是Initializer.cc。
一、Initializer.h
// THIS IS THE INITIALIZER FOR MONOCULAR SLAM. NOT USED IN THE STEREO OR RGBD CASE.
/**
* @brief 单目SLAM初始化相关,双目和RGBD不会使用这个类
*/
class Initializer
{
typedef pair<int,int> Match;
public:
// Fix the reference frame
// 用reference frame来初始化,这个reference frame就是SLAM正式开始的第一帧
Initializer(const Frame &ReferenceFrame, float sigma = 1.0, int iterations = 200);
// Computes in parallel a fundamental matrix and a homography
// Selects a model and tries to recover the motion and the structure from motion
// 用current frame,也就是用SLAM逻辑上的第二帧来初始化整个SLAM,得到最开始两帧之间的R t,以及点云
bool Initialize(const Frame &CurrentFrame, const vector<int> &vMatches12,
cv::Mat &R21, cv::Mat &t21, vector<cv::Point3f> &vP3D, vector<bool> &vbTriangulated);
private:
// 假设场景为平面情况下通过前两帧求取Homography矩阵(current frame 2 到 reference frame 1),并得到该模型的评分
void FindHomography(vector<bool> &vbMatchesInliers, float &score, cv::Mat &H21);
// 假设场景为非平面情况下通过前两帧求取Fundamental矩阵(current frame 2 到 reference frame 1),并得到该模型的评分
void FindFundamental(vector<bool> &vbInliers, float &score, cv::Mat &F21);
// 被FindHomography函数调用具体来算Homography矩阵
cv::Mat ComputeH21(const vector<cv::Point2f> &vP1, const vector<cv::Point2f> &vP2);
// 被FindFundamental函数调用具体来算Fundamental矩阵
cv::Mat ComputeF21(const vector<cv::Point2f> &vP1, const vector<cv::Point2f