[][src]Function opencv::video::calc_optical_flow_pyr_lk

pub fn calc_optical_flow_pyr_lk(
    prev_img: &dyn ToInputArray,
    next_img: &dyn ToInputArray,
    prev_pts: &dyn ToInputArray,
    next_pts: &mut dyn ToInputOutputArray,
    status: &mut dyn ToOutputArray,
    err: &mut dyn ToOutputArray,
    win_size: Size,
    max_level: i32,
    criteria: &TermCriteria,
    flags: i32,
    min_eig_threshold: f64
) -> Result<()>

Calculates an optical flow for a sparse feature set using the iterative Lucas-Kanade method with pyramids.

Parameters

  • prevImg: first 8-bit input image or pyramid constructed by buildOpticalFlowPyramid.
  • nextImg: second input image or pyramid of the same size and the same type as prevImg.
  • prevPts: vector of 2D points for which the flow needs to be found; point coordinates must be single-precision floating-point numbers.
  • nextPts: output vector of 2D points (with single-precision floating-point coordinates) containing the calculated new positions of input features in the second image; when OPTFLOW_USE_INITIAL_FLOW flag is passed, the vector must have the same size as in the input.
  • status: output status vector (of unsigned chars); each element of the vector is set to 1 if the flow for the corresponding features has been found, otherwise, it is set to 0.
  • err: output vector of errors; each element of the vector is set to an error for the corresponding feature, type of the error measure can be set in flags parameter; if the flow wasn't found then the error is not defined (use the status parameter to find such cases).
  • winSize: size of the search window at each pyramid level.
  • maxLevel: 0-based maximal pyramid level number; if set to 0, pyramids are not used (single level), if set to 1, two levels are used, and so on; if pyramids are passed to input then algorithm will use as many levels as pyramids have but no more than maxLevel.
  • criteria: parameter, specifying the termination criteria of the iterative search algorithm (after the specified maximum number of iterations criteria.maxCount or when the search window moves by less than criteria.epsilon.
  • flags: operation flags:
  • OPTFLOW_USE_INITIAL_FLOW uses initial estimations, stored in nextPts; if the flag is not set, then prevPts is copied to nextPts and is considered the initial estimate.
  • OPTFLOW_LK_GET_MIN_EIGENVALS use minimum eigen values as an error measure (see 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.
  • minEigThreshold: the algorithm calculates the minimum eigen value of a 2x2 normal matrix of optical flow equations (this matrix is called a spatial gradient matrix in Bouguet00), divided by number of pixels in a window; if this value is less than 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.

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.

Note:

  • An example using the Lucas-Kanade optical flow algorithm can be found at opencv_source_code/samples/cpp/lkdemo.cpp
  • (Python) An example using the Lucas-Kanade optical flow algorithm can be found at opencv_source_code/samples/python/lk_track.py
  • (Python) An example using the Lucas-Kanade tracker for homography matching can be found at opencv_source_code/samples/python/lk_homography.py

C++ default parameters

  • win_size: Size(21,21)
  • max_level: 3
  • criteria: TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01)
  • flags: 0
  • min_eig_threshold: 1e-4