OpenCV 示例程序 lkdemo

发布于 2024-07-09 11:00:40 字数 985 浏览 11 评论 0原文

参考,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

南风起 2024-07-16 11:00:40

Q1:

如果我重构代码,也许会有所帮助:

if( status[i] ) {
    points[1][k++] = points[1][i];  // <---- Q1
    cvCircle( image, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
}

因此,在问题 1 的行中,i 总是递增(通过循环递增),但 k 仅在 status[i] 为 true 时递增。 简而言之,它通过复制数组中 status[i] 为 false 的点来消除这些点,然后将数组的长度(计数)设置为 k,即通过消除的数字。

Q1:

Perhaps it would help if I refactor the code:

if( status[i] ) {
    points[1][k++] = points[1][i];  // <---- Q1
    cvCircle( image, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
}

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.

£烟消云散 2024-07-16 11:00:40

它会消除任何漂移超过 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.

属性 2024-07-16 11:00:40

我设法找出清除点的位置。
随着帧循环,新点反映在新帧和新帧上
帧刷新前一个。

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.

一口甜 2024-07-16 11:00:40

已经过时了,但出于协议的考虑 -

现在有一个适用于 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

伴随着你 2024-07-16 11:00:40

让我看看我是否明白。 该块代码消除了 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文