Nodes/opencv-comfyui/OpenCV calcOpticalFlowPyrLK_0
ComfyUI Node

OpenCV calcOpticalFlowPyrLK_0

Track feature points with PyrLK

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV calcOpticalFlowPyrLK_0
  • prevImg
  • nextImg
  • prevPts
  • nextPts
  • status
  • err
  • nparray_0
  • nparray_1
  • nparray_2
winSize
maxLevel
criteria
flags
minEigThreshold

Where Farneback gives you a motion vector for every pixel, OpenCV calcOpticalFlowPyrLK_0 tracks only the points you give it. You feed in two frames and a list of starting coordinates - detected corners, landmark points, anywhere you pointed - and it returns where each point moved, whether the track is trustworthy (status), and an error estimate. That's sparse optical flow, and it's the algorithm behind decades of object tracking, video stabilization, and feature matching. It's the Lucas–Kanade method with a pyramidal refinement, hence PyrLK.

If you're going to wire any optical-flow node in this pack, this one is actually the more practical of the two - its output is a set of points (plus status flags), which is data you can reason about, not a two-channel field you have to visualize. Still, the pack's auto-gen roughness is fully on display here.

Inputs that matter

  • prevImg / nextImg - the two NPARRAY frames. Grayscale uint8, required - OpenCV asserts CV_8UC1; convert with cvtColor (code=6). The README's troubleshooting entry is literally this error.
  • prevPts - NPARRAY, your starting points as an (N, 2) float32 array.
  • nextPts - NPARRAY, and the rough edge again: this is an out-parameter (the tracked points), surfaced as a required input. You must wire a slot that gets overwritten - feed a same-size array; the results come out on the first output.
  • winSize - STRING literal, (21, 21) (a Size). This is the search-window size per pyramid level.
  • maxLevel - INT, pyramid depth; 3 is the usual default.
  • criteria - STRING literal, a TermCriteria tuple (type, maxCount, epsilon): (3, 30, 0.01) is the classic "EPS + COUNT, 30 iterations, 0.01 precision."
  • flags - INT, 0 (or 1 = OPTFLOW_LK_GET_MIN_EIGENVALS, 2 = OPTFLOW_USE_INITIAL_FLOW).
  • minEigThreshold - FLOAT; points whose minimum eigenvalue falls below this are dropped from tracking, 1e-4 typical.
  • status / err (optional) - the other out-parameters; leave unwired, they come back as outputs.

Outputs: nparray_0 (tracked nextPts), nparray_1 (status, 1.0/0.0 per point), nparray_2 (error). None of these are images - Nparrays2Image will not thank you for them.

Install

ComfyUI Manager → opencv-comfyui, or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, restart. Needs opencv-contrib-python; batch size 1, NPARRAY conventions.

The honest framing: this is a genuine CV tool for people who already have a point set and a reason to track it. Beginners will find the required-out-parameter nextPts and the grayscale requirement a lot of ceremony before any visible payoff. If you're experimenting with motion tracking inside ComfyUI, though, this is the real primitive - and the _1 sibling next to it is the same node under a second overload number.

Categoryimage/OpenCV

Inputs (11)

NameTypeDefaultDescription
prevImgNPARRAY
nextImgNPARRAY
prevPtsNPARRAY
nextPtsNPARRAY
winSizeSTRING
maxLevelINT
criteriaSTRING
flagsINT
minEigThresholdFLOAT
statusoptNPARRAY
erroptNPARRAY

Outputs (3)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY
nparray_2NPARRAY