本代码使用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. linux相关技术

    1.查询服务器tcp连接状态及连接数 netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

  2. Java-克隆一个对象

    如可方便的克隆一个对象 package com.tj; public class MyClass implements Cloneable { public Object clone() { Clon ...

  3. Debian 9 更新 sourrce.list(163源)

    Debian 9 更新 sourrce.list(163源) 需求说明: 更新apt-get源 kyeup@kyeup-nas:~$ lsb_release -a No LSB modules are ...

  4. Sort a linked list in O(n log n) time using constant space complexity.

    因为题目要求复杂度为O(nlogn),故可以考虑归并排序的思想. 归并排序的一般步骤为: 1)将待排序数组(链表)取中点并一分为二: 2)递归地对左半部分进行归并排序: 3)递归地对右半部分进行归并排 ...

  5. 论文《Piexel Recurrent Nerual Network》总结

    论文<Piexel Recurrent Nerual Network>总结 论文:<Pixel Recurrent Nerual Network> 时间:2016 作者:Aar ...

  6. php 修改

    <?php$id = $_GET['id'];$db = new mysqli("localhost","root","root",& ...

  7. SPOJ QTREE3 Query on a tree again! ——Link-Cut Tree

    [题目分析] QTREE2,一看是倍增算法,太懒了,不写了.( ̄_, ̄ ) QTREE3,树链剖分可以做,发现链上的问题LCT也很好做. 要是子树问题貌似可以DFS序. 然后就成LCT模板题了. 考前 ...

  8. XPosed框架_简单的应用

    0. Xposed框架简介 关于Xposed框架相信大家应该不陌生了,他是Android中Hook技术的一个著名的框架,而Xposed框架是免费的而且还是开源的,本文主要介绍如何通过这个框架来进行系统 ...

  9. 做运动(Dijkstra+并查集+MST)

    上面的题解是这样,这道题我真的脑残,其实打代码的时候就意识到了许多,可以用Dfs+Dij+二分,这样还可以卡一卡 但是我打了spfa+spfa+二分,这个显然很慢,类似的题目我好像还做过一道的,就是在 ...

  10. MySQL 游戏排行榜

    今天在坛子上看到了,顺便写下来. 有两种方法: 1.效率不高,因为有子查询.但是简洁.而且我对SOCRES表做了INDEX.所以性能上也差不了多少. mysql> show create tab ...