ComfyUI Node
CV Optical Flow (TV-L1)
Dense optical flow by TV-L1 energy minimization (cv2.optflow.DualTVL1OpticalFlow) - the accuracy reference of the classic (non-learned) methods. Its L1 data term tolerates illumination change and occlusion far better than Farneback's least squares, and its total-variation prior keeps motion discontinuities SHARP instead of smearing them. The price is speed: expect seconds per megapixel, roughly an order of magnitude slower than 'CV Optical Flow (DIS)'. Use it for offline quality work and DIS for anything interactive. Connect 'init_flow' (the previous pair's flow) to warm-start a video sequence.
CV Optical Flow (TV-L1)
- frame_a
- frame_b
- init_flow
- flow
- magnitude
- angle
◄lambda_0.15►
◄scales5►
◄warps5►
◄epsilon0.010►
◄tau0.25►
◄theta0.30►
◄gamma0.00►
◄scale_step0.80►
◄inner_iterations30►
◄outer_iterations10►
◄median_filtering5►
Categoryimage/CV/contrib
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| frame_a | NPARRAY,IMAGE | First frame (earlier in time); converted to grayscale. 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. | |
| frame_b | NPARRAY,IMAGE | Second frame; resized to frame_a if the sizes differ. 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. | |
| lambda_ | FLOAT | 0.150.001–2 | Weight of the data term against the smoothness term. LOWER = smoother flow (the prior wins); higher follows the pixels and picks up noise. |
| scales | INT | 51–10 | Pyramid levels. More levels capture larger motion; each costs time. |
| warps | INT | 51–20 | Warping steps per pyramid level - the outer linearization loop. More is more accurate and linearly slower; this is the main speed knob. |
| epsilon | FLOAT | 0.0100.0001–1 | Stopping threshold. Tighter (smaller) is more accurate and much slower. |
| init_flowopt | NPARRAY | Optional HxWx2 float32 flow to start from - pass the previous frame pair's flow when processing video. It is copied, never written to, so the upstream node's cached array stays safe. | |
| tauopt | FLOAT | 0.250.01–1 | Time step of the dual formulation. The theory needs tau < 0.125 for guaranteed convergence; cv2 ships 0.25 because it works in practice. |
| thetaopt | FLOAT | 0.300.01–2 | Tightness of the coupling between the two variables the dual scheme splits the problem into. Small values slow convergence. |
| gammaopt | FLOAT | 0.000–1 | Weight of the gradient-constancy term. Above 0 it adds robustness to brightness changes at some cost; cv2's default is 0 (off). |
| scale_stepopt | FLOAT | 0.800.1–0.95 | Size ratio between consecutive pyramid levels. |
| inner_iterationsopt | INT | 301–200 | Inner iterations used to solve the linearized problem at each warp. |
| outer_iterationsopt | INT | 101–100 | Outer iterations of the whole scheme. |
| median_filteringopt | INT | 51–9 | Aperture of the median filter applied between iterations to reject outliers. 1 disables it. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| flow | NPARRAY | HxWx2 float32 (dx, dy) displacement per pixel. |
| magnitude | NPARRAY | HxW float32 motion magnitude in pixels. |
| angle | NPARRAY | HxW float32 motion direction in RADIANS - feed 'CV Flow To Color' in its default radians mode. |