OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
array.hpp
1
6#ifndef OPENEV_CONTAINERS_ARRAY_HPP
7#define OPENEV_CONTAINERS_ARRAY_HPP
8
10#include <array>
11#include <cstddef>
12#include <numeric>
13
14namespace ev {
20template <typename T, std::size_t N>
21class Array_ : public std::array<Event_<T>, N> {
22 using std::array<Event_<T>, N>::array;
23
24public:
29 [[nodiscard]] inline double duration() const {
30 return std::array<Event_<T>, N>::back().t - std::array<Event_<T>, N>::front().t;
31 }
32
37 [[nodiscard]] inline double rate() const {
38 return std::array<Event_<T>, N>::size() / duration();
39 }
40
45 [[nodiscard]] Eventd mean() const {
46 const double x = std::accumulate(std::array<Event_<T>, N>::begin(), std::array<Event_<T>, N>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.x; }) / N;
47 const double y = std::accumulate(std::array<Event_<T>, N>::begin(), std::array<Event_<T>, N>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.y; }) / N;
48 const double t = std::accumulate(std::array<Event_<T>, N>::begin(), std::array<Event_<T>, N>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.t; }) / N;
49 const double p = std::accumulate(std::array<Event_<T>, N>::begin(), std::array<Event_<T>, N>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.p; }) / N;
50 return {x, y, t, p > 0.5};
51 }
52
57 [[nodiscard]] inline cv::Point2d meanPoint() const {
58 const double x = std::accumulate(std::array<Event_<T>, N>::begin(), std::array<Event_<T>, N>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.x; }) / N;
59 const double y = std::accumulate(std::array<Event_<T>, N>::begin(), std::array<Event_<T>, N>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.y; }) / N;
60 return {x, y};
61 }
62
67 [[nodiscard]] inline double meanTime() const {
68 return std::accumulate(std::array<Event_<T>, N>::begin(), std::array<Event_<T>, N>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.t; }) / N;
69 }
70
75 [[nodiscard]] inline double midTime() const {
76 return 0.5 * (std::array<Event_<T>, N>::front().t + std::array<Event_<T>, N>::back().t);
77 }
78};
79template <std::size_t N>
80using Arrayi = Array_<int, N>;
81template <std::size_t N>
82using Arrayl = Array_<long, N>;
83template <std::size_t N>
84using Arrayf = Array_<float, N>;
85template <std::size_t N>
86using Arrayd = Array_<double, N>;
87template <std::size_t N>
88using Array = Arrayi<N>;
89} // namespace ev
90
91#endif // OPENEV_CONTAINERS_ARRAY_HPP
This class extends std::array to implement event arrays. For more information, please refer here.
Definition array.hpp:21
Eventd mean() const
Compute the mean of the events.
Definition array.hpp:45
double duration() const
Time difference between the last and the first event.
Definition array.hpp:29
cv::Point2d meanPoint() const
Compute the mean x,y point of the events.
Definition array.hpp:57
double midTime() const
Calculate the midpoint time between the oldest and the newest event.
Definition array.hpp:75
double meanTime() const
Compute the mean time of the events.
Definition array.hpp:67
double rate() const
Compute event rate as the ratio between the number of events and the time difference between the last...
Definition array.hpp:37
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
Basic event-based vision structures based on OpenCV components.