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.
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)
| Name | Type | Default | Description |
|---|---|---|---|
| frame_a | NPARRAY,IMAGE | First 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_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. | |
| pyr_scale | FLOAT | 0.500.1–0.9 | Pyramid scale between levels (<1); 0.5 halves the resolution at each level. |
| levels | INT | 31–10 | Number of pyramid levels (1 = no pyramid). |
| winsize | INT | 153–101 | Averaging window size; larger = more robust to noise but blurrier flow. |
| iterations | INT | 31–20 | Iterations at each pyramid level. |
| poly_n | INT | 53–11 | Neighborhood size for the polynomial expansion (5 or 7 are typical). |
| poly_sigma | FLOAT | 1.20.3–3 | Gaussian sigma of the polynomial expansion (~1.1 for poly_n=5, ~1.5 for poly_n=7). |
| window | COMBO | box (faster) | Averaging window type; gaussian is slower but yields smoother flow. |
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. |