本代码使用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. 2,格式化输出and编码基础

    格式化输出: input格式化输出: name = input('请输入姓名:') name = input('请输入姓名:') Age = int(input('请输入年龄:')) job = in ...

  2. UI测试点

    UI测试点 1.界面是否美观 2.元素大小 3.界面元素是否对齐方式统一 4.界面字体属性是否正确 5.界面链接及触发动作 6.元素内容是否显示正确.易懂.友好 7.所有输入框进行输入判断测试 8.所 ...

  3. D. Frequent values

    D. Frequent values Time Limit: 3000ms Case Time Limit: 3000ms Memory Limit: 131072KB   64-bit intege ...

  4. lamp环境配置,ubunutu下

    Ubuntu下快速搭建LAMP环境过程记录: 安装 Apache2: sudo apt-get install apache2 安装PHP模块: sudo apt-get install php5 安 ...

  5. spring,mybatis事务管理配置与@Transactional注解使用

    spring,mybatis事务管理配置与@Transactional注解使用[转]   spring,mybatis事务管理配置与@Transactional注解使用 概述事务管理对于企业应用来说是 ...

  6. BZOJ 3998 [TJOI2015]弦论 ——后缀自动机

    直接构建后缀自动机. 然后. 然后只需要再后缀自动机的go树上类似二分的方法进行查找即可,实际上是“26分”. 然后遇到了处理right集合的问题,然后觉得在go和parent树上上传都是可以的,毕竟 ...

  7. 【bzoj1878】[SDOI2009]HH的项链 - 树状数组 - 离线处理

    [SDOI2009]HH的项链 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4834  Solved: 2384[Submit][Status][Dis ...

  8. 数字梯形(cogs 738)

    «问题描述:给定一个由n 行数字组成的数字梯形如下图所示.梯形的第一行有m 个数字.从梯形的顶部的m 个数字开始,在每个数字处可以沿左下或右下方向移动,形成一条从梯形的顶至底的路径.规则1:从梯形的顶 ...

  9. net2:类,事件与委托

    原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  10. Valentine's Day Round hdu 5176 The Experience of Love [好题 带权并查集 unsigned long long]

    传送门 The Experience of Love Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...