Nodes/comfyui_cv/CV Optical Flow (DIS)
ComfyUI Node

CV Optical Flow (DIS)

Dense Inverse Search optical flow (cv2.DISOpticalFlow) - the modern replacement for 'CV Optical Flow (Farneback)'. It matches small patches coarse-to-fine, propagates the winners to their neighbours and then runs a variational refinement, which gives noticeably sharper motion boundaries AND runs faster than Farneback at comparable quality. DISOpticalFlow is a cv2 class the raw wrappers cannot expose. Start from a preset, then override individual parameters if needed. Connect 'init_flow' (e.g. the previous frame pair's flow) to warm-start a video sequence - large motions converge far better that way.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Optical Flow (DIS)
  • frame_a
  • frame_b
  • init_flow
  • flow
  • magnitude
  • angle
presetmedium (most accurate)
finest_scale-1
gradient_iterations-1
refinement_iterations-1
patch_size-1
patch_stride-1
spatial_propagationtrue
mean_normalizationtrue
Categoryimage/CV/features

Inputs (11)

NameTypeDefaultDescription
frame_aNPARRAY,IMAGEFirst 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_bNPARRAY,IMAGESecond 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.
presetCOMBOmedium (most accurate)Speed/quality preset; it presets finest_scale, patch size/stride and the iteration counts. 'ultrafast' is real-time-video fast, 'medium' is the best quality.
finest_scaleINT-1-1–6Finest pyramid level actually computed. -1 keeps the preset's value. 0 = full resolution (sharpest and slowest); raising it blurs and speeds up.
gradient_iterationsINT-1-1–100Gradient-descent iterations per patch. -1 keeps the preset's value; more = more accurate, slower.
refinement_iterationsINT-1-1–100Variational refinement iterations run after the patch search. -1 keeps the preset's value; 0 turns the refinement off entirely (rawer, blockier flow).
init_flowoptNPARRAYOptional HxWx2 flow to start from - pass the previous frame pair's flow when processing a video. It is copied, never written to, so the upstream node's cached array is safe.
patch_sizeoptINT-1-1–64Side of the matched patch in pixels. -1 keeps the preset's value (8 is the usual).
patch_strideoptINT-1-1–32Spacing between patches. -1 keeps the preset's value; smaller = denser and slower.
spatial_propagationoptBOOLEANtrueSeed each patch from its already-solved neighbour. Almost always worth it - the main reason DIS beats a plain patch search.
mean_normalizationoptBOOLEANtrueNormalise patch means before matching, which makes the match robust to brightness changes between frames.

Outputs (3)

NameTypeDescription
flowNPARRAYHxWx2 float32 (dx, dy) displacement per pixel.
magnitudeNPARRAYHxW float32 motion magnitude in pixels.
angleNPARRAYHxW float32 motion direction in RADIANS - feed 'CV Flow To Color' in its default radians mode.