ORB特征点匹配小流程
#include <stdio.h>
#include <iostream>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat img1 = imread("1.jpg");
Mat img2 = imread("2.jpg");
vector<KeyPoint> keypoints_1, keypoints_2;
Mat description_1, description_2;
Ptr<ORB> orb = ORB::create(500,1.2f,8,31,0,2,ORB::HARRIS_SCORE,31,20);
orb->detect(img1,keypoints_1);
orb->detect(img1, keypoints_2);
orb->compute(img1,keypoints_1,description_1);
orb->compute(img2, keypoints_2, description_2);
Mat outimg1;
drawKeypoints(img1,keypoints_1,outimg1,Scalar::all(-1),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
imshow("ORB特征点", outimg1);
vector<DMatch> matches;
BFMatcher matcher(NORM_HAMMING);
matcher.match(description_1,description_2,matches);
double min_dist = 10000, max_dist = 0;
for (int i = 0; i < description_1.rows; i++)
{
double dist = matches[i].distance;
if (dist < min_dist) { min_dist = dist; }
if (dist > max_dist) { max_dist = dist; }
}
cout << min_dist <<"\t"<< max_dist<<endl;
vector<DMatch> good_match;
for (int j = 0; j < description_1.rows; j++)
{
if (matches[j].distance<=max(2*min_dist,30.0))
{
good_match.push_back(matches[j]);
}
}
Mat img_goodmatch;
drawMatches(img1, keypoints_1, img2, keypoints_2, good_match, img_goodmatch);
imshow("优化后的匹配", img_goodmatch);
waitKey(0);
return 0;
}