Kanade-Lucas-Tomasi Feature Tracker 代码分析
因为研究需要,仔细看了下代码,看看有什么可以利用的地方。
整体来说Kanade-Lucas-Tomasi Feature Tracker的方法就是首先找去特征点,之后用光流去跟踪的方法。
Opencv中已经有了example,大家可以运行下看效果,同时Homepage:http://www.ces.clemson.edu/~stb/klt/
上有源码,整个的流程跟Opencv差不多。
我们以官网上的原程序中的example1进行分析:(剩下的几个例子整体流程都差不多,仅仅是目的不一样)
首先都是建立两个结构体:
tc = KLTCreateTrackingContext();
KLTPrintTrackingContext(tc);
fl = KLTCreateFeatureList(nFeatures);
tc就是跟踪的中用到的一些参数在选特征点的时候也有用到。
fl就是我们说道德特征点了,包括了特征值和特征点在图像中的位置。
之后使用:
KLTSelectGoodFeatures(tc, img1, ncols, nrows, fl);
使用上面的函数选取特征点
KLTTrackFeatures(tc, img1, img2, ncols, nrows, fl);
使用这个函数在img2中寻找对应的特征点。
一次循环就可以实现跟踪了。
那么出现了一个问题:特征点是怎么定义的:
我们分析KLTSelectGoodFeatures这个函数:
函数中又使用了:
_KLTSelectGoodFeatures(tc, img, ncols, nrows,
fl, SELECTING_ALL);
这个函数,函数中首先见了了一个pointlist的分量,并分配了内存空间:
pointlist = (int *) malloc(ncols * nrows * 3 * sizeof(int));
为什么要*3呢?其实pointlist中存了图像中点的位置x,y和特征值的大小val。
特征值是什么呢?这个特征是就是对应像素点的梯度值。
{
register float gx, gy;
register float gxx, gxy, gyy;
register int xx, yy;
register int *ptr;
float val;
unsigned int limit = 1;
int borderx = tc->borderx; /* Must not touch cols */
int bordery = tc->bordery; /* lost by convolution */
int x, y;
int i;
if (borderx < window_hw) borderx = window_hw;
if (bordery < window_hh) bordery = window_hh;
/* Find largest value of an int */
for (i = 0 ; i < sizeof(int) ; i++) limit *= 256;
limit = limit/2 - 1;
/* For most of the pixels in the image, do ... */
ptr = pointlist;
for (y = bordery ; y < nrows - bordery ; y += tc->nSkippedPixels + 1)
for (x = borderx ; x < ncols - borderx ; x += tc->nSkippedPixels + 1) {
/* Sum the gradients in the surrounding window */
gxx = 0; gxy = 0; gyy = 0;
for (yy = y-window_hh ; yy <= y+window_hh ; yy++)
for (xx = x-window_hw ; xx <= x+window_hw ; xx++) {
gx = *(gradx->data + ncols*yy+xx);
gy = *(grady->data + ncols*yy+xx);
gxx += gx * gx;
gxy += gx * gy;
gyy += gy * gy;
}
/* Store the trackability of the pixel as the minimum
of the two eigenvalues */
*ptr++ = x;
*ptr++ = y;
val = _minEigenvalue(gxx, gxy, gyy);
if (val > limit) {
KLTWarning("(_KLTSelectGoodFeatures) minimum eigenvalue %f is "
"greater than the capacity of an int; setting "
"to maximum value", val);
val = (float) limit;
}
*ptr++ = (int) val;
npoints++;
}
代码中的特征值取得时每个像素点临域梯度值的加权值。
之后程序来到了函数:
_enforceMinimumDistance(
pointlist,
npoints,
featurelist,
ncols, nrows,
tc->mindist,
tc->min_eigenvalue,
overwriteAllFeatures);
这里通过比较每个像素点val和对应阈值的大小来提取特征点:
if (!featuremap[y*ncols+x] && val >= min_eigenvalue) {
featurelist->feature[indx]->x = (KLT_locType) x;
featurelist->feature[indx]->y = (KLT_locType) y;
featurelist->feature[indx]->val = (int) val;
featurelist->feature[indx]->aff_img = NULL;
featurelist->feature[indx]->aff_img_gradx = NULL;
featurelist->feature[indx]->aff_img_grady = NULL;
featurelist->feature[indx]->aff_x = -1.0;
featurelist->feature[indx]->aff_y = -1.0;
featurelist->feature[indx]->aff_Axx = 1.0;
featurelist->feature[indx]->aff_Ayx = 0.0;
featurelist->feature[indx]->aff_Axy = 0.0;
featurelist->feature[indx]->aff_Ayy = 1.0;
indx++;
min_eigenvalue就是所使用的阈值,在tc中定义
那么程序的修改,我们需要根据自己的特征对这个阈值进行修改,同时对featurelist进行如上的修改,其实主要还是x,y,val三个值的修改。
不对的地方请大家指正。
Kanade-Lucas-Tomasi Feature Tracker 代码分析相关推荐
- BT源代码学习心得(七):跟踪服务器(Tracker)的代码分析(HTTP协议处理对象) -- 转贴自 wolfenstein (NeverSayNever)
BT源代码学习心得(七):跟踪服务器(Tracker)的代码分析(HTTP协议处理对象) author: wolfenstein (NeverSayNever) 上次我们分析了Tracker类初始化的 ...
- BT源代码学习心得(六):跟踪服务器(Tracker)的代码分析(初始化) -- 转贴自 wolfenstein (NeverSayNever)
BT源代码学习心得(六):跟踪服务器(Tracker)的代码分析(初始化) author:wolfenstein Tracker在BT中是一个很重要的部分.这个名词我注意到以前的文章中都是直接引用,没 ...
- BT源代码学习心得(八):跟踪服务器(Tracker)的代码分析(用户请求的实际处理) - 转贴自 wolfenstein (NeverSayNever)
BT源代码学习心得(八):跟踪服务器(Tracker)的代码分析(用户请求的实际处理) author: wolfenstein 通过上一次的分析,我们已经知道了Tracker采用http协议和客户端通 ...
- BT源代码学习心得(六):跟踪服务器(Tracker)的代码分析(初始化)
BT源代码学习心得(六):跟踪服务器(Tracker)的代码分析(初始化) 发信人: wolfenstein (NeverSayNever), 个人文集 标 题: BT源代码学习心得(六):跟踪服务 ...
- tensorflow笔记:多层CNN代码分析
tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) tensorflow笔记:多层CNN代码分析 (三) tensorflow笔记:多层LSTM代 ...
- 开源项目kcws代码分析--基于深度学习的分词技术
http://blog.csdn.net/pirage/article/details/53424544 分词原理 本小节内容参考待字闺中的两篇博文: 97.5%准确率的深度学习中文分词(字嵌入+Bi ...
- vins中imu融合_VINS-Mono代码分析与总结(最终版)
VINS-Mono代码分析总结 参考文献 前言 ??视觉与IMU融合的分类: 松耦合和紧耦合:按照是否把图像的Feature加入到状态向量区分,换句话说就是松耦合是在视觉和IMU各自求出的位姿的基础上 ...
- VINS-Mono代码分析与总结(完整版)
VINS-Mono代码分析总结 参考文献 1 VINS-Mono: A Robust and Versatile Monocular Visual-Inertial State Estimator, ...
- GraphSAGE NIPS 2017 代码分析(Tensorflow版)
文章目录 数据集 ppi数据集信息 toy-ppi-G.json 图的信息 toy-ppi-class_map.json toy-ppi-id_map.json toy-ppi-walks.txt t ...
最新文章
- Tungsten Fabric SDN — Service Chain — 高级特性
- redhat 6.2安装telnet服务
- 从Jenkins或Gerrit上获取拉代码和编译命令
- 【最新】docker 安装elasticsearch + kibana步骤【第二篇_kibana】
- android布局属性
- time模块 random模块
- AcWing 789. 数的范围
- 业务逻辑安全思路总结
- 英雄联盟掉帧、卡顿,用这四个方法就够了
- oh-my-zsh主题添加命令显示执行时间和当前时间
- VisualStudio Qt开发环境搭建以及Qt moc的讲解
- 对象存储(云存储)概述
- markman,让设计更有爱!
- Python人脸微笑识别2-----Ubuntu16.04基于Tensorflow卷积神经网络模型训练的Python3+Dlib+Opencv实现摄像头人脸微笑检测
- ipa包发布App Store
- JSP+SQL基于JSP的学生信息管理系统(源代码+论文+答辩PPT)
- 关于设计抗混叠滤波器的三个指导原则
- 忽如一夜春风来,千树万树梨花开
- 周鸿祎的互联网方法论:颠覆式创新
- 超全教授svg图标素材网站整理