Nodes/opencv-comfyui/OpenCV validateDisparity_0
ComfyUI Node

OpenCV validateDisparity_0

The quality gate for stereo depth maps

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV validateDisparity_0
  • disparity
  • cost
  • nparray
minDisparity
numberOfDisparities
disp12MaxDisp

If you're doing real stereo depth in ComfyUI - two photos of the same scene, matched pixel by pixel to build a disparity map - validateDisparity is the cleanup step that keeps your depth output honest. It takes a raw disparity map plus its matching cost volume and scrubs out the pixels where the stereo matcher was guessing, replacing them with the most conservative value. Think of it as the "are you sure about this one?" pass after a stereo algorithm hands you a map full of confident-looking lies.

How it works

Stereo matching (StereoSGBM-style block matching) produces two things: a disparity map (how far each pixel shifted between the left and right views) and a cost volume (how well each shift matched, per pixel). validateDisparity uses that cost data to run a left-right consistency check: for each pixel it asks whether the disparity is plausible in both directions, using disp12MaxDisp as the tolerance for how much disagreement it'll accept. Bad pixels - occluded areas, textureless regions, mismatches - get their disparity reset to minDisparity, the bottom of the valid range, so downstream 3D reconstruction doesn't try to build depth from garbage. The result is a cleaner disparity map with the errors marked, not removed silently.

Inputs and outputs

  • disparity - the raw disparity map as an NPARRAY.
  • cost - the cost volume from the matcher, same NPARRAY type.
  • minDisparity and numberOfDisparities - the exact values you passed when the stereo matcher was created. They have to match, or the validation math is off.
  • disp12MaxDisp - the maximum allowed difference for the left-right check; larger tolerates more error, smaller is stricter.

Output is a single nparray - the validated disparity map, ready to feed into something like the pack's reprojectImageTo3D_0 if you're building point clouds.

The honest catch

This pack doesn't ship StereoBM or StereoSGBM. Those are OpenCV classes, and the author's generator only wrapped top-level standalone functions - classes were explicitly skipped. So the pack gives you the validator but not the matcher that produces disparity and cost in the first place. You'd have to feed it from a custom script node, another pack, or by loading precomputed maps. That makes validateDisparity_0 a node for people who are already deep in stereo land, not a beginner's on-ramp. If you just want depth from a single image, you don't want any of this - you want a depth-estimation model, which is a whole different pipeline.

Installing

Standard for the pack: ComfyUI Manager, search "opencv-comfyui", install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Dependencies: opencv-contrib-python, numpy, torch (from requirements.txt). Watch the known conflict error Cannot import name 'guidedFilter' from 'cv2.ximgproc' - that's a sign of competing OpenCV installs and wants a clean pip install opencv-contrib-python.

If you're here, you already know

The audience for this node is small: you have a stereo pair, a matcher from somewhere, and a disparity map that needs cleaning before it becomes geometry. If that's you, wire validateDisparity_0 between the matcher and reprojectImageTo3D_0 and keep minDisparity/numberOfDisparities consistent. If that's not you, file this one under "the pack is huge and some of it is for a different project entirely."

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
disparityNPARRAY
costNPARRAY
minDisparityINT
numberOfDisparitiesINT
disp12MaxDispINT

Outputs (1)

NameTypeDescription
nparrayNPARRAY