我无法理解Matlab如何使用 当前帧来通过光流计算视频帧的速度矩阵。速度不会是一个不同像素位置的关系,在时间变化,包括每帧两帧或更多帧的分析?
http://www.mathworks.com/help/vision/ref/vision.opticalflow-class.html
% Set up for stream
nFrames = 0;
while (nFrames<100) % Process for the first 100 frames.
% Acquire single frame from imaging device.
rgbData = step(vidDevice);
% Compute the optical flow for that particular frame.
optFlow = step(optical,rgb2gray(rgbData)); %***HERE IS THE DOUBT! iT JUST USES ONE FRAME!!!***
% Downsample optical flow field.
optFlow_DS = optFlow(r, c);
H = imag(optFlow_DS)*50;
V = real(optFlow_DS)*50;
% Draw lines on top of image
lines = [Y(:)'; X(:)'; Y(:)'+V(:)'; X(:)'+H(:)'];
rgb_Out = step(shapes, rgbData, lines');
% Send image data to video player
% Display original video.
step(hVideoIn, rgbData);
% Display video along with motion vectors.
step(hVideoOut, rgb_Out);
% Increment frame count
nFrames = nFrames + 1;
end
答案 0 :(得分:1)
vision.OpticalFlow
是一个班级。当您创建vision.OpticalFlow
对象并调用其step
方法时,它会记住您传递给它的帧。然后在每次对step
的调用中,它计算最后一次调用的存储帧与当前帧之间的光流。
顺便说一下,vision.OpticalFlow
已被弃用。如果您有最新版本的MATLAB,则可以使用一系列光流功能:opticalFlowFarneback
,opticalFlowHS
,opticalFlowLK
和opticalFlowLKDoG
。