CARLA
 
载入中...
搜索中...
未找到
ImageView.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
9#include "carla/image/BoostGil.h" // 引入Boost.GIL库的头文件
10#include "carla/image/ColorConverter.h" // 引入颜色转换器的头文件
11#include "carla/sensor/data/Color.h" // 引入颜色数据的头文件
12#include "carla/sensor/data/ImageTmpl.h" // 引入图像模板的头文件
13
14#include <type_traits> // 引入类型特性相关的头文件
15
16namespace carla {
17namespace image {
18
19 class ImageView { // 定义ImageView类
20 private:
21
22 // 定义灰度像素布局的类型,使用Boost.GIL库
23 template <typename SrcViewT>
24 using GrayPixelLayout = boost::gil::pixel<typename boost::gil::channel_type<SrcViewT>::type, boost::gil::gray_layout_t>;
25
26 // 从传感器图像生成目标像素类型的视图
27 template <typename DstPixelT, typename ImageT>
28 static auto MakeViewFromSensorImage(ImageT &image) {
29 using namespace boost::gil; // 引入Boost.GIL命名空间
30 namespace sd = carla::sensor::data; // 简化命名空间引用
31 static_assert(
32 std::is_same<typename ImageT::pixel_type, sd::Color>::value, // 确保像素类型为Color
33 "Invalid pixel type"); // 如果不是,则触发编译错误
34 static_assert(
35 sizeof(sd::Color) == sizeof(DstPixelT), // 确保像素大小相同
36 "Invalid pixel size"); // 如果不是,则触发编译错误
37 return interleaved_view( // 创建交错视图
38 image.GetWidth(), // 图片宽度
39 image.GetHeight(), // 图片高度
40 reinterpret_cast<DstPixelT*>(image.data()), // 数据指针转换为目标像素类型
41 sizeof(sd::Color) * image.GetWidth()); // 行长度(字节)
42 }
43
44 public:
45
46 // 创建图像视图
47 template <typename ImageT>
48 static auto MakeView(ImageT &image) {
49 return boost::gil::view(image); // 使用Boost.GIL创建视图
50 }
51
52 // 针对传感器图像类型创建视图
54 return MakeViewFromSensorImage<boost::gil::bgra8_pixel_t>(image); // 使用BGRA8像素类型
55 }
56
57 // 针对传感器图像类型创建常量视图
59 return MakeViewFromSensorImage<boost::gil::bgra8c_pixel_t>(image); // 使用BGRA8C像素类型
60 }
61
62 // 创建颜色转换视图
63 template <typename SrcViewT, typename DstPixelT, typename CC>
64 static auto MakeColorConvertedView(const SrcViewT &src, CC cc) {
65 return _MakeColorConvertedView<DstPixelT>(src, cc); // 调用私有方法进行颜色转换
66 }
67
68 // 创建颜色转换视图,默认目标像素类型为灰度布局
69 template <typename SrcViewT, typename DstPixelT = GrayPixelLayout<SrcViewT>>
70 static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::Depth cc) {
71 return _MakeColorConvertedView<DstPixelT>(src, cc); // 调用私有方法进行深度颜色转换
72 }
73
74 // 创建颜色转换视图,使用对数深度
75 template <typename SrcViewT, typename DstPixelT = GrayPixelLayout<SrcViewT>>
76 static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::LogarithmicDepth) {
77 auto intermediate_view = _MakeColorConvertedView<boost::gil::gray32f_pixel_t>(src, ColorConverter::Depth()); // 中间转换为32位灰度像素
78 return _MakeColorConvertedView<DstPixelT>(intermediate_view, ColorConverter::LogarithmicLinear()); // 最终转换为目标像素类型
79 }
80
81 // 创建颜色转换视图,使用CityScapes调色板
82 template <typename SrcViewT, typename DstPixelT = typename SrcViewT::value_type>
84 return _MakeColorConvertedView<DstPixelT>(src, cc); // 调用私有方法进行调色板转换
85 }
86
87 private:
88
89 // 内部结构,用于定义颜色转换后的类型
90 template <typename SrcView, typename DstP, typename CC>
92 private:
93 typedef boost::gil::color_convert_deref_fn<typename SrcView::const_t::reference, DstP, CC> deref_t; // 定义解引用类型
94 typedef typename SrcView::template add_deref<deref_t> add_ref_t; // 添加解引用
95 public:
96 typedef typename add_ref_t::type type; // 定义最终类型
97 static type make(const SrcView &sv, CC cc) { return add_ref_t::make(sv, deref_t(cc)); } // 创建实例
98 };
99
100 // 私有方法,创建颜色转换视图
101 template <typename DstPixelT, typename SrcViewT, typename CC>
102 static auto _MakeColorConvertedView(const SrcViewT &src, CC cc) {
103 return color_converted_type<SrcViewT, DstPixelT, CC>::make(src, cc); // 返回转换后的视图
104 }
105 };
106
107} // namespace image
108} // namespace carla
static auto MakeView(const sensor::data::ImageTmpl< sensor::data::Color > &image)
Definition ImageView.h:58
static auto MakeView(ImageT &image)
Definition ImageView.h:48
static auto MakeColorConvertedView(const SrcViewT &src, CC cc)
Definition ImageView.h:64
static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::LogarithmicDepth)
Definition ImageView.h:76
static auto MakeView(sensor::data::ImageTmpl< sensor::data::Color > &image)
Definition ImageView.h:53
static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::CityScapesPalette cc)
Definition ImageView.h:83
static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::Depth cc)
Definition ImageView.h:70
boost::gil::pixel< typename boost::gil::channel_type< SrcViewT >::type, boost::gil::gray_layout_t > GrayPixelLayout
Definition ImageView.h:24
static auto MakeViewFromSensorImage(ImageT &image)
Definition ImageView.h:28
static auto _MakeColorConvertedView(const SrcViewT &src, CC cc)
Definition ImageView.h:102
Templated image for any type of pixel.
Definition ImageTmpl.h:33
包含客户端相关类和定义的命名空间。
Definition AtomicList.h:17
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
static double sd[6]
Definition odrSpiral.cpp:56
SrcView::template add_deref< deref_t > add_ref_t
Definition ImageView.h:94
boost::gil::color_convert_deref_fn< typename SrcView::const_t::reference, DstP, CC > deref_t
Definition ImageView.h:93
static type make(const SrcView &sv, CC cc)
Definition ImageView.h:97