OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
space-time.hpp
Go to the documentation of this file.
1
6#ifndef OPENEV_REPRESENTATIONS_SPACE_TIME_HPP
7#define OPENEV_REPRESENTATIONS_SPACE_TIME_HPP
8
11#include <opencv2/core/hal/interface.h>
12#include <opencv2/core/mat.hpp>
13#include <opencv2/core/matx.hpp>
14#include <opencv2/core/types.hpp>
15#include <opencv2/viz/types.hpp>
16#include <vector>
17
18namespace ev {
19[[maybe_unused]] constexpr bool USING_SPACE_TIME_HPP = true;
20
22template <typename T>
23class Event_;
25
51template <typename T, const RepresentationOptions Options = RepresentationOptions::NONE, typename E = int>
52class SpaceTime_ : public EventImage_<T, Options, E> {
53public:
54 static constexpr double DEFAULT_YAW = 30.0;
55 static constexpr double DEFAULT_PITCH = 20.0;
56 static constexpr double DEFAULT_DEPTH = 1.0;
57 static constexpr double DISTANCE = 2.5;
58 static constexpr int MARGIN = 2;
59 static constexpr double LABEL_SCALE = 0.35;
60 static constexpr double DEFAULT_AXES_LENGTH = 0.25;
61 static constexpr double DEFAULT_FADE = 0.8;
62
68 explicit SpaceTime_(const cv::Size canvas, const cv::Size sensor = cv::Size());
69
75 void setView(const double yaw, const double pitch);
76
81 void setDepth(const double depth);
82
88 inline void showAxes(const bool state, const double length = DEFAULT_AXES_LENGTH) {
89 axes_ = state;
90 axesLength_ = std::clamp(length, 0.0, 1.0);
91 }
92
98 inline void fadeWithDepth(const bool state, const double strength = DEFAULT_FADE) {
99 fade_ = state;
100 fadeStrength_ = std::clamp(strength, 0.0, 1.0);
101 }
102
107 inline void setAxesValue(const typename TypeHelper<T>::Type &value) {
108 axesValue_ = value;
109 }
110
115 inline void setAxesColor(const cv::viz::Color &color) {
116 axesValue_ = TypeHelper<T>::convert(color);
117 }
118
123 [[nodiscard]] inline double yaw() const {
124 return yaw_;
125 }
126
131 [[nodiscard]] inline double pitch() const {
132 return pitch_;
133 }
134
139 [[nodiscard]] inline cv::Size sensorSize() const {
140 return sensor_;
141 }
142
149 [[nodiscard]] cv::Point2d project(const Event_<E> &e, const double age) const;
150
155 cv::Mat &render();
156
157private:
158 cv::Size sensor_;
159 double yaw_{DEFAULT_YAW};
160 double pitch_{DEFAULT_PITCH};
161 double depth_{DEFAULT_DEPTH};
162 cv::Matx33d rotation_;
163 double scale_{1};
164 cv::Point2d center_;
165 std::vector<Event_<E>> events_;
166 cv::Mat frame_;
167 cv::Mat backdrop_;
168 bool axes_{false};
169 double axesLength_{DEFAULT_AXES_LENGTH};
170 bool fade_{false};
171 double fadeStrength_{DEFAULT_FADE};
172 typename TypeHelper<T>::Type axesValue_ = TypeHelper<T>::convert(cv::viz::Color::white());
173
174 void fit_();
175 void warp_();
176 void drawAxes_();
177 [[nodiscard]] typename TypeHelper<T>::Type faded_(const typename TypeHelper<T>::Type &value, const cv::Point &pixel, const double age) const;
178 [[nodiscard]] cv::Point2d corner_(const double x, const double y, const double age) const;
179 [[nodiscard]] cv::Point2d project_(const cv::Point3d &point) const;
180
181 [[nodiscard]] cv::Size frameSize_() const override {
182 return sensor_;
183 }
184
185 void clear_() override;
186 void clear_(const cv::Mat &background) override;
187 bool insert_(const Event_<E> &e) override;
188};
204} // namespace ev
205
207#include "openev/representations/space-time.tpp"
209
210#endif // OPENEV_REPRESENTATIONS_SPACE_TIME_HPP
Event abstract representation.
This class extends cv::Point_<T> for event data. For more information, please refer here.
Definition types.hpp:86
This class extends ev::EventImage_<T> to draw the events as a cloud in the x-y-t volume seen in persp...
Definition space-time.hpp:52
cv::Point2d project(const Event_< E > &e, const double age) const
Project an event onto the canvas with the current view.
cv::Mat & render()
Render the space-time view.
void setAxesColor(const cv::viz::Color &color)
Set the colour the axes are drawn with. For more information, please refer here.
Definition space-time.hpp:115
void setDepth(const double depth)
Set the depth of the box, that is, how long the time axis is drawn.
void showAxes(const bool state, const double length=DEFAULT_AXES_LENGTH)
Draw the x, y and t axes from the sensor origin, labelled at their ends.
Definition space-time.hpp:88
void setView(const double yaw, const double pitch)
Set the view angles.
cv::Size sensorSize() const
Sensor size.
Definition space-time.hpp:139
double yaw() const
Definition space-time.hpp:123
void fadeWithDepth(const bool state, const double strength=DEFAULT_FADE)
Fade the events towards the background as they recede, so the depth shows.
Definition space-time.hpp:98
double pitch() const
Definition space-time.hpp:131
void setAxesValue(const typename TypeHelper< T >::Type &value)
Set the value the axes are drawn with.
Definition space-time.hpp:107
SpaceTime_(const cv::Size canvas, const cv::Size sensor=cv::Size())
Construct the canvas.
Event images.
SpaceTime_< cv::Vec3s > SpaceTime3s
Definition space-time.hpp:192
SpaceTime_< cv::Vec3f > SpaceTime3f
Definition space-time.hpp:198
SpaceTime_< cv::Vec3i > SpaceTime3i
Definition space-time.hpp:196
SpaceTime_< cv::Vec3b > SpaceTime3b
Definition space-time.hpp:190
SpaceTime1 SpaceTime
Definition space-time.hpp:203
SpaceTime_< ushort > SpaceTime1w
Definition space-time.hpp:193
SpaceTime_< short > SpaceTime1s
Definition space-time.hpp:191
SpaceTime_< uchar > SpaceTime1b
Definition space-time.hpp:189
SpaceTime1b SpaceTime1
Definition space-time.hpp:201
SpaceTime_< cv::Vec3d > SpaceTime3d
Definition space-time.hpp:200
SpaceTime_< int > SpaceTime1i
Definition space-time.hpp:195
SpaceTime3b SpaceTime3
Definition space-time.hpp:202
SpaceTime_< cv::Vec3w > SpaceTime3w
Definition space-time.hpp:194
SpaceTime_< double > SpaceTime1d
Definition space-time.hpp:199
SpaceTime_< float > SpaceTime1f
Definition space-time.hpp:197