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

sdf/camera.sdf: fields for projection matrix #1088

Merged
merged 11 commits into from
Aug 31, 2022

Conversation

ihasdapie
Copy link
Contributor

@ihasdapie ihasdapie commented Jul 21, 2022

🎉 New feature

Summary

This PR adds sdf fields to allow for configuration of the camera projection matrix.

Related PR in ign-sensors3: gazebosim/gz-sensors#249

Test it

Make a camera with sdf tags specifying these new fields.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
@github-actions github-actions bot added Gazebo 1️1️ Dependency of Gazebo classic version 11 🏰 citadel Ignition Citadel labels Jul 21, 2022
Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! The C++ classes in SDFormat should reflect the XML spec. Do you mind adding the new elements here, with their respective tests?

sdformat/sdf/1.9/camera.sdf

Lines 175 to 193 in 3dd02cc

<element name="intrinsics" required="0">
<description>Camera intrinsic parameters for setting a custom perspective projection matrix (cannot be used with WideAngleCamera since this class uses image stitching from 6 different cameras for achieving a wide field of view). The focal lengths can be computed using focal_length_in_pixels = (image_width_in_pixels * 0.5) / tan(field_of_view_in_degrees * 0.5 * PI/180)</description>
<element name="fx" type="double" default="277" required="1">
<description>X focal length (in pixels, overrides horizontal_fov)</description>
</element>
<element name="fy" type="double" default="277" required="1">
<description>Y focal length (in pixels, overrides horizontal_fov)</description>
</element>
<element name="cx" type="double" default="160" required="1">
<description>X principal point (in pixels)</description>
</element>
<element name="cy" type="double" default="120" required="1">
<description>Y principal point (in pixels)</description>
</element>
<element name="s" type="double" default="0.0" required="1">
<description>XY axis skew</description>
</element>
</element> <!-- End Intrinsics -->
</element> <!-- End Lens -->

Also, note that we use CamelCase for function names, so the function names should be updated not to use _p. Maybe SetLensProjection*?

@ihasdapie
Copy link
Contributor Author

Thanks for the feedback! I'll make those changes

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

Do you mind to add tests for the new methods ?

@@ -151,6 +151,24 @@
<element name="cy" type="double" default="120" required="1">
<description>Y principal point (in pixels)</description>
</element>
<element name="p_fx" type="double" default="277" required="0">
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding the elements! I'm wondering if it's best to put these inside a new <projection> element that's a sibling of intrinsics. Or maybe a child of intrinsics? I'd have to refresh my computer vision knowledge.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, I don't know enough about these parameters to have a useful opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for adding the elements! I'm wondering if it's best to put these inside a new <projection> element that's a sibling of intrinsics. Or maybe a child of intrinsics? I'd have to refresh my computer vision knowledge.

IIUC the projection matrix is the cumulative effect of intrinsic and extrinsic parameters. So unless a xml element can have two parents (which I don't think is possible) I think @chapulina's suggestion to put these inside a new sibling <projection> element is best. I've done this in de4e536

References

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
@ihasdapie
Copy link
Contributor Author

ihasdapie commented Jul 22, 2022

Do you mind to add tests for the new methods ?

Yup, I missed it earlier. They've been added in a26db0e

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
@scpeters scpeters changed the title add sdf fields for camera projection matrix sdf/camera.sdf: fields for projection matrix Aug 18, 2022
@codecov
Copy link

codecov bot commented Aug 18, 2022

Codecov Report

Merging #1088 (896f028) into sdf9 (2e891c2) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             sdf9    #1088      +/-   ##
==========================================
+ Coverage   87.75%   87.81%   +0.05%     
==========================================
  Files          64       64              
  Lines       10055    10099      +44     
==========================================
+ Hits         8824     8868      +44     
  Misses       1231     1231              
Impacted Files Coverage Δ
src/Camera.cc 83.13% <100.00%> (+1.96%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@scpeters
Copy link
Member

Do you mind to add tests for the new methods ?

Yup, I missed it earlier. They've been added in a26db0e

to improve test coverage, let's add these new fields to the sensors.sdf test file and add corresponding test expectations to link_dom.cc

Signed-off-by: Brian Chen <brian.chen@openrobotics.org>
…/sdformat into brianc/sdf9/configure_proj_mat
@ihasdapie
Copy link
Contributor Author

to improve test coverage, let's add these new fields to the sensors.sdf test file and add corresponding test expectations to link_dom.cc

@scpeters I've done so in 47bb73a.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
@scpeters scpeters dismissed stale reviews from chapulina and ahcorde August 26, 2022 21:55

C++ classes now match the spec

@scpeters
Copy link
Member

@ahcorde @chapulina you had requested changes, but I believe they have been addressed, so I dismissed your reviews. I'll merge on Monday unless I hear otherwise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel enhancement New feature or request Gazebo 1️1️ Dependency of Gazebo classic version 11
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants