这些天我正在学习C++和OpenCV.鉴于图像,我想提取其SIFT功能.从http://docs.opencv.org/modules/nonfree/doc/feature_detection.html,我们可以知道OpenCV 2.4.8具有SIFT模块.看这里:
但我不知道如何使用它.目前,要使用SIFT,我需要先调用类SIFT来获取SIFT实例.然后,我需要SIFT::operator()()
用来做SIFT.
但是,什么是OutputArray
,InputArray
, KeyPoint
?谁能举个演示来演示如何使用SIFT
类来做SIFT?
Lia*_*roy 16
请参阅使用OpenCV 2.2的Sift实现中的示例
#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;
}
Run Code Online (Sandbox Code Playgroud)
在OpenCV 2.4.8上测试过
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;
}
Run Code Online (Sandbox Code Playgroud)