CARLA
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"
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> {
22  protected:
23 
25 
26  friend Serializer;
27 
29  : Super(Serializer::header_offset, std::move(data)) {
30  }
31 
32  private:
33 
34  const auto &GetHeader() const {
36  }
37  public:
38 
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
const RawData & GetRawData() const
Definition: Array.h:139
std::vector< std::uint16_t > ToArrayX() const
Get all events&#39; x coordinate for convenience.
Definition: DVSEventArray.h:82
An array of DVS Events in an image structure HxW.
Definition: DVSEventArray.h:20
std::vector< std::uint16_t > ToArrayY() const
Get all events&#39; y coordinate for convenience.
Definition: DVSEventArray.h:91
std::vector< std::vector< std::int64_t > > ToArray() const
Get the array of events in pure vector format.
Definition: DVSEventArray.h:73
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
const auto & GetHeader() const
Definition: DVSEventArray.h:34
std::vector< short > ToArrayPol() const
Get all events&#39; polarity for convenience.
static const DVSHeader & DeserializeHeader(const RawData &data)
std::vector< std::int64_t > ToArrayT() const
Get all events&#39; timestamp for convenience.
Base class for all the sensor data consisting of an array of items.
Definition: Array.h:23
auto GetFOVAngle() const
Get horizontal field of view of the image in degrees.
Definition: DVSEventArray.h:52
std::vector< Color > ToImage() const
Get an event "frame" image for visualization.
Definition: DVSEventArray.h:57
auto GetHeight() const
Get image height in pixels.
Definition: DVSEventArray.h:47
auto GetWidth() const
Get image width in pixels.
Definition: DVSEventArray.h:42
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition: RawData.h:21
Serializes events array generated by DVS camera sensors.