void featureMatch() {
cv::TickMeter meter;
meter.start();
Mat image1 = imread(MYPICTUREPATH "lena.jpg");
Mat image2 = imread(MYPICTUREPATH "lena_face.jpg");
//Mat image1 = imread(MYPICTUREPATH "test.jpg");
//Mat image2 = imread(MYPICTUREPATH "test_templ.jpg");
//! 1.检测关键点
Ptr<AKAZE> akaze=AKAZE::create();
vector<KeyPoint> keypoints1, keypoints2;
akaze->detect(image1, keypoints1);
akaze->detect(image2, keypoints2);
qDebug() << "1.检测关键点";
//! 2.计算/提取描述符
Mat descriptor1, descriptor2;
akaze->compute(image1, keypoints1, descriptor1);
akaze->compute(image2, keypoints2, descriptor2);
qDebug() << "2.计算/提取描述符";
//! 3.描述符匹配
//! 注意:若create()的实参选择不正确,将报出如下错误:
//! OpenCV: terminate handler is called! The last OpenCV error is:
//! OpenCV(4.6.0) Error: Unsupported format or combination of formats (> type=0
//! > ) in buildIndex_, file D:\Qt-OpenCV\OpenCV-Source\modules\flann\src\miniflann.cpp, line 336
Ptr<DescriptorMatcher> descMatcher = DescriptorMatcher::create(DescriptorMatcher::FLANNBASED);
//Ptr<DescriptorMatcher> descMatcher = DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE);
qDebug() << "3.描述符匹配";
//! 4.调用match函数
vector<DMatch> matches;
descMatcher->match(descriptor1, descriptor2, matches);
qDebug() << "4.调用match函数";
//! 5.drawMatches可以用来自动创建用于显示的适当输出结果
Mat dispImg;
drawMatches(image1, keypoints1, image2, keypoints2, matches, dispImg);
/*
drawMatches(image1,
keypoints1,
image2,
keypoints2,
matches,
dispImg,
Scalar(0,255,0), // green for matched
Scalar::all(-1), // unmatched color (default)
vector<char>(), // empty mask
DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
*/
qDebug() << "5.drawMatches可以用来自动创建用于显示的适当输出结果";
imshow("Image-match", dispImg);
meter.stop();
qDebug() << "耗时:" << meter.getTimeMilli() << "毫秒";//
}标签:匹配,Mat,akaze,keypoints2,qDebug,image2,image1,DescriptorExtractor,FeatureDetector From: https://www.cnblogs.com/zdt168/p/16861256.html