how to use SIFT in opencv

前端 未结 4 726
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 18:58

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

4条回答
  •  -上瘾入骨i
    2021-02-05 19:45

    update for OpenCV3

    #include 
    #include 
    #include  //Thanks to Alessandro
    
    int main(int argc, const char* argv[])
    {
        const cv::Mat input = cv::imread("input.jpg", 0); //Load as grayscale
    
        cv::Ptr detector = cv::SiftFeatureDetector::create();
        std::vector 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;
    }
    

提交回复
热议问题