Skip to content

Fix DisparityConverter: the baseline was divided by 100 twice - #806

Merged
asahtik merged 3 commits into
luxonis:developfrom
jmguerreroh:fix/disparity-baseline-develop
Nov 18, 2026
Merged

asahtik merged 3 commits into
luxonis:developfrom
jmguerreroh:fix/disparity-baseline-develop

Conversation

@jmguerreroh

Copy link
Copy Markdown
Contributor

The constructor takes the baseline in centimeters and already converts it to meters, but toRosMsg divided it by 100 again when filling DisparityImage.t. For a 7.5 cm baseline t was published as 0.00075 m instead of 0.075 m, so any depth reconstructed from the message was 100 times too small.

Publish the baseline as it is stored (meters), document the units of the constructor arguments and fix the unit test, which expected the wrong value (0.01 for a 100 cm baseline instead of 1.0).

Summary

DisparityConverter publishes stereo_msgs/DisparityImage.t (the baseline, in meters) 100 times too small. The constructor takes the baseline in centimeters and already converts it to meters (_baseline(baseline / 100.0)). toRosMsg then divides by 100 again (outDispImageMsg.t = _baseline / 100.0). With a 7.5 cm baseline, t is published as 0.00075 m instead of 0.075 m. Any depth reconstructed from the message (depth = f * t / disparity) is therefore 100 times too small. min_disparity and max_disparity use _baseline in meters and are not affected.

The fix is outDispImageMsg.t = _baseline;. The header now also documents the units (cm) of the constructor arguments.

The same two lines exist in every branch that has this converter (foxy, galactic, humble, iron, jazzy, kilted, develop). I'm opening the PRs for jazzy and develop first so the approach can be agreed. I can open the same PR for humble and kilted afterwards.

Related issues

Not part of this PR (it would be a separate issue): the converter divides the 16-bit disparity by 32 (5 fractional bits), but DepthAI uses 3 subpixel fractional bits by default.

Compatibility and configuration

No new topics, parameters or launch options. The value of DisparityImage.t changes to the documented meaning (meters). Consumers that compensated for the wrong value must remove that compensation.

Testing

  • ROS distribution and OS: ROS 2 Jazzy, Ubuntu 24.04
  • DepthAI library version: 2.31.1
  • Camera model and connection: OAK-D Lite, USB 3
  • Test commands or launch configuration: built depthai_bridge from this branch and ran a small program that converts a synthetic frame with DisparityConverter("frame", 458.7, 7.5, 20, 2000). I also ran a real OAK-D Lite publishing stereo/disparity next to stereo/depth (same grid, depth aligned to the right camera).
  • Results:
    • Synthetic frame: t is 0.00075 m before and 0.07500 m after.
    • Real camera (calibration baseline 7.49 cm): with t = 0.0749 and the rectified focal length, depth_mm / (f * t * 1000 / disparity) has a median of 0.98. With the old t it was about 97.6, which is the factor of 100.

AI

  • Were AI agents used for this PR? (Yes / No): No
  • Was the code checked by a human? (Yes / Partially / No): Yes

The constructor takes the baseline in centimeters and already converts it
to meters, but toRosMsg divided it by 100 again when filling
DisparityImage.t. For a 7.5 cm baseline t was published as 0.00075 m
instead of 0.075 m, so any depth reconstructed from the message was 100
times too small.

Publish the baseline as it is stored (meters), document the units of the
constructor arguments and fix the unit test, which expected the wrong
value (0.01 for a 100 cm baseline instead of 1.0).
Copilot AI balanced review requested due to automatic review settings October 30, 2026 17:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The ToRosMsgPtrTest baseline expectation remains 0.01f instead of 1.0f, causing the registered disparity-converter test target to fail after the conversion fix.

1 open issue
What changed in this PR

This PR corrects the baseline published by DisparityConverter, preventing consumers from reconstructing depths 100 times too small.

Changes:

  • Publish the stored baseline in meters without converting it again.
  • Document constructor argument units.
  • Update the direct-conversion test to expect 1 meter for a 100 cm baseline.
File Description
depthai_bridge/​test/​DisparityConverterTest.cpp Corrects the direct-conversion baseline expectation.
depthai_bridge/​src/​DisparityConverter.cpp Removes the duplicate baseline conversion.
depthai_bridge/​include/​depthai_bridge/​DisparityConverter.hpp Documents focal length, baseline, and depth units.

Review effort: Balanced

toRosMsgPtr() delegates to toRosMsg(), so with the 100 cm baseline used in
this test the corrected conversion returns t = 1.0 (m) there too.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change's single unit fix is internally consistent with the updated documentation and corrected test expectations, leaving no outstanding issues to resolve.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@asahtik asahtik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@asahtik
asahtik merged commit fa44110 into luxonis:develop Nov 18, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants