本代码使用VLFeat库中的函数对一幅图像进行了SIFT检测

需要事先配置好VLFeat和OpenCV,VLFeat的配置参考前一篇博文,OpenCV的配置网上一大堆,自己去百度

#include "stdafx.h"
#include <stdio.h>
#include <tchar.h>
#include <opencv2/opencv.hpp>
#include <stdio.h> using namespace cv;
using namespace std; extern "C"{
#include <vl/generic.h>
#include <vl/stringop.h>
#include <vl/sift.h>
#include <vl/getopt_long.h>
}; int _tmain(int argc, _TCHAR* argv[])
{
// 注意此处一定是0,不能不填,因为是单通道,灰度空间
IplImage* img = cvLoadImage("1.jpg", ); // 此处这三个变量的定义看下面vl_sift_new函数中的解释
int noctaves = , nlevels = , o_min = ; // vl_sift_pix 就是float型数据
vl_sift_pix *imgdata = new vl_sift_pix[img->height * img->width]; // 将原图像复制到float型的vl_sift_pix数组中
unsigned char *Pixel;
for (int i=;i<img->height;i++)
{
for (int j=;j<img->width;j++)
{
Pixel=(unsigned char*)(img->imageData+i*img->width+j);
imgdata[i*img->width+j]=*(Pixel);
}
} // VlSiftFilt: This filter implements the SIFT detector and descriptor.
// 这个过滤器实现了SIFT检测器和描述符
VlSiftFilt *siftfilt = NULL; // vl_sift_new(int width, int height, int noctaves, int nlevels, int o_min)
// noctaves: numbers of octaves 组数
// nlevels: numbers of levels per octave 每组的层数
// o_min: first octave index 第一组的索引号
siftfilt = vl_sift_new(img->width, img->height, noctaves, nlevels, o_min); float Descri[][]; //记录每个特征点的描述符,一个特征点有可能有多个描述符,最多有4个
int area[][]; //0~3分别记录每个特征点的坐标x,y,圆的半径大小r,该特征点的方向个数,或者说描述符个数 int keypoint = ;
int idx_point = ; //特征点的个数
int idx_descri = ; //特征点描述符的个数 >= idx_point // vl_sift_process_first_octave:
// The function starts processing a new image by computing its Gaussian scale space at the lower octave.
// It also empties the internal keypoint buffer.
// 这个函数开始处理一幅新图像,通过计算它在低层的高斯尺度空间
// 它还清空内部记录关键点的缓冲区
if (vl_sift_process_first_octave(siftfilt, imgdata) != VL_ERR_EOF)
{
while ()
{
// 计算每组中的关键点
vl_sift_detect(siftfilt); // 遍历每个特征点
keypoint += siftfilt->nkeys; VlSiftKeypoint *pkeypoint = siftfilt->keys; for (int i = ; i < siftfilt->nkeys; i ++)
{
VlSiftKeypoint tempkeypoint = *pkeypoint;
pkeypoint++; area[idx_point][] = tempkeypoint.x;
area[idx_point][] = tempkeypoint.y;
area[idx_point][] = tempkeypoint.sigma/; // 计算并遍历每个点的方向
double angles[]; // The function computes the orientation(s) of the keypoint k.
// The function returns the number of orientations found (up to four).
// The orientations themselves are written to the vector angles.
// 计算每个极值点的方向,包括主方向和辅方向,最多4个方向
int angleCount = vl_sift_calc_keypoint_orientations(siftfilt, angles, &tempkeypoint); area[idx_point][] = angleCount;
idx_point ++; for (int j = ; j < angleCount; ++ j)
{
printf("%d: %f\n", j, angles[j]); // 计算每个方向的描述符
float *descriptors = new float[];
vl_sift_calc_keypoint_descriptor(siftfilt, descriptors, &tempkeypoint, angles[j]); memcpy(Descri[idx_descri], descriptors, * sizeof(float));
idx_descri ++; delete []descriptors;
descriptors = NULL;
} } // vl_sift_process_next_octave:
// The function computes the next octave of the Gaussian scale space.
// Notice that this clears the record of any feature detected in the previous octave.
// 这个函数计算高斯尺度空间中的下一组尺度空间图像
// 这个函数会清除在前一层空间中检测到的特征点
if (vl_sift_process_next_octave(siftfilt) == VL_ERR_EOF)
{
break;
} keypoint = ;
}
} vl_sift_delete(siftfilt);
delete []imgdata;
imgdata = NULL; for (int i = ; i < idx_point; ++ i)
{
cvDrawCircle(img, cvPoint(area[i][], area[i][]), area[i][], CV_RGB(,,));
} cvNamedWindow("Source Image", );
cvShowImage("Source Image", img);
cvWaitKey();
cvReleaseImage(&img);
cvDestroyAllWindows(); return ;
}

VLFeat中SIFT特征点检测的更多相关文章

  1. SIFT特征点检测学习一(转载)

    新手上路,先转载学习tornadomeet的博客:http://www.cnblogs.com/tornadomeet/archive/2012/08/16/2643168.html 特征点检测学习_ ...

  2. SIFT特征点检测与匹配

    SIFT的步骤如下: (1) 尺度空间极值检测(Scale-space Extrema Detection) 也就是在多尺度高斯差分(Difference of Gauss)空间中检测极值点(3x3x ...

  3. sift特征点检测和特征数据库的建立

    类似于ORBSLAM中的ORB.txt数据库. https://blog.csdn.net/lingyunxianhe/article/details/79063547   ORBvoc.txt是怎么 ...

  4. python+OpenCV 特征点检测

    1.Harris角点检测 Harris角点检测算法是一个极为简单的角点检测算法,该算法在1988年就被发明了,算法的主要思想是如果像素周围显示存在多于一个方向的边,我们认为该点为兴趣点.基本原理是根据 ...

  5. OpenCV计算机视觉学习(13)——图像特征点检测(Harris角点检测,sift算法)

    如果需要处理的原图及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice 前言 ...

  6. OpenCV特征点检测------Surf(特征点篇)

    Surf(Speed Up Robust Feature) Surf算法的原理                                                              ...

  7. OpenCV特征点检测——Surf(特征点篇)&flann

    学习OpenCV--Surf(特征点篇)&flann 分类: OpenCV特征篇计算机视觉 2012-04-20 21:55 19887人阅读评论(20)收藏举报 检测特征 Surf(Spee ...

  8. sift特征

    已经有很多博客已经将sift特征提取算法解释的很清楚了,我只是记录一些我不明白的地方,并且记录几个理解sift特征比较好的博客. 1. http://aishack.in/tutorials/sift ...

  9. sift特征源码

    先贴上我对Opencv3.1中sift源码的注释吧,虽然还有很多没看懂.先从detectAndCompute看起 void SIFT_Impl::detectAndCompute(InputArray ...

随机推荐

  1. 关于MongoDB分布式高可用集群实现

    一.环境准备 1.本例使用3台Linux主机,IP地址如下: 点击(此处)折叠或打开 Server B Server C 2.根据需要,开启相应主机防火墙的相关端口.本次需要用到3台主机,所以开启这3 ...

  2. 【12】link与@import的区别

    [12]link与@import的区别 link是HTML方式, @import是CSS方式 link最大限度支持并行下载,@import过多嵌套导致串行下载,出现FOUC link可以通过rel=& ...

  3. static对局部变量的作用

    static修饰局部变量: 1,延长局部变量的生命周期到程序技术时,局部变量才会被销毁 2,并没有改变局部变量的作用域 static修饰局部变量的使用场合: 1,如果某个函数的调用频率特别高 2,这个 ...

  4. python基础-面向对象(类)

    类 类的定义 >>> class P: ...     pass ... >>> P <class __main__.P at 0x0000000001F4B ...

  5. 大数据学习——kafka+storm+hdfs整合

    1 需求 kafka,storm,hdfs整合是流式数据常用的一套框架组合,现在 根据需求使用代码实现该需求 需求:应用所学技术实现,kafka接收随机句子,对接到storm中:使用storm集群统计 ...

  6. 2014 ACM/ICPC Asia Regional 北京 Online

    G - Grade Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushroo ...

  7. 【MVC 1】MVC+EF实体框架—原理解析

    导读:在之前,我们学过了三层框架,即:UI.BLL.DAL.我们将页面显示.逻辑处理和数据访问进行分层,避免了一层.两层的混乱.而后,我们又在经典三层的基础上,应用设计模式:外观.抽象工厂+反射,使得 ...

  8. NYOJ-525一道水题思路及详解

    一道水题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 今天LZQ在玩一种小游戏,但是这游戏数有一点点的大,他一个人玩的累,想多拉一些人进来帮帮他,你能写一个程序帮帮他 ...

  9. PAT天梯赛练习题——L3-005. 垃圾箱分布(暴力SPFA)

    L3-005. 垃圾箱分布 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 大家倒垃圾的时候,都希望垃圾箱距离自己比较近,但是谁 ...

  10. 前端ui框架---ant 蚂蚁金服开源

    蚂蚁金服和饿了么好像不错 饿了么官网:http://element.eleme.io/#/zh-CN饿了么github:http://github.com/elemefe 蚂蚁金服  https:// ...