OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
queue.hpp
Go to the documentation of this file.
1
6#ifndef OPENEV_CONTAINERS_QUEUE_HPP
7#define OPENEV_CONTAINERS_QUEUE_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 <queue>
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 Queue_ : public std::queue<Event_<T>> {
36 using std::queue<Event_<T>>::queue;
37
38public:
40 inline void push(const Event_<T> &e) {
41 std::queue<Event_<T>>::push(e);
42 }
49 template <std::size_t N>
50 inline void push(const Array_<T, N> &array) {
51 for(const Event_<T> &e : array) {
52 std::queue<Event_<T>>::emplace(std::move(e));
53 }
54 }
55
60 inline void push(const Vector_<T> &vector) {
61 for(const Event_<T> &e : vector) {
62 std::queue<Event_<T>>::emplace(std::move(e));
63 }
64 }
65
70 [[nodiscard]] inline double duration() const {
71 return std::queue<Event_<T>>::back().t - std::queue<Event_<T>>::front().t;
72 }
73
78 [[nodiscard]] inline double rate() const {
79 return std::queue<Event_<T>>::size() / duration();
80 }
81
86 [[nodiscard]] Eventd mean() {
87 const std::size_t n = std::queue<Event_<T>>::size();
88 double x{0};
89 double y{0};
90 double t{0};
91 double p{0};
92
93 while(!std::queue<Event_<T>>::empty()) {
94 const Event_<T> &e = std::queue<Event_<T>>::front();
95 x += e.x;
96 y += e.y;
97 t += e.t;
98 p += e.p;
99 std::queue<Event_<T>>::pop();
100 }
101
102 return {x / n, y / n, t / n, p / n > 0.5};
103 }
104
109 [[nodiscard]] inline cv::Point2d meanPoint() {
110 const std::size_t n = std::queue<Event_<T>>::size();
111 double x{0};
112 double y{0};
113
114 while(!std::queue<Event_<T>>::empty()) {
115 const Event_<T> &e = std::queue<Event_<T>>::front();
116 x += e.x;
117 y += e.y;
118 std::queue<Event_<T>>::pop();
119 }
120
121 return {x / n, y / n};
122 }
123
128 [[nodiscard]] inline double meanTime() {
129 const std::size_t n = std::queue<Event_<T>>::size();
130 double t{0};
131
132 while(!std::queue<Event_<T>>::empty()) {
133 t += std::queue<Event_<T>>::front().t;
134 std::queue<Event_<T>>::pop();
135 }
136
137 return t / n;
138 }
139
144 [[nodiscard]] inline double midTime() const {
145 return 0.5 * (std::queue<Event_<T>>::front().t + std::queue<Event_<T>>::back().t);
146 }
147};
152using Queue = Queuei;
153} // namespace ev
154
155#endif // OPENEV_CONTAINERS_QUEUE_HPP
This class extends std::array to implement event arrays. For more information, please refer here.
Definition array.hpp:21
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::queue to implement event queues. For more information, please refer here.
Definition queue.hpp:35
double rate() const
Compute event rate as the ratio between the number of events and the time difference between the last...
Definition queue.hpp:78
void push(const Array_< T, N > &array)
Push elements from an array of events.
Definition queue.hpp:50
cv::Point2d meanPoint()
Compute the mean x,y point of the events.
Definition queue.hpp:109
double meanTime()
Compute the mean time of the events.
Definition queue.hpp:128
void push(const Vector_< T > &vector)
Push elements from a vector of events.
Definition queue.hpp:60
Eventd mean()
Compute the mean of the events.
Definition queue.hpp:86
double midTime() const
Calculate the midpoint time between the oldest and the newest event.
Definition queue.hpp:144
double duration() const
Time difference between the last and the first event.
Definition queue.hpp:70
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.