Repository navigation
Account for the principal point offset when projecting stereo disparities - #1216
Open
Rahul-cs50 wants to merge 2 commits into
Open
Rahul-cs50 wants to merge 2 commits into
Rahul-cs50 wants to merge 2 commits into
Conversation
…ties DisparityImage disparities are already adjusted for cx_l - cx_r, but point_cloud_node, processPoints and processPoints2 projected them with the camera model's Q, whose Q(3,3) subtracts that offset again. With cx_l != cx_r every point got the wrong depth, or landed behind the camera. Project with Q(3,3) = 0 instead, so Z = fT/d as the message specifies. Signed-off-by: Rahul-cs50 <rahulseervi.dev@gmail.com>
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
…loud-principal-point-offset # Conflicts: # stereo_image_proc/include/stereo_image_proc/stereo_processor.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the two rectified cameras have different principal points (
cx_l != cx_r),point_cloud_nodeandStereoProcessor::processPoints/processPoints2put every point at the wrong depth, and can put it behind the camera.stereo_msgs/DisparityImagedisparities are pre-adjusted for that offset,d = x_l - x_r - (cx_l - cx_r)withZ = fT/d, andStereoProcessor::processDisparitypublishes exactly that. The three consumers then project the image withStereoCameraModel::projectDisparityImageTo3d(), which iscv::reprojectImageTo3D()with the model's Q. Q expects the rawx_l - x_rand carries the offset inQ(3,3) = fy * (cx_l - cx_r)(active since ros-perception/vision_opencv@833f005b, 2012), so the offset is subtracted a second time and the cloud getsZ = fT / (d - (cx_l - cx_r)).For example, a textured plane 2.0 m away, seen by a pair with
f = 300,B = 0.12 mandcx_l - cx_r = 20 px, comes out of the matcherdisparity_nodeuses (StereoProcessor::processDisparity) withd = 18(the right value,fT/Z), and the cloud puts it at Z = -18 m.ROS
camera_calibrationrectifies withCALIB_ZERO_DISPARITY(OpenCV's default forstereoRectify), which makescx_l == cx_r, so its calibrations aren't affected. Rectifying withflags=0, as some other tools do, keeps the offset.This was found before in #349 (2018), which proposed dropping the pre-adjustment in
processDisparity. That PR was closed in 2022 because it targeted Indigo. This PR fixes the consumers instead, so the published disparity keeps the meaningDisparityImage.msgdocuments, which other producers such asdepth_image_proc's disparity node follow too.Change
A new
stereo_image_proc::projectAdjustedDisparityImageTo3d()projects with a copy of the model's Q that hasQ(3,3) = 0, since the offset is already in the disparity. This is the same as addingcx_l - cx_rback to each disparity before callingprojectDisparityImageTo3d(). Missing values are handled as before (handleMissingValues = true,MISSING_Z).point_cloud_node,processPointsandprocessPoints2use it.When
cx_l == cx_r,Q(3,3)was already 0, so the output is unchanged. The output does change for anyone who feedspoint_cloud_noderawx_l - x_rdisparities from a camera pair withcx_l != cx_r. Such disparities don't followDisparityImage.msg, and the old double subtraction happened to give them the right depth.Not changed here:
processDisparitystill fillsmin_disparity/max_disparitywith the raw search range, while the image holds adjusted values. I can open a separate PR for that if you'd like.Test
New gtest
test/test_stereo_processor.cpp. It builds aStereoCameraModelwithcx_l - cx_r = 20 px,fx != fy, and a constant adjusted disparity of 25 px with one missing pixel. It checks X, Y and Z of every point fromprojectAdjustedDisparityImageTo3d(),processPoints()andprocessPoints2()againstZ = fT/d(2.0 m), and checks that the missing pixel stays missing.In a
ros:rolling-ros-basecontainer (image_geometry 4.1.0, OpenCV 4.10):AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS=1), lint_cmake, xmllint and copyright;processPointsandprocessPoints2fail with Z = 10.0 m (fT / (d - 20)).processDisparity, thenprocessPoints2). With this change the cloud's median Z is 2.000 m, the true depth. Without it, the median is -18.0 m.test_disparity_nodeandtest_point_cloud_nodetime out in my container both with and without this change, so I couldn't use them here.