Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

opticalFlowHS class

Estimate optical flow using Horn-Schunck method

Description

Estimate the direction and speed of a moving object from one image or video frame to another using the Horn-Schunck method.

Construction

opticFlow = opticalFlowHS returns an optical flow object that is used to estimate the direction and speed of an object’s motion. opticalFlowHS uses the Horn-Schunck algorithm.

opticFlow = opticalFlowHS(Name,Value) includes additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'MaxIteration',10

expand all

Expected smoothness of optical flow, specified as the comma-separated pair consisting of 'Smoothness' and a positive scalar. Increase this value when there is increased motion between consecutive frames. A typical value for 'Smoothness' is around 1.

Maximum number of iterations to perform in the optical flow iterative solution, specified as the comma-separated pair consisting of 'MaxIteration' and a positive integer-valued scalar. Increase this value to estimate objects with low velocity.

Computation stops when the number of iterations equals MaxIteration or when the algorithm reaches the value set by VelocityDifference. To use only MaxIteration to stop computation, set VelocityDifference to 0.

Minimum absolute velocity difference at which to stop iterative computation, specified as the comma-separated pair consisting of 'VelocityDifference' and a positive scalar. This value depends on the input data type. Decrease this value to estimate the optical flow of objects that have low velocity.

Computation stops when the number of iterations equals MaxIteration or when the algorithm reaches the value set by VelocityDifference. To only use MaxIteration to stop computation, set VelocityDifference to 0. To use only VelocityDifference, set MaxIteration to Inf

Methods

estimateFlowEstimate optical flow
resetReset the internal state of the object

Examples

expand all

Read in a video file.

vidReader = VideoReader('viptraffic.avi');

Create optical flow object.

opticFlow = opticalFlowHS;

Estimate the optical flow of objects in the video.

while hasFrame(vidReader)
    frameRGB = readFrame(vidReader);
    frameGray = rgb2gray(frameRGB);
  
    flow = estimateFlow(opticFlow,frameGray); 

    imshow(frameRGB) 
    hold on
    plot(flow,'DecimationFactor',[5 5],'ScaleFactor',25)
    hold off 
end

Algorithms

expand all

To compute the optical flow between two images, you must solve the following optical flow constraint equation:

Ixu+Iyv+It=0

.

  • Ix, Iy, and It are the spatiotemporal image brightness derivatives.

  • u is the horizontal optical flow.

  • v is the vertical optical flow.

References

[1] Barron, J. L., D. J. Fleet, S. S. Beauchemin, and T. A. Burkitt. “Performance of optical flow techniques”. CVPR, 1992.

Extended Capabilities

Introduced in R2015a