Main Content

reset

Reset the internal state of the optical flow estimation object

Since R2024b

Description

reset(flowModel) resets the internal state of the optical flow estimation object, flowModel. The previous frame is reset to its initial value which is a uniform image of intensity value 0. To reuse an opticalFlowRAFT object for a new video, call reset to clear cached frame information from a previously processed video.

example

Examples

collapse all

Create a RAFT optical flow object.

flowModel = opticalFlowRAFT;

Create an object to read the input video file.

vidReader = VideoReader("visiontraffic.avi",CurrentTime=11);

Create a custom figure window to visualize the optical flow vectors.

h = figure;
movegui(h);
hViewPanel = uipanel(h, Position=[0 0 1 1], Title="Plot of Optical Flow Vectors");
hPlot = axes(hViewPanel);

Read consecutive image frames to estimate optical flow. Display the current current frame and overlay optical flow vectors using a quiver plot. The estimateFlow function calculates the optical flow between two consecutive frames.

Note that the function internally stores the previous frame and utilizes it implicitly for optical flow estimation. Consequently, when the function is called for the first time on a sequence of frames, it will return a zero flow. This is because, in the absence of a genuine previous frame, the initial frame is treated as both the current and previous frame, leading to no detectable motion between the two. This is consistent with the argument structure and behavior of established optical flow estimation methods, such as opticalFlowFarneback.

while hasFrame(vidReader)
    frame = readFrame(vidReader);
    flow = estimateFlow(flowModel,frame);

    imshow(frame)
    hold on
    plot(flow,DecimationFactor=[10 10],ScaleFactor=0.45,Parent=hPlot,color="g");
    hold off
    pause(10^-3)
end

Reset the opticalFlowRAFT object after the video processing has completed. This clears the internal state of the object, including the saved previous frame.

reset(flowModel);

Input Arguments

collapse all

Object for optical flow estimation, specified as an opticalFlowRAFT object.

Version History

Introduced in R2024b