Nodes/comfyui_cv/cv2.calcOpticalFlowPyrLK
ComfyUI Node

cv2.calcOpticalFlowPyrLK

Raw wrapper of cv2.calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, winSize?, maxLevel?, criteria?, flags?, minEigThreshold?). Parameters marked '?' are optional; blank means OpenCV default. See the OpenCV documentation for details.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
cv2.calcOpticalFlowPyrLK
  • prevImg
  • nextImg
  • prevPts
  • nextPts
  • winSize
  • nextPts
  • status
  • err
maxLevel3
criteria_typemax count or epsilon (whichever first)
criteria_max_count30
criteria_epsilon0.00
flagsnone (0)
minEigThreshold0.0001
Categoryimage/CV/low-level/cv2 C

Inputs (11)

NameTypeDefaultDescription
prevImgNPARRAY,IMAGE,MASKfirst 8-bit input image or pyramid constructed by buildOpticalFlowPyramid. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
nextImgNPARRAY,IMAGE,MASKsecond input image or pyramid of the same size and the same type as prevImg. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
prevPtsNPARRAYvector of 2D points for which the flow needs to be found; point coordinates must be single-precision floating-point numbers. A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here.
nextPtsNPARRAYoutput 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. A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here.
winSizeoptCV_TUPLE0,0size of the search window at each pyramid level. One value with 2 components (w, h) - it travels as a whole, so it cannot arrive half-connected. Wire it from 'CV Tuple' or type the components in place.
maxLeveloptINT3-2147483648–21474836470-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. Preset to the OpenCV default (3).
criteria_typeoptCOMBOmax count or epsilon (whichever first)When to stop iterating: after max_count iterations, when the change drops below epsilon, or whichever comes first.
criteria_max_countoptINT301–2147483647Maximum iterations (ignored when 'epsilon only').
criteria_epsilonoptFLOAT0.000–1e+38Target accuracy / smallest change worth continuing for (ignored when 'max count only').
flagsoptSTRINGnone (0)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. cv2.calcOpticalFlowPyrLK flags: one of none (0) plus any of OPTFLOW_USE_INITIAL_FLOW, OPTFLOW_LK_GET_MIN_EIGENVALS, pipe-joined (e.g. "none (0) | OPTFLOW_USE_INITIAL_FLOW"). In the UI this renders as a dropdown with one toggle per flag.
minEigThresholdoptFLOAT0.0001-1e+38–1e+38the algorithm calculates the minimum eigen value of a 2x2 normal matrix of optical flow equations (this matrix is called a spatial gradient matrix in ), 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 Preset to the OpenCV default (0.0001).

Outputs (3)

NameTypeDescription
nextPtsNPARRAY
statusNPARRAY
errNPARRAY