Skip to content
PPHYSICAL AI GUIDESTART HERE →

Field guide

Stereo Depth Error: Budget Disparity at Working Distance

Calculate how stereo disparity affects depth at your working distance. Run exact error intervals, catch fixed-point mistakes, and separate resolution from accuracy.

By Physical AI Guide Editorial TeamPublished Updated

The short answer

Budget stereo depth at the actual working distance, using focal length in pixels, baseline in known length units and the disparity representation delivered by your pipeline. A fine disparity increment is not an accuracy guarantee. Ask separately how often correspondence fails and how far retained depths are from an independent reference.

For an illustrative rectified stereo pair with an 800-pixel focal length and an 80-millimeter baseline, a point at two meters has 32 pixels of corrected disparity. A hypothetical disparity error bounded by plus or minus 0.5 pixel maps to depths from 1.9692 to 2.0317 meters. That exceeds a hypothetical 20-millimeter depth-error allowance, even though a 1/16-pixel disparity increment corresponds to only about 3.91 millimeters of local depth resolution there.

The distinction is useful when reviewing a picking or navigation camera proposal: resolution, correspondence error and application accuracy are different quantities. We executed the offline calculation below. We did not capture stereo images, run a matcher or test a camera or robot. All numerical camera settings and error allowances are invented examples, not measured device specifications.

Establish the disparity and geometry contract

For the rectified horizontal stereo geometry used here:

Z = f_px * B / d_px

Z is depth along the rectified camera’s forward axis, not the straight-line distance to every off-axis point. f_px is the horizontal focal length of the rectified image in pixels. B is baseline, and Z has the same length unit as B. d_px is disparity after the appropriate principal-point correction.

The ROS 2 DisparityImage definition explicitly gives Z = fT/d. It defines f in pixels, baseline t in world units, and its floating-point image as already adjusted:

d = x_left - x_right - (cx_left - cx_right)

Do not subtract that principal-point difference again from a compliant DisparityImage. Conversely, a raw horizontal coordinate difference is not automatically this adjusted disparity. For the illustrative geometry, a raw difference of 34 pixels and principal-point difference of two pixels gives d = 32, hence Z = 2 meters. Applying the correction twice gives 30 pixels and the wrong depth.

The CameraInfo definition distinguishes raw intrinsics K from the rectified projection matrix P. Their focal lengths and principal points can differ. For a horizontal stereo pair it gives the right camera’s projection translation as Tx = -fx' * B. That matrix entry is not itself a baseline in meters: recovering baseline requires the matching focal length and convention.

Before calculating, retain the producer, rectification settings, image dimensions, projection matrices, baseline units, principal-point convention and invalid-value rules. Use geometry corresponding to the actual processed image. Mixing a resized disparity map with an unchanged pixel focal length is not a valid depth calculation. The camera-sizing guide addresses the separate question of feature samples and exposure.

Check fixed-point scaling before interpreting depth

The OpenCV 4.13.0 API documents four fractional bits for the signed fixed-point disparity output of StereoBM and StereoSGBM. Its reprojectImageTo3D instructions say to divide that output by 16 and convert it to floating point before reprojection.

That rule is specific to that representation, not every disparity image. Our 32-pixel example would be stored as 512 in that format. Treating 512 as pixels would produce 0.125 meter instead of two meters. Dividing an already converted floating-point image again introduces the opposite scaling error. Record conversions at component boundaries rather than guessing from a topic name or how a colorized image looks.

Separate depth resolution from depth error

The same ROS message definition defines delta_d as the smallest allowed disparity increment and gives:

local_depth_increment = Z**2 / (f_px * B) * delta_d

This is a local sensitivity relationship. It does not state that every match is within delta_d of the correct disparity. In particular, do not silently turn an increment into a standard deviation, maximum error or confidence interval.

Our example contrasts that increment with a separately assumed plus or minus 0.5-pixel error bound. We have no measured evidence that any camera or matcher meets that bound. Holding baseline and focal length exact and ignoring all other error sources, the exact interval is:

K = f_px * B
nominal_depth = K / d
near_depth = K / (d + error_px)
far_depth = K / (d - error_px)

This requires positive K and d > error_px >= 0. The far-side error is larger than the near-side error because depth is reciprocal in disparity. If the interval reaches zero disparity, there is no finite far-depth bound under this model. Reject that case rather than printing a reassuring linear approximation.

Nominal depth Corrected disparity Local increment for 1/16 pixel Exact far-side error for 0.5 pixel
1 m 64 px 0.98 mm 7.87 mm
2 m 32 px 3.91 mm 31.75 mm
4 m 16 px 15.625 mm 129.03 mm

These are calculated values for the stated hypothetical geometry, not a camera comparison. Increasing range from one to two meters multiplies the local sensitivity by four. The exact finite-error change is not perfectly quadratic, which is why the calculator retains both interval endpoints.

More search range does not establish more accurate range

The ROS message also carries a disparity search range and a potentially valid image window. It relates disparity limits to depth limits through the same reciprocal geometry. Searching for smaller disparities can make more distant points geometrically eligible; it does not establish reliable correspondence there.

The OpenCV stereo-depth tutorial discusses noisy disparity, texture filtering, ambiguity filtering and speckles at object boundaries. A nominal range calculation cannot settle those matching problems. Preserve rejected or missing depths instead of evaluating only a favorable subset of valid pixels.

Run the exact depth-budget calculation

This standard-library Python 3 example checks finite values, an unbounded interval and the fixed-point scaling mistake. The error_px input is a hypothetical deterministic bound, not an estimated distribution. The calculation isolates disparity effects with exact baseline and focal length; it is not a complete uncertainty model.

from math import isfinite, isclose


def depth_interval(f_px, baseline_m, disparity_px, error_px):
    values = (f_px, baseline_m, disparity_px, error_px)
    if not all(isfinite(v) for v in values):
        raise ValueError("inputs must be finite")
    if f_px <= 0 or baseline_m <= 0 or error_px < 0:
        raise ValueError("invalid geometry or error bound")
    if disparity_px <= error_px:
        raise ValueError("no finite positive far-depth bound")
    k = f_px * baseline_m
    return (k / disparity_px,
            k / (disparity_px + error_px),
            k / (disparity_px - error_px))


f_px, baseline_m = 800.0, 0.080
error_px, increment_px = 0.5, 1 / 16  # Independent illustrative inputs.
allowance_m = 0.020                 # Chosen example, not a standard.
k = f_px * baseline_m

for depth_m in (1.0, 2.0, 4.0):
    d = k / depth_m
    nominal, near, far = depth_interval(f_px, baseline_m, d, error_px)
    local_step_m = depth_m**2 / k * increment_px
    fits = max(nominal - near, far - nominal) <= allowance_m
    print(f"Z={nominal:.1f} m, d={d:.1f} px: "
          f"[{near:.4f}, {far:.4f}] m; "
          f"step={local_step_m * 1000:.2f} mm; "
          f"within chosen 20 mm={fits}")

raw_fixed_point = 512
converted_px = raw_fixed_point / 16
correct = depth_interval(f_px, baseline_m, converted_px, 0)[0]
wrong = depth_interval(f_px, baseline_m, raw_fixed_point, 0)[0]
assert isclose(correct, 2.0) and isclose(wrong, 0.125)
print(f"Scaling check: converted={correct:.3f} m, unconverted={wrong:.3f} m")

try:
    depth_interval(f_px, baseline_m, 0.5, error_px)
except ValueError as exc:
    print(f"Rejected: {exc}")
else:
    raise AssertionError("zero-crossing interval was accepted")

Output from executing this exact example:

Z=1.0 m, d=64.0 px: [0.9922, 1.0079] m; step=0.98 mm; within chosen 20 mm=True
Z=2.0 m, d=32.0 px: [1.9692, 2.0317] m; step=3.91 mm; within chosen 20 mm=False
Z=4.0 m, d=16.0 px: [3.8788, 4.1290] m; step=15.62 mm; within chosen 20 mm=False
Scaling check: converted=2.000 m, unconverted=0.125 m
Rejected: no finite positive far-depth bound

True means only that this hypothetical disparity-only interval fits the chosen allowance. It does not mean a real system passes. Baseline and calibration uncertainty, incorrect correspondence, observation timing, mounting transforms and physical task error are outside the calculation.

A depth-evidence handoff worksheet

This is our proposed review record, not a certification checklist. Agree limits before collecting acceptance data. Keep unperformed checks marked NOT TESTED.

Review item Evidence to retain
Required decision Depth-axis tolerance, working distances, relevant object sizes and workspace locations
Geometry and representation Rectified focal length, baseline units, principal-point adjustment, encoding and conversions
Error assumptions Disparity increment separately from measured error or an explicitly assumed bound
Matching coverage Total relevant observations, valid and rejected counts, spatial gaps and invalid-value handling
Independent depth check Reference provenance, distances, per-observation signed errors and predeclared limits
Challenging conditions Relevant materials, textures, boundaries, illumination and motion, with failures retained
Timing and coordinates Acquisition pairing, clock domains, depth frame and robot mounting-transform revision
Change ownership Who approves calibration, processing and mounting changes, and repeats affected checks

For an independent depth check, compare the same quantity on both sides: camera-axis depth is not interchangeable with radial range or a robot-base coordinate. Retain reference uncertainty and alignment details. A number of decimal places in a point cloud does not establish physical accuracy.

For moving scenes, stereo geometry does not establish that left and right observations represent the same instant. Use the sensor-timing guide to review observation pairing separately. For robot-coordinate use, the hand-eye calibration guide separates mounting-transform consistency from independent task accuracy. Neither can be replaced by a fine disparity step.

The useful purchasing question is therefore not just how far the camera reports depth. It is whether the retained observations support the required decision at the intended distances, with known conventions, visible failure coverage and an independently checked application result.

Sources and limits

  1. ROS 2 DisparityImage source, Rolling revision pinned at review on November 27, 2026. Defines adjusted floating-point disparity, focal length and baseline units, depth geometry, search limits, valid window and disparity increment. It does not supply the example’s 0.5-pixel error bound.
  2. ROS 2 CameraInfo source, same pinned revision. Defines raw and rectified camera matrices, the optical frame and the horizontal stereo projection translation convention.
  3. OpenCV 4.13.0 calib3d API, release-tagged source reviewed November 27, 2026. Defines fixed-point stereo output and conversion before reprojectImageTo3D. We did not execute those OpenCV functions.
  4. OpenCV 4.13.0 stereo-depth tutorial, reviewed November 27, 2026. Explains reciprocal stereo geometry and matching/filtering limitations. The release-tagged pages do not state a separate document publication date.

The exact interval derivation, numerical example, negative control and handoff worksheet are Physical AI Guide’s analysis. We verified the software arithmetic only. No hardware accuracy, sensor ranking, safety function or successful robot deployment is claimed.

Frequently asked questions

Does subpixel disparity resolution guarantee stereo depth accuracy?

No. The smallest disparity increment describes representation or resolution, not a bound on matching error, calibration error or physical task error. Validate depth against an independent reference and retain invalid measurements as well as valid ones.

Why does stereo depth become more sensitive to disparity error at longer distances?

For fixed focal length and baseline, depth is inversely proportional to corrected disparity. Its local sensitivity to disparity is proportional to depth squared. Exact error intervals become asymmetric and must not cross zero disparity.

Should ROS 2 DisparityImage values be divided by 16?

Not as a general rule. DisparityImage specifies floating-point, principal-point-adjusted disparities. OpenCV documents a factor of 16 for the signed fixed-point output of StereoBM and StereoSGBM. Inspect the producer and representation before converting.