我是新的光流和计算机视觉在一般情况下,我开始工作与一个简单的演示例子从Matlab。
它的目的是使用视频并将运动矢量绘制到屏幕上。我使用以下代码:
%% initialization
close all
clear all
% Create reader
reader = vision.VideoFileReader;
reader.Filename = 'viptraffic.avi';
% Create viewer
viewer = vision.DeployableVideoPlayer;
%%viewer.FrameRate = 10;
%Create Optical Flow
optical = vision.OpticalFlow; %how pixels are moving from one frame to the next
optical.OutputValue = 'Horizontal and vertical components in complex form'; %will allow us to draw a vector
%%%on the vision so that we see how the pixels are moving from one frame to the next
%%We pass the horizontal and vertical components to the shape inserter
%%below
% Display vector fields
shapes = vision.ShapeInserter;
shapes.Shape = 'Lines';
shapes.BorderColor = 'white';
R = 1:4:120;%%downsample the optical flow field
C = 1:4:160;%%downsample the optical flow field
[Cv, Rv] = meshgrid (C, R); %%% display a grid on the image and take every fourth value
Rv = Rv(:)';
Cv = Cv(:)';
%% Execution
reset(reader)
%Set up for stream
while ~isDone(reader)
I = step(reader);
of = step(optical,rgb2gray(I));
size(of)
ofd = of(R,C);
size(ofd)
H = imag(ofd)*20;
V = real(ofd)*20;
%Draw lines on top of image
lines = [Rv;Cv; Rv+H(:)'; Cv+V(:)']; %%start and a finish , start+movement, end+movement
% lines = [Cv;Rv;Cv;Rv];
Ishp = step(shapes,I,lines);
step(viewer,Ishp);
end
release(viewer);我不知道为什么向量线绘制得不正确。
有谁可以帮我?
谢谢
PS:结果如下:

发布于 2014-07-02 17:57:17
试着使用
lines = [Rv(:); Cv(:); Rv(:)+H(:); Cv(:)+V(:)];而不是
lines = [Rv;Cv; Rv+H(:)'; Cv+V(:)'];更好的是,如果您有一个最新版本的Matlab,尝试使用insertShape函数而不是vision.ShapeInserter。
编辑:如果您有计算机视觉系统工具箱的最新版本,请尝试新的光流函数:opticalFlowHS、opticalFlowLK、opticalFlowLKDoG和opticalFlowFarneback。
https://stackoverflow.com/questions/24520318
复制相似问题