我有OpenCV 3.0,并且已经用opencv_contrib模块编译并安装了它,所以这不是问题。不幸的是,以前版本中的示例不适用于当前版本,因此尽管此问题具有already been asked more than once,但我仍希望可以使用一个更新的示例。即使是official examples在此版本中也不起作用(功能检测有效,但其他功能示例无效),并且它们仍然使用SURF。
所以,如何在C ++上使用OpenCV SIFT?我想抓住两张图像中的关键点并进行匹配,类似于this example,但是即使仅获取这些点和描述符也已足够。帮助!
然后:
#include "opencv2/xfeatures2d.hpp" // // now, you can no more create an instance on the 'stack', like in the tutorial // (yea, noticed for a fix/pr). // you will have to use cv::Ptr all the way down: // cv::Ptr<Feature2D> f2d = xfeatures2d::SIFT::create(); //cv::Ptr<Feature2D> f2d = xfeatures2d::SURF::create(); //cv::Ptr<Feature2D> f2d = ORB::create(); // you get the picture, i hope.. //-- Step 1: Detect the keypoints: std::vector<KeyPoint> keypoints_1, keypoints_2; f2d->detect( img_1, keypoints_1 ); f2d->detect( img_2, keypoints_2 ); //-- Step 2: Calculate descriptors (feature vectors) Mat descriptors_1, descriptors_2; f2d->compute( img_1, keypoints_1, descriptors_1 ); f2d->compute( img_2, keypoints_2, descriptors_2 ); //-- Step 3: Matching descriptor vectors using BFMatcher : BFMatcher matcher; std::vector< DMatch > matches; matcher.match( descriptors_1, descriptors_2, matches );
也,别忘了链接opencv_xfeatures2d!
有一些有用的答案,但是我会添加我的版本(对于OpenCV 3.X