这些天我正在学习C++和OpenCV。给定一幅图像,我想提取它的SIFT特征。从http://docs.opencv.org/modules/nonfree/doc/feature_detection.html我们可以知道OpenCV 2.4.8有SIFT模块。请看这里:

但是我不知道如何使用它。目前,要使用SIFT,我需要首先调用SIFT类来获取SIFT实例。然后,我需要使用SIFT::operator()()来做筛选。
但是什么是OutputArray,InputArray,KeyPoint呢?谁能演示一下如何使用SIFT类来做SIFT?
发布于 2014-03-29 06:03:36
请参阅来自Sift implementation with OpenCV 2.2的示例
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp> //Thanks to Alessandro
int main(int argc, const char* argv[])
{
const cv::Mat input = cv::imread("input.jpg", 0); //Load as grayscale
cv::SiftFeatureDetector detector;
std::vector<cv::KeyPoint> keypoints;
detector.detect(input, keypoints);
// Add results to image and save.
cv::Mat output;
cv::drawKeypoints(input, keypoints, output);
cv::imwrite("sift_result.jpg", output);
return 0;
}在OpenCV 2.4.8上测试
发布于 2020-04-03 22:10:07
OpenCV 4.2.0的更新(当然,不要忘记链接opencv_xfeatures2d420.lib )
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/xfeatures2d.hpp>
int main(int argc, char** argv)
{
const cv::Mat input = cv::imread("input.jpg", 0); //Load as grayscale
cv::Ptr<cv::xfeatures2d::SIFT> siftPtr = cv::xfeatures2d::SIFT::create();
std::vector<cv::KeyPoint> keypoints;
siftPtr->detect(input, keypoints);
// Add results to image and save.
cv::Mat output;
cv::drawKeypoints(input, keypoints, output);
cv::imwrite("sift_result.jpg", output);it.
return 0;
}发布于 2018-05-24 19:09:45
OpenCV3更新
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp> //Thanks to Alessandro
int main(int argc, const char* argv[])
{
const cv::Mat input = cv::imread("input.jpg", 0); //Load as grayscale
cv::Ptr<cv::SiftFeatureDetector> detector = cv::SiftFeatureDetector::create();
std::vector<cv::KeyPoint> keypoints;
detector->detect(input, keypoints);
// Add results to image and save.
cv::Mat output;
cv::drawKeypoints(input, keypoints, output);
cv::imwrite("sift_result.jpg", output);
return 0;
}https://stackoverflow.com/questions/22722772
复制相似问题