Nodes/ComfyUI Optical Flow/Visualize optical flow
ComfyUI Node

Visualize optical flow

The debug view that shows whether your flow is sane or garbage

By seanlynch·Created 3 years ago·Updated 2 years ago· 34
Visualize optical flow
  • image
  • flow
  • IMAGE

Optical flow is invisible. A displacement map is just two channels of numbers that mean nothing when you stare at them in a list, and if you feed a bad one into Apply optical flow you'll only find out 50 frames into a render that everything's smeared. This node is the cheap insurance against that: it takes your flow plus an image and draws the motion as arrows on top of it, so you can look at what the flow thinks is happening before you trust it.

The README is upfront that it's a diagnostic: "It's up to you whether you use the 'prev', 'current', or an image you intend to apply the flow to." All that matters is the image is the same size as the frames the flow was computed from. Use prev if you want to see motion as it leaves the earlier frame; use current if you want to see where it arrived; use your generated frame if you want to sanity-check what the warp will do to it.

How it works

The node renders two layers. First, it converts your image to grayscale - that's your background, and it means you won't get your original colors back, so don't treat this as an enhancement node. Then it converts the flow into a color field: hue encodes direction (the angle of each arrow), brightness encodes magnitude (how far the pixel moved), via OpenCV's cartToPolar and an HSV-to-BGR conversion. On top of that it draws an arrow every 8 pixels along the grid, each arrow colored by the direction it points.

So you get both readings at once: the arrows tell you where things are moving and roughly how far, the color wash tells you the same thing at full resolution. It's a genuinely readable visualization, straight out of the classic optical-flow playbook.

Inputs and outputs

  • image - an IMAGE, same dimensions as the frames used to compute the flow.
  • flow - the OPTICAL_FLOW output from Compute optical flow.

The output is a single IMAGE. Pipe it into a PreviewImage or Save Image node - there's nothing to tune, so this is the whole node.

What to look for

A healthy flow is a coherent field: arrows pointing consistently in the direction the camera or subject actually moved, smooth transitions where motion is smooth. What you're hunting for:

  • Chaotic, needle-in-a-beehive arrows - either your prev/current frames don't belong together (wrong pair, wrong order) or the scene changed so much between frames that dense flow has nothing to lock onto.
  • Arrows pointing the wrong way - you flipped prev/current in Compute. The flow will happily compute either direction; it can't know which was first.
  • Wildly long arrows - the motion between frames is too big for the method to track cleanly. Smaller steps between frames fix this.

If the arrows look right, the flow is probably good, and you can wire it into Apply optical flow with some confidence. If they look wrong, you just saved yourself an afternoon of wondering why your video is melting.

Installing it

It's part of the seanlynch/comfyui-optical-flow pack, so install once and you get all three nodes. ComfyUI Manager: search ComfyUI Optical Flow, install, restart. Manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/seanlynch/comfyui-optical-flow

No models, no extra dependencies - it runs on the OpenCV and NumPy that ship with ComfyUI. The whole pack is small, CPU-only, and dependency-light, which makes this little debug node a lot easier to recommend than the average custom node.

CategoryOptical flow

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
flowOPTICAL_FLOW

Outputs (1)

NameTypeDescription
IMAGEIMAGE