CARLA
 
载入中...
搜索中...
未找到
ColorConverter.h
浏览该文件的文档.
1// Copyright (c) 2017 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// 包含 BoostGil 和 CityScapesPalette 的头文件,可能用于图像处理和颜色转换操作
11// 命名空间 carla::image,用于组织与图像相关的功能
12namespace carla {
13namespace image {
14// ColorConverter 类,可能用于实现各种颜色转换操作
16 public:
17// LogarithmicLinear 结构体,可能用于进行对数线性转换
19 // 模板函数,对输入像素 src 进行对数线性转换,并将结果存储在输出像素 dst 中
20 template <typename DstPixelT>
21 void operator()(const boost::gil::gray32fc_pixel_t &src, DstPixelT &dst) const {
22 using namespace boost::gil;
23 // 根据输入像素值进行对数计算,得到一个中间值 value
24 const float value = 1.0f + std::log(src[0u]) / 5.70378f;
25 // 对中间值进行范围限制,确保在 0.005f 和 1.0f 之间,得到 clamped
26 const float clamped = std::max(std::min(value, 1.0f), 0.005f);
27 // 使用 color_convert 函数将 clamped 的灰度值转换为目标像素类型 dst
28 color_convert(gray32fc_pixel_t{clamped}, dst);
29 }
30 };
31// Depth 结构体,可能用于处理深度信息的转换
32 struct Depth {
33 // 模板函数,对输入像素 src 进行深度转换,并将结果存储在输出像素 dst 中
34 template <typename SrcPixelT, typename DstPixelT>
35 void operator()(const SrcPixelT &src, DstPixelT &dst) const {
36 using namespace boost::gil;
37
38 // 检查源像素类型是否为 uint8_t 类型的颜色分量
39 static_assert(
40 sizeof(typename color_space_type<SrcPixelT>::type) == sizeof(uint8_t),
41 "Invalid pixel type.");
42 // 根据输入像素的红、绿、蓝通道值计算深度值 depth
43 const float depth =
44 get_color(src, red_t()) +
45 (get_color(src, green_t()) * 256) +
46 (get_color(src, blue_t()) * 256 * 256);
47 const float normalized = depth / static_cast<float>(256 * 256 * 256 - 1);
48 color_convert(gray32fc_pixel_t{normalized}, dst);
49 }
50 };
51
53 // CityScapesPalette 结构体,可能用于将像素转换为 CityScapes 调色板中的颜色
55 template <typename SrcPixelT, typename DstPixelT>
56 void operator()(const SrcPixelT &src, DstPixelT &dst) const {
57 using namespace boost::gil;
58
59 // 检查源像素类型是否为 uint8_t 类型的颜色分量
60 static_assert(
61 sizeof(typename color_space_type<SrcPixelT>::type) == sizeof(uint8_t),
62 "Invalid pixel type.");
63 // 根据输入像素的红通道值获取 CityScapesPalette 中的颜色值 color
64 const auto color = image::CityScapesPalette::GetColor(get_color(src, red_t()));
65 // 使用 color_convert 函数将获取的颜色值转换为目标像素类型 dst
66 color_convert(rgb8c_pixel_t{color[0u], color[1u], color[2u]}, dst);
67 }
68 };
69 };
70
71} // namespace image
72} // namespace carla
static constexpr auto GetColor(uint8_t tag)
根据标签返回对应的RGB颜色值。
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
void operator()(const SrcPixelT &src, DstPixelT &dst) const
void operator()(const SrcPixelT &src, DstPixelT &dst) const
void operator()(const boost::gil::gray32fc_pixel_t &src, DstPixelT &dst) const