OpenCV入门 - 提取SIFT特征向量

OpenCV入门 - 提取SIFT特征向量




    为了确保旋转不变性,会以关键点为中心,以关键点的方向建立坐标轴,不是单独考察单一的这个关键点,而是需要一个邻域。邻域中每个小格的方向代表该像素的梯度方向,长度是梯度模大小,在每个4X4的小块上计算8个方向的梯度方向直方图,统计每个方向的累加值,形成一个种子点。David G.Lowe建议对每个关键点使用4X4=16个种子点进行描述,每个种子点包含8个方向信息,所以一个关键点就会产生16X8=128维的信息,形成128维的SIFT特征向量。下面使用opencv来对一个图片求特征向量。
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp> //
#include <iostream>
using namespace cv;
using namespace std;

int main(int argc, const char *argv[]){
    const cv::Mat input = cv::imread("input.jpg", 0);// load as grayscale
    cv::Mat descriptors;
    Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create("SIFT");

    cv::SiftFeatureDetector detector;
    vector<cv::KeyPoint> keypoints;
    detector.detect(input, keypoints);
    
    extractor->compute(input, keypoints, descriptors);
    cout << descriptors.rows << ":" << descriptors.cols << endl;
    // too many bits
    //cout << descriptors << endl;

    return 0;
}

通过结果可以看到共有266个关键点,可以输出来看看。

技术分享


参考:

1.opencv 2.4.10 reference

文章来自:http://blog.csdn.net/vonzhoufz/article/details/45647053
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3