how to use SIFT in opencv

試著忘記壹切 提交于 2019-12-20 14:15:39

问题


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?


回答1:


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




回答2:


update for 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;
}



回答3:


I was having the same question for opencv3 but i found this . It explains why SIFT and SURF removed from the default install of OpenCV 3.0 and how to use SIFT and SURF in OpenCV 3.



来源:https://stackoverflow.com/questions/22722772/how-to-use-sift-in-opencv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!