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

CV Optical Flow (Farneback)

Dense optical flow between two frames (cv2.calcOpticalFlowFarneback): the per-pixel motion from frame_a to frame_b. The raw cv2 wrapper is unusable here - its 'flow' in/out array is a required input and the numeric parameters have no sensible defaults - so this node passes flow=None and presets the Farneback parameters. Both frames are converted to grayscale and frame_b is resized to frame_a if their sizes differ. Outputs the raw HxWx2 flow plus ready-to-visualise magnitude and angle (RADIANS): feed angle + magnitude straight into 'CV Flow To Color' (its default radians mode), or the flow field into two cv2.extractChannel nodes for dx/dy.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Optical Flow (Farneback)
  • frame_a
  • frame_b
  • flow
  • magnitude
  • angle
pyr_scale0.50
levels3
winsize15
iterations3
poly_n5
poly_sigma1.2
windowbox (faster)
Categoryimage/CV/features

Inputs (9)

NameTypeDefaultDescription
frame_aNPARRAY,IMAGEFirst frame (earlier in time); any colour space, 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.
pyr_scaleFLOAT0.500.1–0.9Pyramid scale between levels (<1); 0.5 halves the resolution at each level.
levelsINT31–10Number of pyramid levels (1 = no pyramid).
winsizeINT153–101Averaging window size; larger = more robust to noise but blurrier flow.
iterationsINT31–20Iterations at each pyramid level.
poly_nINT53–11Neighborhood size for the polynomial expansion (5 or 7 are typical).
poly_sigmaFLOAT1.20.3–3Gaussian sigma of the polynomial expansion (~1.1 for poly_n=5, ~1.5 for poly_n=7).
windowCOMBObox (faster)Averaging window type; gaussian is slower but yields smoother flow.

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.