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<T, N> {
22 using std::array<T, N>::array;
23
24public:
29 [[nodiscard]] inline double duration() const {
30 return (std::array<T, N>::back()).t - (std::array<T, N>::front()).t;
31 }
32
37 [[nodiscard]] inline double rate() const {
38 return std::array<T, N>::size() / duration();
39 }
40
45 [[nodiscard]] Eventd mean() const {
46 double x = 0.0;
47 double y = 0.0;
48 double t = 0.0;
49 double p = 0.0;
50
51 for(const T &e : *this) {
52 x += static_cast<double>(e.x);
53 y += static_cast<double>(e.y);
54 t += static_cast<double>(e.t);
55 p += static_cast<double>(e.p);
56 }
57
58 return {x / N, y / N, t / N, p / N >= 0.5};
59 }
60
65 [[nodiscard]] inline double meanTime() const {
66 return std::accumulate(std::array<T, N>::begin(), std::array<T, N>::end(), 0.0, [](double sum, const T &e) { return sum + e.t; }) / N;
67 }
68};
69template <std::size_t N>
70using Arrayi = Array_<Eventi, N>;
71template <std::size_t N>
72using Arrayl = Array_<Eventl, N>;
73template <std::size_t N>
74using Arrayf = Array_<Eventf, N>;
75template <std::size_t N>
76using Arrayd = Array_<Eventd, N>;
77template <std::size_t N>
78using Array = Array_<Event, N>;
79template <std::size_t N>
80using AugmentedArrayi = Array_<AugmentedEventi, N>;
81template <std::size_t N>
82using AugmentedArrayl = Array_<AugmentedEventl, N>;
83template <std::size_t N>
84using AugmentedArrayf = Array_<AugmentedEventf, N>;
85template <std::size_t N>
86using AugmentedArrayd = Array_<AugmentedEventd, N>;
87template <std::size_t N>
88using AugmentedArray = Array_<AugmentedEvent, 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 in the array.
Definition array.hpp:45
double duration() const
Time difference between the last and the first event in the array.
Definition array.hpp:29
double meanTime() const
Compute the mean time of the events in the array.
Definition array.hpp:65
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
Basic event-based vision structures based on OpenCV components.