Nodes/comfyui_cv/CV Stereo Disparity (SGBM)
ComfyUI Node

CV Stereo Disparity (SGBM)

Per-pixel disparity from a RECTIFIED stereo pair (cv2.StereoSGBM): how far each point shifts between the left and right view - inversely proportional to depth. StereoSGBM is a cv2 class the raw wrappers cannot expose, so this node manages it: both frames are grayscaled, the P1/P2 smoothness terms are derived from block_size (OpenCV's documented heuristic) and the int16 result is converted to float disparity in pixels. The pair MUST be rectified (epipolar lines horizontal) - run cv2.stereoRectify + initUndistortRectifyMap + cv2.remap first. Preview the disparity with 'Preview CV Array' (normalize / heatmap); larger disparity = closer.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Stereo Disparity (SGBM)
  • left
  • right
  • disparity
  • valid
num_disparities64
block_size7
min_disparity0
modeSGBM (balanced)
uniqueness_ratio10
speckle_window_size100
speckle_range2
disp12_max_diff-1
Categoryimage/CV/features

Inputs (10)

NameTypeDefaultDescription
leftNPARRAY,IMAGELeft rectified frame (grayscaled internally). 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.
rightNPARRAY,IMAGERight rectified frame; resized to left if 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.
num_disparitiesINT6416–512Disparity search range (0..num_disparities), rounded up to a multiple of 16. Larger covers nearer objects / wider baselines but is slower.
block_sizeINT71–21Matched block size in pixels (forced odd; 3-11 is typical). Smaller = more detail but noisier.
min_disparityINT0-256–256Smallest disparity to search from (usually 0).
modeCOMBOSGBM (balanced)SGBM is the standard; 3-way is faster at lower quality; HH runs the full-scale two-pass (best, slowest).
uniqueness_ratiooptINT100–100Margin (%) by which the best match must beat the runner-up to be accepted.
speckle_window_sizeoptINT1000–1000Largest smooth disparity blob treated as speckle noise and invalidated (0 = off).
speckle_rangeoptINT20–64Max disparity variation within a speckle component.
disp12_max_diffoptINT-1-1–64Left-right consistency check, in pixels: a match whose reverse match disagrees by more than this is invalidated. -1 (cv2's default) turns it off and leaves occlusion junk in the map; 1 is the usual setting when the disparity is about to be interpolated or turned into 3D points.

Outputs (2)

NameTypeDescription
disparityNPARRAYHxW float32 disparity in pixels; invalid pixels are below min_disparity (see 'valid').
validNPARRAYuint8 0/255 mask of pixels with a valid disparity.