# 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.

# opticalFlowLK class

Estimate optical flow using Lucas-Kanade method

## Description

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

## Construction

`opticFlow = opticalFlowLK` returns an optical flow object used to estimate the direction and speed of an object’s motion. `opticalFlowLK` uses the Lucas-Kanade algorithm and a difference filter, `[-1 1]`, for temporal smoothing.

`opticFlow = opticalFlowLK(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: `'NoiseThreshold'`,`0.0039`

expand all

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

## Methods

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

## Examples

expand all

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

Create optical flow object.

`opticFlow = opticalFlowLK('NoiseThreshold',0.009);`

Estimate and display 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',10) 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.