如何在OpenCV 3.0和c ++中使用SIFT? [英] How do I use SIFT in OpenCV 3.0 with c++?
问题描述
我有OpenCV 3.0,我已经编译&安装它与opencv_contrib模块,这不是一个问题。不幸的是,以前版本的示例不适用于当前版本,因此虽然此问题已多次我想一个更实际的例子,我可以实际使用。即使是官方示例也无法使用
I have OpenCV 3.0, and I have compiled & installed it with the opencv_contrib module so that's not a problem. Unfortunately the examples from previous versions do not work with the current one, and so although this question has already been asked more than once I would like a more current example that I can actually work with. Even the official examples don't work in this version (feature detection works but not other feature examples) and they use SURF anyway.
那么,我如何在C ++上使用OpenCV SIFT?在这个版本中(功能检测工作,但不是其他功能的例子),他们使用SURF。我想抓住两个图像中的关键点,并匹配它们,类似于这个例子,但即使只是得到点和描述符将是足够的帮助。帮助!
So, how do I use OpenCV SIFT on C++? I want to grab the keypoints in two images and match them, similar to this example, but even just getting the points and descriptors would be enough help. Help!
推荐答案
- get the opencv_contrib repo
- take your time with the readme there, add it to your main opencv cmake settings
- rerun cmake /make / install in the main opencv repo
然后:
#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!
also, don't forget to link opencv_xfeatures2d !
这篇关于如何在OpenCV 3.0和c ++中使用SIFT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!