CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
sensor
data
DVSEventArray.h
Go to the documentation of this file.
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
"
12
#include "
carla/sensor/data/Color.h
"
13
#include "
carla/sensor/s11n/DVSEventArraySerializer.h
"
14
15
namespace
carla
{
16
namespace
sensor
{
17
namespace
data
{
18
19
/// An array of DVS Events in an image structure HxW
20
class
DVSEventArray
:
public
Array
<DVSEvent> {
21
using
Super
=
Array<DVSEvent>
;
22
protected
:
23
24
using
Serializer
=
s11n::DVSEventArraySerializer
;
25
26
friend
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
;
40
41
/// Get image width in pixels.
42
auto
GetWidth
()
const
{
43
return
GetHeader
().width;
44
}
45
46
/// Get image height in pixels.
47
auto
GetHeight
()
const
{
48
return
GetHeader
().height;
49
}
50
51
/// Get horizontal field of view of the image in degrees.
52
auto
GetFOVAngle
()
const
{
53
return
GetHeader
().fov_angle;
54
}
55
56
/// Get an event "frame" image for visualization
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
// Blue is positive
63
img[index].b = 255u;
64
}
else
{
65
// Red is negative
66
img[index].r = 255u;
67
}
68
}
69
return
img;
70
}
71
72
/// Get the array of events in pure vector format
73
std::vector<std::vector<std::int64_t>>
ToArray
()
const
{
74
std::vector<std::vector<std::int64_t>> array;
75
for
(
const
auto
&event : *
this
) {
76
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});
77
}
78
return
array;
79
}
80
81
/// Get all events' x coordinate for convenience
82
std::vector<std::uint16_t>
ToArrayX
()
const
{
83
std::vector<std::uint16_t> array;
84
for
(
const
auto
&event : *
this
) {
85
array.push_back(event.x);
86
}
87
return
array;
88
}
89
90
/// Get all events' y coordinate for convenience
91
std::vector<std::uint16_t>
ToArrayY
()
const
{
92
std::vector<std::uint16_t> array;
93
for
(
const
auto
&event : *
this
) {
94
array.push_back(event.y);
95
}
96
return
array;
97
}
98
99
/// Get all events' timestamp for convenience
100
std::vector<std::int64_t>
ToArrayT
()
const
{
101
std::vector<std::int64_t> array;
102
for
(
const
auto
&event : *
this
) {
103
array.push_back(event.t);
104
}
105
return
array;
106
}
107
108
/// Get all events' polarity for convenience
109
std::vector<short>
ToArrayPol
()
const
{
110
std::vector<short> array;
111
for
(
const
auto
&event : *
this
) {
112
array.push_back(2*
static_cast<
short
>
(event.pol) - 1);
113
}
114
return
array;
115
}
116
117
};
118
119
}
// namespace data
120
}
// namespace sensor
121
}
// namespace carla
Array.h
DVSEventArraySerializer.h
DVSEvent.h
Debug.h
carla::sensor::RawData
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition
RawData.h:21
carla::sensor::data::Array< DVSEvent >::Array
Array(RawData &&data, FuncT get_offset)
Definition
Array.h:127
carla::sensor::data::Array< DVSEvent >::GetRawData
const RawData & GetRawData() const
Definition
Array.h:139
carla::sensor::data::Array< DVSEvent >::data
value_type * data()
Definition
Array.h:94
carla::sensor::data::DVSEventArray::ToArrayX
std::vector< std::uint16_t > ToArrayX() const
Get all events' x coordinate for convenience.
Definition
DVSEventArray.h:82
carla::sensor::data::DVSEventArray::GetHeader
const auto & GetHeader() const
Definition
DVSEventArray.h:34
carla::sensor::data::DVSEventArray::ToArray
std::vector< std::vector< std::int64_t > > ToArray() const
Get the array of events in pure vector format.
Definition
DVSEventArray.h:73
carla::sensor::data::DVSEventArray::Super
Array< DVSEvent > Super
Definition
DVSEventArray.h:21
carla::sensor::data::DVSEventArray::ToArrayT
std::vector< std::int64_t > ToArrayT() const
Get all events' timestamp for convenience.
Definition
DVSEventArray.h:100
carla::sensor::data::DVSEventArray::ToImage
std::vector< Color > ToImage() const
Get an event "frame" image for visualization.
Definition
DVSEventArray.h:57
carla::sensor::data::DVSEventArray::Serializer
s11n::DVSEventArraySerializer Serializer
Definition
DVSEventArray.h:24
carla::sensor::data::DVSEventArray::DVSEventArray
DVSEventArray(RawData &&data)
Definition
DVSEventArray.h:28
carla::sensor::data::DVSEventArray::event_type
DVSEvent event_type
Definition
DVSEventArray.h:39
carla::sensor::data::DVSEventArray::ToArrayY
std::vector< std::uint16_t > ToArrayY() const
Get all events' y coordinate for convenience.
Definition
DVSEventArray.h:91
carla::sensor::data::DVSEventArray::GetHeight
auto GetHeight() const
Get image height in pixels.
Definition
DVSEventArray.h:47
carla::sensor::data::DVSEventArray::ToArrayPol
std::vector< short > ToArrayPol() const
Get all events' polarity for convenience.
Definition
DVSEventArray.h:109
carla::sensor::data::DVSEventArray::GetFOVAngle
auto GetFOVAngle() const
Get horizontal field of view of the image in degrees.
Definition
DVSEventArray.h:52
carla::sensor::data::DVSEventArray::GetWidth
auto GetWidth() const
Get image width in pixels.
Definition
DVSEventArray.h:42
carla::sensor::s11n::DVSEventArraySerializer
Serializes events array generated by DVS camera sensors.
Definition
DVSEventArraySerializer.h:24
carla::sensor::s11n::DVSEventArraySerializer::DeserializeHeader
static const DVSHeader & DeserializeHeader(const RawData &data)
Definition
DVSEventArraySerializer.h:38
carla::sensor::data
Definition
ROS2.h:33
carla::sensor
Definition
client/detail/Client.h:58
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
std
Definition
CarlaRecorderCollision.h:31
Color.h
carla::sensor::data::DVSEvent
Definition
DVSEvent.h:16
Generated by
1.18.0