Nodes/ComfyUI CV/cv2.ximgproc.getDisparityVis
ComfyUI Node

cv2.ximgproc.getDisparityVis

Making a stereo disparity map actually viewable

By bmad4ever·Created 4 months ago·Updated 14 days ago· 1
cv2.ximgproc.getDisparityVis
  • src
  • nparray
◄scale1.0000►

The KB's depth doc is all learned monocular models - MiDaS, Depth Anything, MoGe - and it says the reason they took over is the absence of rigs: "no stereo camera rig, no lidar, no structured light." This node lives on the other side of that line. If you do have a stereo pair, cv2.StereoSGBM_create gives you real, metric-ish disparity instead of relative depth, and the raw output is a signed 16-bit integer map that previews as a black rectangle until you convert it. That conversion is what getDisparityVis is for. It's the pack's canonical disparity visualiser, one line of OpenCV.

How it works

Stereo matchers return disparity in fixed-point units (16× the real value, so fractional disparities survive as integers) plus a −1 marker where no match was found. getDisparityVis maps that to a displayable single-channel 8-bit image and multiplies by scale to set the brightness. Valid regions get brighter with distance-from-camera mapping; the invalid holes come out dark, which is why a good disparity preview looks like a speckled mess in the sky and on glass.

  • src - the disparity map from a matcher, CV_16S depth. In this pack that means the NPARRAY coming off a generated cv2.StereoBM / cv2.StereoSGBM wrapper, or a curated CV Stereo Disparity (BM)/(SGBM) node.
  • scale (1.0) - brightness multiplier applied during the conversion. Raise it when your disparities are small (a near-ortho pair) and the picture is uniformly dark; the useful range is empirical, not theoretical.

Output is a plain NPARRAY (it doesn't echo a socket type, so it never guesses). Wire it into CV Array → Image to preview, CV Array → Mask if you want the near/far split as a mask (float inputs get min-max normalized there), or CV Color Map to see it as a false-colour heatmap - much easier to read than greyscale when you're judging whether the matcher did anything.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv

Restart ComfyUI, or install ComfyUI CV via ComfyUI Manager. Python ≥3.12, a recent V3-API ComfyUI, opencv-contrib-python-headless~=5.0.0.93. Nothing to download. The node is contrib-only, so a non-contrib OpenCV wheel on the same site-packages/cv2 will hide it - tools/repair_opencv_contrib.py --check is the diagnostic (and --apply the fix).

Common issues

You fed it a depth map, not a disparity map. Depth Anything and friends emit float relative depth; that's a different animal. Passing a float map into this node doesn't error out politely, it produces a plausible-looking image with meaningless brightness. Disparity comes from a matcher.

Everything is black. Either scale is too low for your disparity range, or the matcher genuinely failed (block size too large for the texture, too little overlap between the views). Previewing the raw matcher output with Inspect CV Data tells you which - if its max is near 0, the problem is upstream.

The holes are huge. That's the display telling you the truth. SGBM finds nothing in textureless regions, and this node adds nothing. Refinement is a separate job: the pack's curated CV Disparity Filter (WLS) and CV Disparity Interpolate (Edge-Aware) nodes handle filling. The textbook hole-filler, ximgproc.fastBilateralSolverFilter, is exposed as a generated wrapper but raises (-213) needs to be compiled with EIGEN on stock wheels - the pack's README calls that out by name, so don't chase it.

No left-right consistency here. getDisparityVis is telemetry: it shows you what the matcher produced. It validates nothing, and its output should not be fed to a 3D consumer as if it were cleaned depth.

Categoryimage/CV/low-level/ximgproc

Inputs (2)

NameTypeDefaultDescription
srcNPARRAY,IMAGE,MASKinput disparity map (CV_16S depth) 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.
scaleoptFLOAT1.0000-1e+38–1e+38disparity map will be multiplied by this value for visualization Preset to the OpenCV default (1.0).

Outputs (1)

NameTypeDescription
nparrayNPARRAY—