使用光流对流图像 [英] Convection of an image using optical flow

查看:104
本文介绍了使用光流对流图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个图像(frame1和frame2),我能够使用opencv计算u,v:

I have two images (frame1 and frame2) and I am able to calculate u,v using opencv:

flow = cv2.calcOpticalFlowFarneback(prvs,next, 0.5, 1, 3, 15, 3, 5, 1, 0)

我想使用此u,v转换frame1,以使用各种光流方法量化差异的质量.我打算用这些u,v来推断.

I want to translate frame1 using this u,v to quantify the quality of the difference using various optical flow methods. I intend to extrapolate using these u,v.

有没有简单的方法可以实现这一目标?

Is there a simple way to achieve this?

推荐答案

一种计算简单转换的方法是平均流量:

One way to compute a simple translation is to average the flow:

avg_u = np.mean(flow[:, :, 0])
avg_v = np.mean(flow[:, :, 1])

这将提供翻译所需的向量(avg_u, avg_v).

This gives the vector (avg_u, avg_v) needed to translate.

关于您的评论,似乎您想将每个像素(x,y)移动到其流矢量(u(x,y), v(x,y))指定的位置.

Regarding your comments, it seems you want to move every pixel (x,y) to the location specified by its flow vector (u(x,y), v(x,y)).

首先,生成笛卡尔网格:

First, generate a Cartesian grid:

height, width = flow.shape[0, 1]
R2 = np.dstack(np.meshgrid(np.arange(width), np.arange(height)))

然后,所需的映射只是在流中添加此网格:

Then, the desired mapping is simply the addition of this grid with the flow:

pixel_map = R2 + flow

最后,执行 cv2.remap :

Finally, perform a cv2.remap:

new_frame = cv2.remap(prev_frame, pixel_map)

这篇关于使用光流对流图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆