Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distortion normalization improvement + fix "folding" on large distortions #3009

Merged
merged 25 commits into from
Jun 21, 2021

Conversation

kjeppesen1
Copy link
Contributor

@kjeppesen1 kjeppesen1 commented May 22, 2021

Fixes #3003.

Modifies how Brown's distortion equations are applied to better reflect real distortion. Image is projected from image plane to camera plane to apply distortion equations, then projected back to image plane.

Before/after focal scaling implementation:
distortion_comparisons_gazebo

Before/after extreme distortion edge case fix:
before fix after fix


We use a tag <ignition:legacy_mode> in a distortion context to select this new behavior.

Regardless of if the new mode or legacy mode are used, this PR adds a bug fix for heavy distortions that prevents the distorted image from "folding back" on itself, as seen in the image above.

@kjeppesen1
Copy link
Contributor Author

@audrow

@audrow audrow self-assigned this May 22, 2021
@audrow audrow marked this pull request as ready for review May 27, 2021 00:32
@audrow
Copy link
Contributor

audrow commented May 28, 2021

One comment on the test we've added: We've added a more extreme barrel and pin cushion distortion to an existing test for distortion. This test is not very rigorous and may pass even before this PR or if the results are incorrect, for example because of parameter leaking #2527.

I think after #2527 is fixed, it would be good to add a stronger test to check that behavior is as expected. A possible work around for #2527 is to make environments with one camera per world and test their expected behavior individually.

@scpeters
Copy link
Member

scpeters commented Jun 2, 2021

This test is not very rigorous and may pass even before this PR or if the results are incorrect, for example because of parameter leaking #2527.

I have run this test without the fixes in this branch and confirmed that it does not fail, reducing its usefulness.

for example because of parameter leaking #2527.

I believe that parameter leaking does not occur in this test because the individual cameras are each added dynamically using the SpawnCamera helper function. I think we don't need to wait for a fix to #2527 to improve this test and would prefer that we figure out how to do so in this pull request

@scpeters
Copy link
Member

scpeters commented Jun 2, 2021

Before/after extreme distortion edge case fix:
before fix after fix

how did you generate these images?

@audrow
Copy link
Contributor

audrow commented Jun 2, 2021

how did you generate these images?

We took them in Gazebo by placing a checkerboard directly in front of a camera with significant distortion (k1 = -0.5). Also, we're not doing border cropping here, so the gray around the edges is where there's no information.

@scpeters
Copy link
Member

scpeters commented Jun 4, 2021

this is a behavior change, so I think we should use a namespaced SDFormat parameter to opt-in to it, to keep existing camera parameters functioning the same way. Something like <ignition:use_focal_length>? Please suggest an appropriate parameter name. If you want to disable cropping with this flag, you can do that as well

<distortion>
  <ignition:use_focal_length>true</ignition:use_focal_length>
  <k1>...</k1>
  ...
</distortion>

@kjeppesen1
Copy link
Contributor Author

kjeppesen1 commented Jun 4, 2021

this is a behavior change, so I think we should use a namespaced SDFormat parameter to opt-in to it, to keep existing camera parameters functioning the same way. Something like <ignition:use_focal_length>? Please suggest an appropriate parameter name.

I agree with this approach. Something that indicates that it will use the provided distortion coefficients directly would be ideal. Maybe <ignition:use_real_distortion>, <ignition:use_exact_coefficients>, or <ignition:directly_use_coefficients>, although those aren't great either.

If you want to disable cropping with this flag, you can do that as well

I am in favor of disabling cropping with this implementation since cropping invalidates the distortion parameters (and therefore defeats the purpose of using the tag).

kbjeppes and others added 6 commits June 8, 2021 14:15
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
@audrow audrow force-pushed the distortion_normalization branch from 47ad970 to 77bb479 Compare June 9, 2021 16:50
@audrow
Copy link
Contributor

audrow commented Jun 9, 2021

@scpeters and @kjeppesen1, I've added a <ignition:use_real_distortion> tag and extended existing tests to make sure that this works. I also rebased this branch.

@audrow
Copy link
Contributor

audrow commented Jun 9, 2021

I believe that parameter leaking does not occur in this test because the individual cameras are each added dynamically using the SpawnCamera helper function. I think we don't need to wait for a fix to #2527 to improve this test and would prefer that we figure out how to do so in this pull request

I'll think about a better test to add.

paudrow added 2 commits June 10, 2021 09:56
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
@audrow
Copy link
Contributor

audrow commented Jun 10, 2021

I've applied the feedback from yesterday and added a test that I believe checks the feature.

Changes:

  • Use <ignition:legacy_mode> flag
  • Check for using legacy mode in the setCrop method
  • Add a test that checks for expected cropping and distortion behavior with legacy and non legacy modes

I spawned cameras in the test environment to get around #2527.

@audrow audrow added the enhancement New feature or request label Jun 10, 2021
gazebo/rendering/Distortion.cc Outdated Show resolved Hide resolved
distortedIdx = distortedRow * this->dataPtr->distortionTexWidth + distortedCol;

// check if the index has already been set
if (this->dataPtr->distortionMap[distortedIdx] != unsetPixelVector)
Copy link
Member

Choose a reason for hiding this comment

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

this logic block looks new. should we add && !this->dataPtr->legacyMode to the if statement? or we could reverse it:

if (this->dataPtr->legacyMode)
{
  this->dataPtr->distortionMap[distortedIdx] = normalizedLocation;
}
// check if the index has already been set
else if (this->dataPtr->distortionMap[distortedIdx] != unsetPixelVector)
{
...
}

if not, then we should clarify that this is a bug fix that applies in all cases

Copy link
Contributor

@audrow audrow Jun 10, 2021

Choose a reason for hiding this comment

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

I think this can be considered a bug fix, since there will be the wrapping behavior shown in #3009 (comment) on very large barrel distortions with the legacy method.

I'm not sure what would be the best place to mention this. I can alter the PR to mention the bug fix and add a comment in this part of the code. Anywhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

gazebo/rendering/Distortion.cc Outdated Show resolved Hide resolved
test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
test/integration/camera_sensor.cc Show resolved Hide resolved
paudrow added 5 commits June 11, 2021 08:54
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
This reverts commit ba51bac.

# Conflicts:
#	test/integration/camera_sensor.cc
Signed-off-by: Audrow Nash <audrow@hey.com>
@audrow
Copy link
Contributor

audrow commented Jun 15, 2021

@mvespign, thanks for removing the duplicate method. This was done by 4fe9c4b (before 464adb1). I'm going to force push to remove the recent commits.

@audrow audrow force-pushed the distortion_normalization branch from 1d51120 to 861f8eb Compare June 15, 2021 18:40
@audrow audrow requested review from scpeters and audrow and removed request for audrow June 15, 2021 18:42
paudrow added 2 commits June 15, 2021 14:53
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
@audrow audrow requested a review from scpeters June 15, 2021 21:56
Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

the new test looks good. I think you've matched the style of other tests, though there is a fair bit of repeated code. Some lambda functions could probably reduce some code duplication, but it's fine as is

test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
Signed-off-by: Audrow Nash <audrow@hey.com>
@audrow audrow requested a review from scpeters June 16, 2021 00:40
Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

ok, I think this is almost there. I just have one minor nit, and I noticed some lines are longer than 80 characters. Our CI is not currently reporting style errors due to gazebo-tooling/release-tools#446, but I think avoiding trailing whitespace and long lines should be enough

test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
paudrow added 2 commits June 16, 2021 17:30
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
@audrow
Copy link
Contributor

audrow commented Jun 17, 2021

I think that it should be good now.

@audrow audrow requested a review from scpeters June 17, 2021 00:36
@scpeters
Copy link
Member

I've tested with libgazebo_ros_camera, and I think the logic is working properly now

Copy link
Member

@scpeters scpeters left a comment

Choose a reason for hiding this comment

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

I just noticed some new clang warnings, but aside from that I approve

test/integration/camera_sensor.cc Outdated Show resolved Hide resolved
Signed-off-by: Audrow Nash <audrow@hey.com>
gazebo/rendering/Distortion.cc Outdated Show resolved Hide resolved
gazebo/rendering/Distortion.cc Outdated Show resolved Hide resolved
gazebo/rendering/Distortion.cc Outdated Show resolved Hide resolved
double _cx = 0.5, double _cy = 0.5);
double _cx = 0.5, double _cy = 0.5,
bool _legacyMode = true,
double _horizontalFov = 0.78539816339744828);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this breaks ABI?

ABI checker didn't show any issue here but I'm not sure if that's because it's not testing the ServerFixture library.

Also add \param[in] for _horizontalFov

Copy link
Member

Choose a reason for hiding this comment

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

I think this breaks ABI?

ABI checker didn't show any issue here but I'm not sure if that's because it's not testing the ServerFixture library.

I was wondering the same thing, but we only distribute ServerFixture in a static library, and I believe ABI is only a concern for dynamically loaded libraries

paudrow added 3 commits June 18, 2021 12:03
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
Signed-off-by: Audrow Nash <audrow@hey.com>
@audrow audrow requested a review from iche033 June 18, 2021 19:08
@scpeters
Copy link
Member

Windows CI failed for an unrelated reason, and the failures in the other jobs look unrelated to me. Merging now...

@scpeters scpeters merged commit a708aa3 into gazebosim:gazebo11 Jun 21, 2021
@scpeters scpeters mentioned this pull request Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Distortion implementation correction
5 participants