记录一下学习过程,话不多说贴代码:
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/flann/flann.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <iostream>
int main() {
cv::Mat srcImage1 = cv::imread("img1.png", 1);
cv::Mat srcImage2 = cv::imread("img2.png", 1);
if (!srcImage1.data || !srcImage2.data) {
std::cout << "No images" << std::endl;
}
int minHessian = 400;
cv::Ptr<cv::xfeatures2d::SurfFeatureDetector> detector = cv::xfeatures2d::SurfFeatureDetector::create(minHessian);
//keypoint存储着特征点像素的坐标
std::vector<cv::KeyPoint> keypoint1, keypoint2;
cv::Mat dstImage1, dstImage2;
//特征点检测,并计算特征点的特征向量
detector->detect(srcImage1, keypoint1);
detector->detect(srcImage2, keypoint2);
detector-&