ORB-SLAM2学习笔记—— FindHomography函数
作者:互联网
FindHomography
void Initializer::FindHomography(vector<bool> &vbMatchesInliers, float &score, cv::Mat &H21)
{
// Number of putative matches
const int N = mvMatches12.size();
// Normalize coordinates
vector<cv::Point2f> vPn1, vPn2;
//防止不同分辨率、尺度和坐标原点下的影响,提高解的稳定性和精度
//T 表示归一化的关系 P‘ = T * p
Normalize(mvKeys1,vPn1, T1);
Normalize(mvKeys2,vPn2, T2);
cv::Mat T2inv = T2.inv();
// Best Results variables
score = 0.0;
//N个点,都是0
vbMatchesInliers = vector<bool>(N,false);
// Iteration variables
//八点法
vector<cv::Point2f> vPn1i(8);
vector<cv::Point2f> vPn2i(8);
cv::Mat H21i, H12i;
vector<bool> vbCurrentInliers(N,false);
float currentScore;
// Perform all RANSAC iterations and save the solution with highest score
//mMaxIterations:随机选取的(8组点对)点对的数量
for(int it=0; it<mMaxIterations; it++)
{
// Select a minimum set
//提取出八个点在mvMatches12中对应的索引,在取出坐标
for(size_t j=0; j<8; j++)
{
int idx = mvSets[it][j];
vPn1i[j] = vPn1[mvMatches12[idx].first];
vPn2i[j] = vPn2[mvMatches12[idx].second];
}
//计算本质矩阵,并且这里把归一化坐标的还原也计算在本质矩阵中
cv::Mat Hn = ComputeH21(vPn1i,vPn2i);
H21i = T2inv*Hn*T1;
H12i = H21i.inv();
//计算分数,选择最好的模型
currentScore = CheckHomography(H21i, H12i, vbCurrentInliers, mSigma);
//用更好的分数 替换 旧的,直到得到最好的模型
if(currentScore>score)
{
H21 = H21i.clone();
vbMatchesInliers = vbCurrentInliers;
score = currentScore;
}
}
}
标签:H21i,score,FindHomography,currentScore,SLAM2,vector,mvMatches12,ORB,cv 来源: https://blog.csdn.net/weixin_51326570/article/details/114741527