OpenCV 示例程序 lkdemo
参考,OpenCv\samples\c\lkdemo.c
有人知道以下代码片段的作用吗?
从 lkdemo.c Q1 中提取的代码
for( i = k = 0; i < count; i++ )
{
if( add_remove_pt )
{
double dx = pt.x - points[1][i].x;
double dy = pt.y - points[1][i].y;
if( dx*dx + dy*dy <= 25 )
{
add_remove_pt = 0;
continue;
}
}
if( !status[i] )
continue;
points[1][k++] = points[1][i];
cvCircle( image, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
}
count = k;
。
粗线有什么作用? >>> 点[1][k++] = 点[1][i];
为什么是 k++ ? 我很困惑,认为下一点被覆盖了 当前点
Q2。
当 cvCircle id 随着帧循环而绘制时,旧点被清除并新点被绘制在哪里?
我期待您的意见。
谢谢=)
reference, OpenCv\samples\c\lkdemo.c
Anybody know what does the following snippet of codes does ?
Code extracted from lkdemo.c
for( i = k = 0; i < count; i++ )
{
if( add_remove_pt )
{
double dx = pt.x - points[1][i].x;
double dy = pt.y - points[1][i].y;
if( dx*dx + dy*dy <= 25 )
{
add_remove_pt = 0;
continue;
}
}
if( !status[i] )
continue;
points[1][k++] = points[1][i];
cvCircle( image, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
}
count = k;
Q1.
What does the bold line does ? >> points[1][k++] = points[1][i];
Why k++ ? I am confuse, thinking that next point is overwritten by
the current point
Q2.
As cvCircle id drawn as the frame loops, where is the old points cleared and new point drawn ?
I look forward to your inputs.
Thanks =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Q1:
如果我重构代码,也许会有所帮助:
因此,在问题 1 的行中,i 总是递增(通过循环递增),但 k 仅在 status[i] 为 true 时递增。 简而言之,它通过复制数组中 status[i] 为 false 的点来消除这些点,然后将数组的长度(计数)设置为 k,即通过消除的数字。
Q1:
Perhaps it would help if I refactor the code:
So in the line for question 1, i always increments (it's incremented by the loop) but k only increments when status[i] is true. In short, it eliminates any points in the array where status[i] is false by copying over them, and then setting the length of the array (count) to k, the number that passed the elimination.
它会消除任何漂移超过 5 个像素 (5*5=25) 的点。 k 用于跟踪删除点时的输出索引。
It's eliminating any points that have drifted more than 5 pixels (5*5=25). k is being used to track the output index when points are deleted.
我设法找出清除点的位置。
随着帧循环,新点反映在新帧和新帧上
帧刷新前一个。
I manage to figure out the where the clearing of points are done.
As frame loops the new points are reflected on the new frame and the new
frame refreshes the previous.
已经过时了,但出于协议的考虑 -
现在有一个适用于 iPhone 的开源 Lucas Kanade 应用程序 - http://www.success-ware.com/150842/Lucas-Kanade-Detection-for-the-iPhone
它也使用 lkdemo 代码,并添加了一些额外的内容它。
您将在上面的链接中找到 AppStore 上的应用程序和项目源代码的链接。
任何人,
干杯,
奥德
Way out-dated, but for protocol's sake -
There's an open source Lucas Kanade app for the iPhone now - http://www.success-ware.com/150842/Lucas-Kanade-Detection-for-the-iPhone
It uses lkdemo code as well, and adds some extras around it.
You will find links to both an app on the AppStore and the project's source code in the link above.
HTH anyone,
Cheers,
Oded
让我看看我是否明白。 该块代码消除了 status[i] 为 false 的任何点,即前一个图像中存在但当前图像中未找到的点。 但这样做的话,我们就会在跟踪中丢失这些点,不是吗? 我的意思是,如果我们跟踪一个具有 N px 的对象,那么每次迭代我们都会丢弃点。 这是一个好方法吗? 为什么要这样做?
Let me see if I get it. This block code eliminates any points where status[i] is false, that is, the ones that were in the previous image and were not found in the current image. But doing this, we're losing these points in our tracking, aren't we? I mean, if we are tracking an object with N px, every iterate we're dropping points out. Is that a good approach? Why to do this?