Nodes/comfyui_cv/CV Optical Flow (RLOF, Dense)
ComfyUI Node

CV Optical Flow (RLOF, Dense)

Dense optical flow by Robust Local Optical Flow (cv2.optflow.calcOpticalFlowDenseRLOF): it tracks a GRID of points with an illumination-robust local solver, then interpolates them into a dense field with the same edge-aware interpolators as 'CV Disparity Interpolate'. That makes it the quality/speed middle ground between DIS and TV-L1, and the best of the three when the two frames differ in EXPOSURE, because the illumination model is part of the per-point solve. Unlike every other flow node here it needs COLOUR: the cross-based support region segments on colour, so a grayscale input is expanded to BGR and the method loses its main advantage. Raise 'grid_step' for speed, lower it for detail.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Optical Flow (RLOF, Dense)
  • frame_a
  • frame_b
  • flow
  • magnitude
  • angle
grid_step6
interpolationEPIC (edge-preserving, default)
forward_backward_threshold1.0
use_variational_refinementfalse
use_post_proctrue
epic_k128
epic_sigma0.050
epic_lambda999
ric_superpixel_size15
ric_slic_typeSLIC
fgs_lambda500
fgs_sigma1.5
solver_typebilinear (accurate, default)
support_regioncross-based segmentation (default)
small_win_size9
large_win_size21
max_level4
max_iterations30
use_m_estimatorfalse
use_illumination_modeltrue
use_global_motion_priortrue
cross_segmentation_threshold25
min_eigen_value0.0001
global_motion_ransac_threshold10.0
Categoryimage/CV/contrib

Inputs (26)

NameTypeDefaultDescription
frame_aNPARRAY,IMAGEFirst frame. Kept in COLOUR (8-bit BGR) - RLOF uses the colour to grow its support regions. 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, same size as frame_a. 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.
grid_stepINT61–64Spacing in pixels of the point grid that is actually tracked; everything between is interpolated. The dominant speed/detail knob (cv2 default 6).
interpolationCOMBOEPIC (edge-preserving, default)How the tracked grid becomes a dense field. EPIC fits a local affine model along image edges, RIC fits one plane per SLIC superpixel (sharpest at motion boundaries, slowest, and it RANDOMIZES its model fitting so its output varies slightly run to run), GEO is a plain geodesic weighting and is the fastest.
forward_backward_thresholdFLOAT1.00–30Drop a grid point when re-tracking it back misses its origin by more than this many pixels. 0 disables the check and keeps every point, including the ones that ran into an occlusion.
use_variational_refinementBOOLEANfalseRun a variational polish over the interpolated field (the same refinement DIS ends with). Sharpens boundaries at a noticeable cost; cv2's default is off.
use_post_procoptBOOLEANtrueRun the fast global smoother after interpolation. Recommended - without it the per-region models stay visible as blocky steps.
epic_koptINT1281–512EPIC/GEO: neighbouring tracked points used to fit each local model. Larger = smoother, slower.
epic_sigmaoptFLOAT0.0500.001–1EPIC/GEO: falloff of the geodesic distance weighting.
epic_lambdaoptFLOAT9990–5000EPIC/GEO: regularization of the local affine fit.
ric_superpixel_sizeoptINT154–64RIC only: average SLIC superpixel side in pixels. Smaller follows finer structure at more cost.
ric_slic_typeoptCOMBOSLICRIC only: superpixel algorithm. SLIC is the baseline, SLICO adapts its compactness automatically, MSLIC is the manifold variant.
fgs_lambdaoptFLOAT5001–10000Post-processing smoother strength (ignored when use_post_proc is off).
fgs_sigmaoptFLOAT1.50.01–100Post-processing edge sensitivity in colour units (ignored when use_post_proc is off).
solver_typeoptCOMBObilinear (accurate, default)Iteration scheme. 'bilinear' interpolates sub-pixel and is more accurate; 'standard' samples on the pixel grid and is faster.
support_regionoptCOMBOcross-based segmentation (default)Shape of the region matched around each point. 'cross-based' grows the window along colour-similar pixels, which is what keeps RLOF sharp at motion boundaries; 'fixed window' is the classic square block.
small_win_sizeoptINT93–51Window used at the finest level / inside a support region.
large_win_sizeoptINT213–101Largest matching window; bigger tolerates bigger motion and blurs fine detail.
max_leveloptINT40–8Pyramid levels (0 = no pyramid). More levels track larger displacements.
max_iterationsoptINT301–200Iterations per level before giving up on a point.
use_m_estimatoroptBOOLEANfalseUse the robust Lorentzian norm instead of plain L2. cv2's own default is OFF (the parameter object ships with the norm sigmas at FLT_MAX). Turning it on costs time and helps when the two frames contain outlier motion.
use_illumination_modeloptBOOLEANtrueSolve for a per-region brightness/contrast change as well as the motion - the 'robust' in RLOF. Turn it off only if the exposure is provably constant and you need the speed.
use_global_motion_prioroptBOOLEANtrueEstimate a global (camera) motion first and start every point from it. Helps a panning camera, hurts nothing much.
cross_segmentation_thresholdoptINT250–255Colour difference at which the cross-based support region stops growing (ignored for a fixed window).
min_eigen_valueoptFLOAT0.00010–1Points whose structure tensor is flatter than this are declared untrackable.
global_motion_ransac_thresholdoptFLOAT10.00–100RANSAC inlier threshold used when fitting the global motion prior (ignored when that prior is off).

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.