Documentation

### This is machine translation

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

# opticalFlowLKDoG class

Estimate optical flow using Lucas-Kanade derivative of Gaussian method

## Description

Estimate the direction and speed of a moving object from one image or video frame to another using the Lucas-Kanade derivative of Gaussian (DoG) method.

## Construction

`opticFlow = opticalFlowLKDoG` returns an optical flow object that is used to estimate the direction and speed of an object’s motion. `opticalFlowLKDoG` uses the Lucas-Kanade method and a derivative of Gaussian (DoG) filter for temporal smoothing.

`opticFlow = opticalFlowLKDoG(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 quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: `'NumFrames'`,`3`

Number of buffered frames for temporal smoothing, specified as the comma-separated pair consisting of '`NumFrames`' and a positive integer-valued scalar. The more you increase this number, the less an object’s abrupt movement affects the optical flow calculation. The amount of delay in flow estimation depends on the value of `NumFrames`. The output flow corresponds to the image at ${t}_{flow}=\left({t}_{current}-\left(NumFrames-1\right)/2\right)$, where tcurrent is the time of the current image.

Standard deviation for image smoothing filter, specified as the comma-separated pair consisting of '`ImageFilterSigma`' and a positive scalar.

Standard deviation for gradient smoothing filter, specified as the comma-separated pair consisting of '`GradientFilterSigma`' and a positive scalar.

Threshold for noise reduction, specified as the comma-separated pair consisting of '`NoiseThreshold`' and a positive scalar. As you increase this number, the less an object’s movement impacts the optical flow calculation.

## Methods

 estimateFlow Estimate optical flow reset Reset the internal state of the object

## Examples

collapse all

`vidReader = VideoReader('viptraffic.avi');`

Create optical flow object.

`opticFlow = opticalFlowLKDoG('NumFrames',3);`

Estimate the optical flow of the objects and display the flow vectors.

``` 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:

`${I}_{x}u+{I}_{y}v+{I}_{t}=0$`

.

• ${I}_{x}$, ${I}_{y}$, and ${I}_{t}$ 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.