how to use SIFT in opencv

前端 未结 4 723
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  攒了一身酷
    2021-02-05 19:33

    Update for OpenCV 4.2.0 (don’t forget to link opencv_xfeatures2d420.lib, of course)

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

提交回复
热议问题