VLFeat中SIFT特征点检测
本代码使用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特征点检测的更多相关文章
- SIFT特征点检测学习一(转载)
新手上路,先转载学习tornadomeet的博客:http://www.cnblogs.com/tornadomeet/archive/2012/08/16/2643168.html 特征点检测学习_ ...
- SIFT特征点检测与匹配
SIFT的步骤如下: (1) 尺度空间极值检测(Scale-space Extrema Detection) 也就是在多尺度高斯差分(Difference of Gauss)空间中检测极值点(3x3x ...
- sift特征点检测和特征数据库的建立
类似于ORBSLAM中的ORB.txt数据库. https://blog.csdn.net/lingyunxianhe/article/details/79063547 ORBvoc.txt是怎么 ...
- python+OpenCV 特征点检测
1.Harris角点检测 Harris角点检测算法是一个极为简单的角点检测算法,该算法在1988年就被发明了,算法的主要思想是如果像素周围显示存在多于一个方向的边,我们认为该点为兴趣点.基本原理是根据 ...
- OpenCV计算机视觉学习(13)——图像特征点检测(Harris角点检测,sift算法)
如果需要处理的原图及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice 前言 ...
- OpenCV特征点检测------Surf(特征点篇)
Surf(Speed Up Robust Feature) Surf算法的原理 ...
- OpenCV特征点检测——Surf(特征点篇)&flann
学习OpenCV--Surf(特征点篇)&flann 分类: OpenCV特征篇计算机视觉 2012-04-20 21:55 19887人阅读评论(20)收藏举报 检测特征 Surf(Spee ...
- sift特征
已经有很多博客已经将sift特征提取算法解释的很清楚了,我只是记录一些我不明白的地方,并且记录几个理解sift特征比较好的博客. 1. http://aishack.in/tutorials/sift ...
- sift特征源码
先贴上我对Opencv3.1中sift源码的注释吧,虽然还有很多没看懂.先从detectAndCompute看起 void SIFT_Impl::detectAndCompute(InputArray ...
随机推荐
- SpringMVC之HandlerMapping源码分析
01.doDispatch方法中代码如下:HandlerExecutionChain mappedHandler=this.getHandler(processedRequest) 02.Dispat ...
- 彻底理解Python中的yield
阅读别人的python源码时碰到了这个yield这个关键字,各种搜索终于搞懂了,在此做一下总结: 通常的for…in…循环中,in后面是一个数组,这个数组就是一个可迭代对象,类似的还有链表,字符串,文 ...
- CodeForces 321C Ciel the Commander
Ciel the Commander Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- 九度oj 题目1088:剩下的树
题目描述: 有一个长度为整数L(1<=L<=10000)的马路,可以想象成数轴上长度为L的一个线段,起点是坐标原点,在每个整数坐标点有一棵树,即在0,1,2,...,L共L+1个位置上有L ...
- [SCOI2005]最大子矩阵 (动态规划)
题目描述 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩阵分值之和最大.注意:选出的k个子矩阵不能相互重叠. 输入输出格式 输入格式: 第一行为n,m,k(1≤n≤100,1≤m≤2 ...
- 【倒跑并查集维护连通块】NCPC 2016 A. Artwork
http://codeforces.com/gym/101550/attachments [AC] #include<bits/stdc++.h> using namespace std; ...
- spring 如何动态加载properties文件的内容
1. 在xml中配置你的properties路径: <bean id="messageSource" class="org.springframework.cont ...
- MyEclipse6.5增加对Tomcat7的支持
MyEclipse6.5增加对Tomcat7的支持 最近在研究Servlet3.0,它是JavaEE6.0规范中的一部分 而Servlet3.0对服务器是有要求的,比如Tomcat7+(而Tomcat ...
- OTOCI(bzoj 1180)
Description 给出n个结点以及每个点初始时对应的权值wi.起始时点与点之间没有连边.有3类操作: 1.bridge A B:询问结点A与结点B是否连通.如果是则输出“no”.否则输出“yes ...
- P3102 [USACO14FEB]秘密代码Secret Code
题目描述 Farmer John has secret message that he wants to hide from his cows; the message is a string of ...