想要检测特征并匹配 2 个不同帧中的特征

Want to detect features and match the feature in 2 different frames

我目前在 QT Creator 中使用 OpenCV 3.4.0,C++。 我已经尝试过此页面中的示例代码 https://docs.opencv.org/2.4/doc/tutorials/features2d/feature_description/feature_description.html

int minHessian = 400;
cv::xfeatures2d::SurfFeatureDetector detector(minHessian);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);

// computing descriptors
cv::xfeatures2d::SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);

// matching descriptors
BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);

// drawing the results
namedWindow("matches", 1);
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
imshow("matches", img_matches);
waitKey(0);

但是代码一直返回错误

no matching function for call to 'cv::xfeatures2d::SURF::SURF(int&)(2nd line)

cannot declare variable 'detector' to be of abstract type 'cv::xfeatures2d::SURF'(2nd line)

cannot declare variable 'extractor' to be of astract type 'cv::xfeatures2d::SURF'(7th line)

我已经导入了我认为包括 xfeatures2d 在内的所有必要模块

问题是什么?

还有我可以尝试的其他示例代码吗?

您的编码反映了与 OpenCV 3.4.0 不兼容的旧版本 OpenCV。你可以这样试试。最好将模板图转为灰度图,更好匹配:

cv::Ptr<Feature2D> detector = cv::xfeatures2d::SurfFeatureDetector::create();
detector->detect(img1, keypoints1);

cv::Ptr<DescriptorExtractor> extractor = cv::xfeatures2d::SurfFeatureDetector::create();
extractor->compute(img1, keypoints1, descriptors1);