cv.calcOpticalFlowPyrLK - MATLAB File Help |
Calculates an optical flow for a sparse feature set using the iterative Lucas-Kanade method with pyramids
nextPts = cv.calcOpticalFlowPyrLK(prevImg, nextImg, prevPts)
[nextPts, status, err] = cv.calcOpticalFlowPyrLK(...)
[...] = cv.calcOpticalFlowPyrLK(..., 'OptionName', optionValue, ...)
prevImg
.{[x,y], ...}
prevPts
.GetMinEigenvals
option; if the flow wasn't found then the
error is not defined (use status
to find such cases).nextPts
. If not specified, prevPts
will be used as an initial
estimate. The vector must have the same size as in the input. Not set by
default.MaxLevel
. Default to 3.Criteria.maxCount
or when the search window moves by less
than Criteria.epsilon
. Struct with {'type','maxCount','epsilon'}
fields is accepted. The type field should have one of 'Count', 'EPS', or
'Count+EPS' to indicate which criteria to use. Default to
struct('type','Count+EPS', 'maxCount',30, 'epsilon',0.01)
.MinEigThreshold
description); if the flag is not set, then L1 distance
between patches around the original and a moved point, divided by number
of pixels in a window, is used as a error measure. Default to false.MinEigThreshold
, then a corresponding
feature is filtered out and its flow is not processed, so it allows to
remove bad points and get a performance boost. Default to 1e-4.The function implements a sparse iterative version of the Lucas-Kanade optical flow in pyramids. See [Bouguet00]. The function is parallelized with the TBB library.
[Bouguet00]:
Jean-Yves Bouguet. "Pyramidal Implementation of the Lucas Kanade Feature Tracker. Description of the algorithm", Intel Corporation, 2001.
prevIm = rgb2gray(imread('prev.jpg'));
nextIm = rgb2gray(imread('next.jpg'));
prevPts = cv.goodFeaturesToTrack(prevIm);
nextPts = cv.calcOpticalFlowPyrLK(prevIm, nextIm, prevPts);