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

Fix camera focal length #510

Merged
merged 3 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions webots_ros2/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog for package webots_ros2
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2022.1.4 (2022-XX-XX)
------------------
* Fix the camera focal length in the CameraInfo topic.

2022.1.3 (2022-11-02)
------------------
* Added macOS support.
Expand Down
4 changes: 4 additions & 0 deletions webots_ros2_driver/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog for package webots_ros2_driver
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2022.1.4 (2022-XX-XX)
------------------
* Fix the camera focal length in the CameraInfo topic.

2022.1.3 (2022-11-02)
------------------
* Added macOS support.
Expand Down
4 changes: 1 addition & 3 deletions webots_ros2_driver/src/plugins/static/Ros2Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ namespace webots_ros2_driver
mCameraInfoMessage.distortion_model = "plumb_bob";

// Convert FoV to focal length.
// Reference: https://en.wikipedia.org/wiki/Focal_length#In_photography
const double diagonal = sqrt(pow(mCamera->getWidth(), 2) + pow(mCamera->getHeight(), 2));
const double focalLength = 0.5 * diagonal * (cos(0.5 * mCamera->getFov()) / sin(0.5 * mCamera->getFov()));
const double focalLength = mCamera->getWidth() / (2 * tan(mCamera->getFov() / 2));

mCameraInfoMessage.d = {0.0, 0.0, 0.0, 0.0, 0.0};
mCameraInfoMessage.r = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
Expand Down