Matlab中的光流

时间:2016-02-11 22:02:35

标签: matlab opticalflow

如何在Matlab中计算和显示两幅图像的光流? 它们是否具有内置功能,如果是这样,您如何实现它?

2 个答案:

答案 0 :(得分:0)

如果您只是对如何将光流可视化为颜色和/或箭头感兴趣,这里有一个简单的脚本向您展示如何在Matlab中完成:

% Generate an example flow field
[u,v] = meshgrid(linspace(-1,1)/sqrt(2));
mag = sqrt(u.^2 + v.^2);
an = (atan2(v,u)+pi)/(2*pi);

%display as arrows
subplot(1,2,2);
quiver(u(1:5:end,1:5:end),v(1:5:end,1:5:end));
axis image

%display as color
subplot(1,2,1);
imagesc(hsv2rgb(an,mag,mag));
axis image

我的toolbox on optical flow in Matlab(我现在正在宣传)至少有3种不同的方式,通过箭头和颜色编码的组合可视化光流。要将其与avi电影文件一起使用,请执行以下操作:

in.movieType = 'example.avi'; % assumes a file 'example.avi' in current folder. 
% in.movieType = 'synthetic';  % generate synthetic video. 
% in.movieType = 'camera';     % assumes a camera available in the system. 

in.method =  @Flow1;       %Locally regularized and vectorized method
% in.method =  @FlowLK;      %Lucas and Kanade 
% in.method =  @FlowHS;      %Horn and Schunk, variational (global regularization)

in.bRecordFlow = 1; %record the optical flow, not only display it

% resolution of flow field [Height Width]:
in.flowRes = [24 24];     %flow resolution <= video resolution

% DO THE CALL TO THE TOOLBOX(initiate the session):
pathToSave = vidProcessing(in);

% view interactively the saved session:
FancyFlowPlayer(pathToSave);

答案 1 :(得分:0)

如果您可以访问Matlab计算机视觉工具箱,则可以使用Lucas-Kanade Optical FLow,Horn-Schunck和Farnebäck的内置功能。 它们都需要灰度图像序列。它们返回一个Flow对象,其中包含x,y方向的流量以及幅度和角度。 为了显示你可以使用情节或箭袋。