OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
deque.hpp
Go to the documentation of this file.
1
6#ifndef OPENEV_CONTAINERS_DEQUE_HPP
7#define OPENEV_CONTAINERS_DEQUE_HPP
8
9#include "openev/containers/array.hpp"
10#include "openev/containers/vector.hpp"
11#include "openev/core/types.hpp"
12#include <cstddef>
13#include <deque>
14#include <utility>
15
16namespace ev {
18#ifndef OPENEV_ARRAY_HPP
19template <typename T, std::size_t N>
20class Array_;
21#endif
22
23#ifndef OPENEV_VECTOR_HPP
24template <typename T>
25class Vector_;
26#endif
34template <typename T>
35class Deque_ : public std::deque<Event_<T>> {
36 using std::deque<Event_<T>>::deque;
37
38public:
40 inline void push_back(const Event_<T> &e) {
41 std::deque<Event_<T>>::push_back(e);
42 }
49 template <std::size_t N>
50 inline void push_back(const Array_<T, N> &array) {
51 std::deque<Event_<T>>::insert(std::deque<Event_<T>>::end(), array.begin(), array.end());
52 }
53
58 inline void push_back(const Vector_<T> &vector) {
59 std::deque<Event_<T>>::insert(std::deque<Event_<T>>::end(), vector.begin(), vector.end());
60 }
61
66 [[nodiscard]] inline double duration() const {
67 return std::deque<Event_<T>>::back().t - std::deque<Event_<T>>::front().t;
68 }
69
74 [[nodiscard]] inline double rate() const {
75 return std::deque<Event_<T>>::size() / duration();
76 }
77
82 [[nodiscard]] Eventd mean() {
83 const double x = std::accumulate(std::deque<Event_<T>>::begin(), std::deque<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.x; }) / std::deque<Event_<T>>::size();
84 const double y = std::accumulate(std::deque<Event_<T>>::begin(), std::deque<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.y; }) / std::deque<Event_<T>>::size();
85 const double t = std::accumulate(std::deque<Event_<T>>::begin(), std::deque<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.t; }) / std::deque<Event_<T>>::size();
86 const double p = std::accumulate(std::deque<Event_<T>>::begin(), std::deque<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.p; }) / std::deque<Event_<T>>::size();
87 return {x, y, t, p > 0.5};
88 }
89
94 [[nodiscard]] inline cv::Point2d meanPoint() {
95 const double x = std::accumulate(std::deque<Event_<T>>::begin(), std::deque<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.x; }) / std::deque<Event_<T>>::size();
96 const double y = std::accumulate(std::deque<Event_<T>>::begin(), std::deque<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.y; }) / std::deque<Event_<T>>::size();
97 return {x, y};
98 }
99
104 [[nodiscard]] inline double meanTime() {
105 return std::accumulate(std::deque<Event_<T>>::begin(), std::deque<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.t; }) / std::deque<Event_<T>>::size();
106 }
107
112 [[nodiscard]] inline double midTime() const {
113 return 0.5 * (std::deque<Event_<T>>::front().t + std::deque<Event_<T>>::back().t);
114 }
115};
120using Deque = Dequei;
121} // namespace ev
122
123#endif // OPENEV_CONTAINERS_DEQUE_HPP
This class extends std::array to implement event arrays. For more information, please refer here.
Definition array.hpp:21
This class extends std::deque to implement event deques. For more information, please refer here.
Definition deque.hpp:35
void push_back(const Vector_< T > &vector)
Push elements from a vector of events.
Definition deque.hpp:58
cv::Point2d meanPoint()
Compute the mean x,y point of the events.
Definition deque.hpp:94
void push_back(const Array_< T, N > &array)
Push elements from an array of events.
Definition deque.hpp:50
double rate() const
Compute event rate as the ratio between the number of events and the time difference between the last...
Definition deque.hpp:74
Eventd mean()
Compute the mean of the events.
Definition deque.hpp:82
double duration() const
Time difference between the last and the first event.
Definition deque.hpp:66
double meanTime()
Compute the mean time of the events.
Definition deque.hpp:104
double midTime() const
Calculate the midpoint time between the oldest and the newest event.
Definition deque.hpp:112
This class extends cv::Point_<T> for event data. For more information, please refer here.
Definition types.hpp:60
bool p
Definition types.hpp:63
double t
Definition types.hpp:62
This class extends std::vector to implement event vectors. For more information, please refer here.
Definition vector.hpp:36
Basic event-based vision structures based on OpenCV components.