lei*_*paC 12 c++ opencv sift opencv3.0
我有OpenCV 3.0,我已经使用opencv_contrib模块编译和安装它,所以这不是问题.不幸的是,以前版本的示例不能与当前版本一起使用,因此虽然这个问题已经被多次询问 过,但我想要一个更实际的例子,我可以实际使用它.即使是官方示例也不适用于此版本(功能检测有效但其他功能示例无效),无论如何它们都使用SURF.
那么,我如何在C++上使用OpenCV SIFT?我想抓住两个图像中的关键点并匹配它们,类似于这个例子,但即使只是得到点和描述符也足够了.救命!
ber*_*rak 40
然后:
#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 );
Run Code Online (Sandbox Code Playgroud)
另外,别忘了链接opencv_xfeatures2d!