OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
vector.hpp
1
6#ifndef OPENEV_CONTAINERS_VECTOR_HPP
7#define OPENEV_CONTAINERS_VECTOR_HPP
8
9#include "openev/containers/array.hpp"
11#include "openev/core/types.hpp"
12#include <cstddef>
13#include <numeric>
14#include <utility>
15#include <vector>
16
17namespace ev {
19#ifndef OPENEV_ARRAY_HPP
20template <typename T, std::size_t N>
21class Array_;
22#endif
23
24#ifndef OPENEV_QUEUE_HPP
25template <typename T>
26class Queue_;
27#endif
35template <typename T>
36class Vector_ : public std::vector<Event_<T>> {
37 using std::vector<Event_<T>>::vector;
38
39public:
41 inline void push_back(const Event_<T> &e) {
42 std::vector<Event_<T>>::push_back(e);
43 }
50 template <std::size_t N>
51 inline void push_back(const Array_<T, N> &array) {
52 std::vector<Event_<T>>::reserve(std::vector<Event_<T>>::size() + array.size());
53 std::vector<Event_<T>>::insert(std::vector<Event_<T>>::end(), array.begin(), array.end());
54 }
55
60 [[nodiscard]] inline double duration() const {
61 return std::vector<Event_<T>>::back().t - std::vector<Event_<T>>::front().t;
62 }
63
68 [[nodiscard]] inline double rate() const {
69 return std::vector<Event_<T>>::size() / duration();
70 }
71
76 [[nodiscard]] Eventd mean() const {
77 const double x = std::accumulate(std::vector<Event_<T>>::begin(), std::vector<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.x; }) / std::vector<Event_<T>>::size();
78 const double y = std::accumulate(std::vector<Event_<T>>::begin(), std::vector<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.y; }) / std::vector<Event_<T>>::size();
79 const double t = std::accumulate(std::vector<Event_<T>>::begin(), std::vector<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.t; }) / std::vector<Event_<T>>::size();
80 const double p = std::accumulate(std::vector<Event_<T>>::begin(), std::vector<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.p; }) / std::vector<Event_<T>>::size();
81 return {x, y, t, p > 0.5};
82 }
83
88 [[nodiscard]] inline cv::Point2d meanPoint() const {
89 const double x = std::accumulate(std::vector<Event_<T>>::begin(), std::vector<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.x; }) / std::vector<Event_<T>>::size();
90 const double y = std::accumulate(std::vector<Event_<T>>::begin(), std::vector<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.y; }) / std::vector<Event_<T>>::size();
91 return {x, y};
92 }
93
98 [[nodiscard]] inline double meanTime() const {
99 return std::accumulate(std::vector<Event_<T>>::begin(), std::vector<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.t; }) / std::vector<Event_<T>>::size();
100 }
101
106 [[nodiscard]] inline double midTime() const {
107 return 0.5 * (std::vector<Event_<T>>::front().t + std::vector<Event_<T>>::back().t);
108 }
109};
110using Vectori = Vector_<int>;
111using Vectorl = Vector_<long>;
112using Vectorf = Vector_<float>;
113using Vectord = Vector_<double>;
114using Vector = Vectori;
115} // namespace ev
116
117#endif // OPENEV_CONTAINERS_VECTOR_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::vector to implement event vectors. For more information, please refer here.
Definition vector.hpp:36
double midTime() const
Calculate the midpoint time between the oldest and the newest event.
Definition vector.hpp:106
double rate() const
Compute event rate as the ratio between the number of events and the time difference between the last...
Definition vector.hpp:68
double duration() const
Time difference between the last and the first event.
Definition vector.hpp:60
double meanTime() const
Compute the mean time of the events.
Definition vector.hpp:98
Eventd mean() const
Compute the mean of the events.
Definition vector.hpp:76
void push_back(const Array_< T, N > &array)
Push back elements from an array of events.
Definition vector.hpp:51
cv::Point2d meanPoint() const
Compute the mean x,y point of the events.
Definition vector.hpp:88
Queue container for basic event structures.
Basic event-based vision structures based on OpenCV components.