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

CV Stereo Disparity (BM)

Per-pixel disparity from a RECTIFIED stereo pair with the classic BLOCK MATCHER (cv2.StereoBM) - the fast, local cousin of 'CV Stereo Disparity (SGBM)'. It compares raw SAD windows scanline by scanline with no global smoothness term, so it runs several times faster but leaves far more holes in low-texture areas; that is what texture_threshold controls. Use it for a quick preview, a speed/quality comparison, or when the scene is richly textured. The pair MUST be rectified (epipolar lines horizontal). 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 (BM)
  • left
  • right
  • disparity
  • valid
  • valid_fraction
num_disparities64
block_size15
min_disparity0
texture_threshold10
uniqueness_ratio10
prefilterx-Sobel
prefilter_cap31
speckle_window_size100
speckle_range2
disp12_max_diff-1
Categoryimage/CV/features

Inputs (12)

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_sizeINT155–51SAD window size in pixels; forced ODD and clamped to 5..51 (StereoBM rejects anything else). Larger = smoother but blurs depth edges; 15-21 is typical.
min_disparityINT0-256–256Smallest disparity to search from (usually 0).
texture_thresholdINT100–163863Reject a block whose texture (summed x-gradient) is below this - the main reason BM leaves holes on flat walls. 0 accepts every block (noisy). It is a SUM over the whole SAD window, so it only bites in the thousands: the ceiling above which every pixel is rejected is block_size^2 * prefilter_cap (about 7000 at the defaults, 163863 at block_size 51 / prefilter_cap 63).
uniqueness_ratioINT100–100Margin (%) by which the best match must beat the runner-up to be accepted.
prefilteroptCOMBOx-SobelPre-filter applied before matching to remove lighting differences between the two cameras. x-Sobel (an x gradient, clipped to prefilter_cap) is what OpenCV itself defaults to and the usual choice. normalized response is the older local brightness normalisation kept from the legacy C API - it is more tolerant of a smooth exposure difference between the cameras but weaker on repetitive texture.
prefilter_capoptINT311–63Pre-filtered values are clipped to +/- this.
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–256Max allowed left-right consistency error in pixels (-1 = do not run the left-right check).

Outputs (3)

NameTypeDescription
disparityNPARRAYHxW float32 disparity in pixels; rejected pixels are below min_disparity (see 'valid').
validNPARRAYuint8 0/255 mask of pixels with a valid disparity - BM rejects many more than SGBM, so always check it.
valid_fractionFLOATFraction of pixels with a valid disparity (0..1) - the headline number when comparing BM against SGBM.