Skip to content

Commit

Permalink
Fix camera focal length (#510)
Browse files Browse the repository at this point in the history
* Fix camera focal length

* Update CHANGELOG.rst

* Update CHANGELOG.rst

Co-authored-by: ad-daniel <[email protected]>
  • Loading branch information
lukicdarkoo and ad-daniel authored Nov 9, 2022
1 parent 3ffa1de commit 75118d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
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

0 comments on commit 75118d7

Please sign in to comment.