CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ros2
publishers
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
12
namespace
carla
{
13
namespace
ros2
{
14
15
struct
CameraIntrinsics
{
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.
38
[[nodiscard]]
inline
CameraIntrinsics
ComputeIntrinsics
(
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
carla::ros2
Definition
AutowareSteeringCompensation.h:15
carla::ros2::ComputeIntrinsics
CameraIntrinsics ComputeIntrinsics(uint32_t width, uint32_t height, float fov_degrees) noexcept
Definition
CameraIntrinsics.h:38
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::ros2::CameraIntrinsics
Definition
CameraIntrinsics.h:15
carla::ros2::CameraIntrinsics::fx
double fx
Definition
CameraIntrinsics.h:16
carla::ros2::CameraIntrinsics::cy
double cy
Definition
CameraIntrinsics.h:19
carla::ros2::CameraIntrinsics::cx
double cx
Definition
CameraIntrinsics.h:18
carla::ros2::CameraIntrinsics::fy
double fy
Definition
CameraIntrinsics.h:17
Generated by
1.18.0