如何在opencv中使用SIFT [英] how to use SIFT in opencv
本文介绍了如何在opencv中使用SIFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在正在学习C ++和OpenCV。给定图像,我想提取其SIFT特征。从的示例
#include< opencv2 / core / core.hpp>
#include< opencv2 / highgui / highgui.hpp>
#include< opencv2 / nonfree / features2d.hpp> //感谢Alessandro
int main(int argc,const char * argv [])
{
const cv :: Mat input = cv :: imread(input。 jpg,0); // Load as grayscale
cv :: SiftFeatureDetector检测器;
std :: vector< cv :: KeyPoint>关键点;
detector.detect(input,keypoints);
//将结果添加到图像并保存。
cv :: Mat output;
cv :: drawKeypoints(input,keypoints,output);
cv :: imwrite(sift_result.jpg,output);
return 0;
}
在OpenCV 2.4.8上测试
I am learning C++ and OpenCV these days. Given an image, I want to extract its SIFT features. From http://docs.opencv.org/modules/nonfree/doc/feature_detection.html, we can know that OpenCV 2.4.8 has the SIFT module. See here:
But I do not know how to use it. Currently, to use SIFT, I need to first call the class SIFT to get a SIFT instance. Then, I need to use SIFT::operator()()
to do SIFT.
But what is OutputArray
, InputArray
, KeyPoint
? Could anyone give a demo to show how to use SIFT
class to do SIFT?
解决方案
See the example from 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;
}
Tested on OpenCV 2.4.8
这篇关于如何在opencv中使用SIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文