用于计算光流空间导数的Python库

发布于 2024-12-12 10:15:46 字数 361 浏览 0 评论 0原文

我正在尝试使用 Python 中的 OpenCV 从视频计算差分图像速度不变量(例如旋度、发散、变形等)。为此,我需要计算光流 x、y 方向的空间导数。不幸的是,OpenCV 似乎只提供计算光流的 API,而不提供其衍生产品。

有没有用于计算光流的空间导数的Python库?我发现这个SO问题有点类似Lucas Kanade 光流,方向向量,并且该人编写了用于计算空间导数的代码,但如果可能的话,我会喜欢一个库而不是编写我自己编码。任何建议将不胜感激!

I'm trying to compute a differential image velocity invariants (e.g. curl, divergence, deformation, etc) from a video using OpenCV in Python. To do that, I need to compute the spatial derivatives in the x,y directions of the optical flow. Unfortunately, OpenCV only seems to supply the APIs for computing optical flow, not its derivative.

Are there any Python libraries out there for computing spatial derivatives of optical flow? I found this SO question that was somewhat similar Lucas Kanade Optical Flow, Direction Vector, and there is code the person wrote for computing spatial derivatives, but if at all possible I'd love a library rather than writing the code myself. Any suggestions would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

吹泡泡o 2024-12-19 10:15:46

这就是我的看法(我对光流进行了一些工作):

您想要计算光流场的各个偏导数;一个用于x 方向,一个用于y 方向。

我尝试像这样解决问题:

  • 将流数组/矩阵拆分为两个矩阵:xy 流。
  • 对于其中的每一个,您都可以采用简单的方法,只做一个简单的区别:derivative = current_state - last_state。但这种方法非常混乱,因为导数将对最轻微的误差很敏感。
  • 为了解决这个问题,您可以使用易于微分的回归曲线(例如多项式)来近似数据点的一大块(也许是一整行?)。

只需区分近似曲线即可。

您还可以仅平滑各个矩阵并进行幼稚差异,这应该比近似数据点快得多,但应该更能容忍错误。

This is the way I see it (I've worked with optical flow a little bit):

You want to compute the individual partial derivatives of the optical flow field; one for the x direction, and one for the y.

I'd attempt to solve the problem like so:

  • Split your flow array/matrix into two matrices: x and y flow.
  • For each of those, you could go the naive route and just do a simple difference: derivative = current_state - last_state. But this approach is very messy, as the derivative will be sensitive to the slightest bit of error.
  • To counter that, you could approximate one chunk of your data points (maybe a whole row?) with a regression curve that is easily differentiable, like a polynomial.

The just differentiate that approximated curve and you're good to go.

You could also just smooth individual matrices and do a naive difference, which should be much faster than approximating data points, but should be more tolerant to error.

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