c++ - 想要检测特征并在 2 个不同的帧中匹配特征
问题描述
我目前在 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);
推荐阅读
- java - 股票价格使用哪个十进制实现?
- c++ - 申请短期过滤数据库
- flutter - 如何在颤动中编辑 TextEditingController 对象的值?
- reactjs - 将数组作为函数的参数发送
- swift - xcode 11 xcode 10 兼容性
- c++ - 需要生成x(输入)个字母,然后将它们放入4的char数组中
- c# - 如何阻止 Blazor 捕获异常?
- javascript - 如何让vue路由器链接连接到vue组件?
- python - 如何从 Jupyter Notebook 上的其他 .ipynb 导入变量?
- string - MIPS - 如何连接用户输入字符串并在读取连续的“\n”“\n”后将它们打印出来?