1 前言
在上一篇blog中,我们分析了CMT的整体算法流程及前面几步的实现分析,接下来我们继续分析后面的几步。
2 Step 4,5,6 特征点匹配与数据融合
这几步就是通过跟踪和特征匹配来获取这一帧的特征点,将两者融合在一起。
上一篇文章分析了光流,这里再分析一下特征匹配。源代码如下:
//Detect keypoints, compute descriptors 计算当前图像的关键点
vector<KeyPoint> keypoints;
detector->detect(im_gray, keypoints);
// 计算当前图像特征点的描述
Mat descriptors;
descriptor->compute(im_gray, keypoints, descriptors);
//Match keypoints globally 在全局和之前的数据库匹配特征点,计算出匹配的特征点
vector<Point2f> points_matched_global;
vector<int> classes_matched_global;
matcher.matchGlobal(keypoints, descriptors, points_matched_global, classes_matched_global);
主要过程在matchGlobal函数中,分析如下:
void Matcher::matchGlobal(const vector<KeyPoint> & keypoints, const Mat descriptors,
vector<Point2f> & points_matched, vector<int> & classes_matched)
{
if (keypoints.size() == 0)
{
return;
}
vector<vector<DMatch> > matches;
// 使用knnMatch进行特征匹配,每一个特征描述匹配最佳的2个特征
bfmatcher->knnMatch(descriptors, database, matches, 2);
for (size_t i = 0; i < matches