CARLA
 
载入中...
搜索中...
未找到
DVSEventArray.h
浏览该文件的文档.
1// Copyright (c) 2020 Robotics and Perception Group (GPR)
2// University of Zurich and ETH Zurich
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/Debug.h" // 包含调试相关的头文件
10#include "carla/sensor/data/Array.h" // 包含数组数据结构的头文件
11#include "carla/sensor/data/DVSEvent.h" // 包含DVS事件的数据结构
12#include "carla/sensor/data/Color.h" // 包含颜色相关的数据结构
13#include "carla/sensor/s11n/DVSEventArraySerializer.h" // 包含序列化DVS事件数组的头文件
14
15namespace carla {
16namespace sensor {
17namespace data {
18
19 /// DVS事件的数组,采用HxW图像结构
20 class DVSEventArray : public Array<DVSEvent> {
21 using Super = Array<DVSEvent>; // 使用父类Array<DVSEvent>的别名
22 protected:
23
24 using Serializer = s11n::DVSEventArraySerializer; // 序列化器的别名
25
26 friend Serializer; // 声明Serializer为友元类,可以访问私有成员
27
28 explicit DVSEventArray(RawData &&data) // 构造函数,接受原始数据
29 : Super(Serializer::header_offset, std::move(data)) { // 调用父类构造函数
30 }
31
32 private:
33
34 const auto &GetHeader() const { // 获取头部信息
35 return Serializer::DeserializeHeader(Super::GetRawData()); // 反序列化头部
36 }
37 public:
38
39 using event_type = DVSEvent; // 将事件类型定义为DVSEvent
40
41 /// 获取图像的宽度(以像素为单位)
42 auto GetWidth() const {
43 return GetHeader().width; // 返回头部中的宽度
44 }
45
46 /// 获取图像的高度(以像素为单位)
47 auto GetHeight() const {
48 return GetHeader().height; // 返回头部中的高度
49 }
50
51 /// 获取图像的水平视野角度(以度为单位)
52 auto GetFOVAngle() const {
53 return GetHeader().fov_angle; // 返回头部中的视野角度
54 }
55
56 /// 获取事件"帧"图像用于可视化
57 std::vector<Color> ToImage() const {
58 std::vector<Color> img(GetHeight() * GetWidth()); // 创建图像向量
59 for (const auto &event : *this) { // 遍历所有事件
60 size_t index = (GetWidth() * event.y) + event.x; // 计算图像索引
61 if (event.pol == true) { // 如果极性为正
62 img[index].b = 255u; // 将蓝色通道设为255
63 } else { // 否则
64 img[index].r = 255u; // 将红色通道设为255
65 }
66 }
67 return img; // 返回生成的图像
68 }
69
70 /// 获取事件的纯向量格式数组
71 std::vector<std::vector<std::int64_t>> ToArray() const {
72 std::vector<std::vector<std::int64_t>> array; // 创建二维数组
73 for (const auto &event : *this) { // 遍历所有事件
74 array.push_back({static_cast<std::int64_t>(event.x), static_cast<std::int64_t>(event.y), static_cast<std::int64_t>(event.t), (2*static_cast<std::int64_t>(event.pol)) - 1}); // 添加事件的x, y, t和极性信息
75 }
76 return array; // 返回事件数组
77 }
78
79 /// 获取所有事件的x坐标,便于使用
80 std::vector<std::uint16_t> ToArrayX() const {
81 std::vector<std::uint16_t> array; // 创建x坐标数组
82 for (const auto &event : *this) { // 遍历所有事件
83 array.push_back(event.x); // 添加x坐标
84 }
85 return array; // 返回x坐标数组
86 }
87
88 /// 获取所有事件的y坐标,便于使用
89 std::vector<std::uint16_t> ToArrayY() const {
90 std::vector<std::uint16_t> array; // 创建y坐标数组
91 for (const auto &event : *this) { // 遍历所有事件
92 array.push_back(event.y); // 添加y坐标
93 }
94 return array; // 返回y坐标数组
95 }
96
97 /// 获取所有事件的时间戳,便于使用
98 std::vector<std::int64_t> ToArrayT() const {
99 std::vector<std::int64_t> array; // 创建时间戳数组
100 for (const auto &event : *this) { // 遍历所有事件
101 array.push_back(event.t); // 添加时间戳
102 }
103 return array; // 返回时间戳数组
104 }
105
106 /// 获取所有事件的极性,便于使用
107 std::vector<short> ToArrayPol() const {
108 std::vector<short> array; // 创建极性数组
109 for (const auto &event : *this) { // 遍历所有事件
110 array.push_back(2*static_cast<short>(event.pol) - 1); // 将极性转换为-1和1
111 }
112 return array; // 返回极性数组
113 }
114
115 };
116
117} // namespace data
118} // namespace sensor
119} // namespace carla
包装一个传感器生成的原始数据以及一些有用的元信息。
Definition RawData.h:20
所有传感器数据的基类,包含一个项目数组。
Definition Array.h:23
const RawData & GetRawData() const
Definition Array.h:162
DVS事件的数组,采用HxW图像结构
std::vector< std::uint16_t > ToArrayX() const
获取所有事件的x坐标,便于使用
std::vector< std::vector< std::int64_t > > ToArray() const
获取事件的纯向量格式数组
std::vector< std::int64_t > ToArrayT() const
获取所有事件的时间戳,便于使用
std::vector< Color > ToImage() const
获取事件"帧"图像用于可视化
std::vector< std::uint16_t > ToArrayY() const
获取所有事件的y坐标,便于使用
auto GetHeight() const
获取图像的高度(以像素为单位)
std::vector< short > ToArrayPol() const
获取所有事件的极性,便于使用
auto GetFOVAngle() const
获取图像的水平视野角度(以度为单位)
auto GetWidth() const
获取图像的宽度(以像素为单位)
序列化 DVS 摄像机传感器生成的事件数组。
static const DVSHeader & DeserializeHeader(const RawData &data)
CARLA模拟器的主命名空间。
Definition Carla.cpp:139