简体   繁体   中英

Calculate object's velocity in video frames - Optical Flow (Matlab)

I can't understand how Matlab calculates the velocity matrix of a video frame by Optical Flow using just the current frame. 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?

http://www.mathworks.com/help/imaq/examples/live-motion-detection-using-optical-flow.html?requestedDomain=www.mathworks.com

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

vision.OpticalFlow is a class. When you create a vision.OpticalFlow object, and call its step method, it remembers the frame you pass into it. Then on every subsequent call to step , it computes the optical flow between the stored frame from the last call, and the current frame.

By the way, vision.OpticalFlow has been deprecated. If you have a recent version of MATLAB, there is a family of optical flow functions you can use: opticalFlowFarneback , opticalFlowHS , opticalFlowLK , and opticalFlowLKDoG .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM