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 ...
随机推荐
- Knockout v3.4.0 中文版教程-6-计算监控-可写的计算监控
2.可写的计算监控 初学者可能想要跳过本节 - 可写的计算监控是相当高级的部分,在大多数情况下不是必需的. 通常,计算监控是一个通过其他监控值计算出的值,因此是只读的. 令人惊讶的是,可以使计算监控值 ...
- 【20】display,float,position的关系
[20]display,float,position的关系 如果display为none,元素不显示. 否则,如果position值为absolute或者fixed,元素绝对定位,float的计算值为 ...
- kali2018利用ss和ProxyChains实现任意应用代理
第一步:配置ss 第二步:配置proxychain vim /etc/proxychains.conf 第三步:使用proxychains 终端输入: proxychains firefox 通过代理 ...
- 第五部分 linux系统管理员 开机流程 模组管理 与loader
第五部分 linux系统管理员 开机流程 模组管理 与loader 开机流程分析 cmos保存电脑硬件的参数 bios 基本的输入输出系统 读取硬件的软件 MBR master bo ...
- A. Test for Job
A. Test for Job Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO ...
- Title共通写法
用: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_c ...
- 刷题总结——教主的魔法(bzoj3343)
题目: Description 教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了一起,这次他们排成了一列,被编号为1.2.…….N. ...
- 刷题总结——art2(ssoj)
题目: 题解: o(n)复杂度扫一遍再用一个stack维护就可以了·····mdzz这道题都不会做·· 代码: #include<iostream> #include<cstdio& ...
- 在 Linux 实例上自动安装并运行 VNC Server
原文网址:https://help.aliyun.com/knowledge_detail/41181.html?spm=5176.8208715.110.11.4c184ae8mlC7Yy 您可以使 ...
- iOS 收款计算器算法
一个收款计算器算法,从之前高仿有赞Demo里面抽离的一个界面 demo 在这里 https://github.com/L-vinCent/calculView_function 显示计算记录 不能连续 ...