2014-03-28 28 views
8

這些天我正在學習C++和OpenCV。鑑於圖像,我想提取其SIFT功能。從http://docs.opencv.org/modules/nonfree/doc/feature_detection.html,我們可以知道OpenCV 2.4.8有SIFT模塊。 請看這裏: enter image description here如何在opencv中使用SIFT

但我不知道如何使用它。目前,要使用SIFT,我需要首先調用SIFT類來獲取SIFT實例。然後,我需要使用SIFT::operator()()來做SIFT。

但是什麼是OutputArray, InputArray,KeyPoint?任何人都可以演示如何使用SIFT類來做SIFT嗎?

+1

也許是[tutorials]之一(http://docs.opencv.org/doc/tutorials/ features2d/feature_detection/feature_detection.html#feature-detection)有幫助嗎? – berak

+0

@berak它是SurfFeatureDetector,而不是SIFT。但是,我想要使用的是SIFT類。我在鏈接中顯示它。謝謝 ! – tqjustc

+2

是的,我知道。但程序是類似的 – berak

回答

13

查看來自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

+3

你不需要'#include「opencv2/nonfree/features2d.hpp」'? –

+1

@Alessandro是的,檢查編輯 –

1

我具有用於opencv3同樣的問題,但是,我發現this的例子。它解釋了爲什麼SIFT和SURF從OpenCV 3.0的默認安裝中刪除以及如何在OpenCV 3中使用SIFT和SURF。