Calculate object's velocity in video frames - Optical Flow (Matlab)
<p>I can't understand how Matlab calculates the velocity matrix of a video frame by Optical Flow using <strong>just</strong> the <strong>current frame.</strong> The velocity wouldn't be a relation of different pixels position varying in the time what would include the analysis of two frame or more per time?</p>

<p><a href="http://www.mathworks.com/help/imaq/examples/live-motion-detection-using-optical-flow.html?requestedDomain=www.mathworks.com" rel="nofollow">http://www.mathworks.com/help/imaq/examples/live-motion-detection-using-optical-flow.html?requestedDomain=www.mathworks.com</a></p>

<p><a href="http://www.mathworks.com/help/vision/ref/vision.opticalflow-class.html" rel="nofollow">http://www.mathworks.com/help/vision/ref/vision.opticalflow-class.html</a></p>

<pre><code>% Set up for stream
nFrames = 0;
while (nFrames&lt;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
</code></pre>