CARLA
Loading...
Searching...
No Matches
CameraIntrinsics.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include <cmath>
10#include <cstdint>
11
12namespace carla {
13namespace ros2 {
14
16 double fx;
17 double fy;
18 double cx;
19 double cy;
20};
21
22// Builds a pinhole-camera intrinsic matrix from horizontal FOV (degrees) and
23// image dimensions (pixels):
24// fx = width / (2 * tan(fov_deg * pi / 360))
25// fy = fx (square pixels)
26// cx = width / 2
27// cy = height / 2
28//
29// This is the corrected form from upstream commit 86ebadcee. The pre-fix
30// spelling read `width / (2 * tan(fov) * M_PI / 360)` which applied the
31// degree-to-radian conversion to `tan(fov)` instead of to `fov`, producing a
32// nonsensical focal length.
33//
34// M_PI is used here, not std::numbers::pi_v, because this header is consumed
35// by the carla-ros2-native ExternalProject in Ros2Native/, which does not
36// configure CMAKE_CXX_STANDARD and therefore defaults to C++17 where <numbers>
37// is unavailable.
39 uint32_t width, uint32_t height, float fov_degrees) noexcept {
40 const double w = static_cast<double>(width);
41 const double h = static_cast<double>(height);
42 const double fov_rad = static_cast<double>(fov_degrees) * M_PI / 360.0;
43 const double fx = w / (2.0 * std::tan(fov_rad));
44 return {fx, fx, w / 2.0, h / 2.0};
45}
46
47} // namespace ros2
48} // namespace carla
CameraIntrinsics ComputeIntrinsics(uint32_t width, uint32_t height, float fov_degrees) noexcept
This file contains definitions of common data structures used in traffic manager.