OpenCV calcOpticalFlowPyrLK_0
Track feature points with PyrLK
- prevImg
- nextImg
- prevPts
- nextPts
- status
- err
- nparray_0
- nparray_1
- nparray_2
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
NPARRAYframes. Grayscaleuint8, required - OpenCV assertsCV_8UC1; convert withcvtColor(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)(aSize). This is the search-window size per pyramid level. - maxLevel - INT, pyramid depth;
3is the usual default. - criteria - STRING literal, a
TermCriteriatuple(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-4typical. - 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.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| prevImg | NPARRAY | — | |
| nextImg | NPARRAY | — | |
| prevPts | NPARRAY | — | |
| nextPts | NPARRAY | — | |
| winSize | STRING | — | |
| maxLevel | INT | — | |
| criteria | STRING | — | |
| flags | INT | — | |
| minEigThreshold | FLOAT | — | |
| statusopt | NPARRAY | — | |
| erropt | NPARRAY | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| nparray_0 | NPARRAY | — |
| nparray_1 | NPARRAY | — |
| nparray_2 | NPARRAY | — |