根据ORB找描述子,之后进行匹配,如下图所示:
主要是-BFMatcher是使用:
Mat img1, img2, img11, img22;
img1 = imread(path1);
img2 = imread(path2);
imshow("img1", img1);
waitKey(0);
//1.ORB检测
Ptr<ORB> orb = ORB::create();
//2.生成描述子
vector<KeyPoint> kp1, kp2;
Mat des1, des2;
orb->detectAndCompute(img1, Mat(), kp1, des1);
orb->detectAndCompute(img2, Mat(), kp2, des2);
//3.两个描述子匹配,两个mat 做for循环 只不过在这用BFMatcher
//3.1 定义一个类对象
//3.2 把两个mat放进去 输出的是matches 汉明距离作为距离度量
//3.3 matches应该是一个容器,里面是mat
//3.4 排序取前10个。
BFMatcher bf(NORM_HAMMING, true);
vector <DMatch> matches;
bf.match(des1, des2, matches, Mat());//值放入matches
sort(matches.begin(), matches.end());//排序
matches = vector<DMatch>(matches.begin(), matches.begin() + 10);//重新赋值取前10个
vector<char> match_mask(matches.size(), 1);//新建一个容器 个数应该是10个
Mat img3;
drawMatches(img1, kp1, img2, kp2, matches, img3, Scalar::all(-1),
Scalar::all(-1), match_mask, DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
imshow("ORB Feature baoli Demo", img3);
waitKey(0);
destroyAllWindows();