![](/img/trans.png)
[英]How to obtain velocity and magnitude vectors of the optical flow field? I am using Lucas-Kande method of optical flow
[英]Car Tracking using Optical Flow. Why isnt the vectors plotting properly
我是光学流和计算机视觉的新手,我开始使用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:这是结果:
尝试使用
lines = [Rv(:); Cv(:); Rv(:)+H(:); Cv(:)+V(:)];
代替
lines = [Rv;Cv; Rv+H(:)'; Cv+V(:)'];
更好的是,如果您使用的是Matlab的最新版本,请尝试使用insertShape
函数而不是vision.ShapeInserter
。
编辑:如果您具有计算机视觉系统工具箱的最新版本,请尝试新的光流功能: opticalFlowHS
, opticalFlowLK
, opticalFlowLKDoG
和opticalFlowFarneback
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.