首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在opencv中使用SIFT

如何在opencv中使用SIFT
EN

Stack Overflow用户
提问于 2014-03-29 04:38:28
回答 4查看 58K关注 0票数 13

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

但是我不知道如何使用它。目前,要使用SIFT,我需要首先调用SIFT类来获取SIFT实例。然后,我需要使用SIFT::operator()()来做筛选。

但是什么是OutputArrayInputArrayKeyPoint呢?谁能演示一下如何使用SIFT类来做SIFT?

EN

回答 4

Stack Overflow用户

发布于 2014-03-29 06:03:36

请参阅来自Sift implementation with OpenCV 2.2的示例

代码语言:javascript
复制
#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上测试

票数 18
EN

Stack Overflow用户

发布于 2020-04-03 22:10:07

OpenCV 4.2.0的更新(当然,不要忘记链接opencv_xfeatures2d420.lib )

代码语言:javascript
复制
#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;
}
票数 6
EN

Stack Overflow用户

发布于 2018-05-24 19:09:45

OpenCV3更新

代码语言:javascript
复制
#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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22722772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档