OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
array.hpp
Go to the documentation of this file.
1
6#ifndef OPENEV_CONTAINERS_ARRAY_HPP
7#define OPENEV_CONTAINERS_ARRAY_HPP
8
10#include <array>
11#include <cstddef>
12#include <numeric>
13#include <opencv2/core/types.hpp>
14
15namespace ev {
16constexpr bool USING_ARRAY_HPP = true;
17
23template <typename T, std::size_t N>
24class Array_ : public std::array<Event_<T>, N> {
25 using std::array<Event_<T>, N>::array;
26 using ResultType = TimeType;
27
28public:
33 [[nodiscard]] inline ResultType duration() const {
34 return std::array<ev::Event_<T>, N>::back().t - std::array<ev::Event_<T>, N>::front().t;
35 }
36
41 [[nodiscard]] inline ResultType rate() const {
42 return std::array<ev::Event_<T>, N>::size() / duration();
43 }
44
49 [[nodiscard]] inline Event_<ResultType> mean() const {
50 const ResultType x = std::accumulate(std::array<ev::Event_<T>, N>::begin(), std::array<ev::Event_<T>, N>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.x; }) / N;
51 const ResultType y = std::accumulate(std::array<ev::Event_<T>, N>::begin(), std::array<ev::Event_<T>, N>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.y; }) / N;
52 const ResultType t = std::accumulate(std::array<ev::Event_<T>, N>::begin(), std::array<ev::Event_<T>, N>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.t; }) / N;
53 const ResultType p = std::accumulate(std::array<ev::Event_<T>, N>::begin(), std::array<ev::Event_<T>, N>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.p; }) / N;
54 return {x, y, t, p > 0.5};
55 }
56
61 [[nodiscard]] inline cv::Point_<ResultType> meanPoint() const {
62 const ResultType x = std::accumulate(std::array<ev::Event_<T>, N>::begin(), std::array<ev::Event_<T>, N>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.x; }) / N;
63 const ResultType y = std::accumulate(std::array<ev::Event_<T>, N>::begin(), std::array<ev::Event_<T>, N>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.y; }) / N;
64 return {x, y};
65 }
66
71 [[nodiscard]] inline ResultType meanTime() const {
72 return std::accumulate(std::array<ev::Event_<T>, N>::begin(), std::array<ev::Event_<T>, N>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.t; }) / N;
73 }
74
79 [[nodiscard]] inline ResultType midTime() const {
80 return 0.5 * (std::array<ev::Event_<T>, N>::front().t + std::array<ev::Event_<T>, N>::back().t);
81 }
82};
83
84template <std::size_t N>
86template <std::size_t N>
88template <std::size_t N>
90template <std::size_t N>
92template <std::size_t N>
94} // namespace ev
95
96#endif // OPENEV_CONTAINERS_ARRAY_HPP
Array_< long, N > Arrayl
Definition array.hpp:87
Array_< float, N > Arrayf
Definition array.hpp:89
Array_< double, N > Arrayd
Definition array.hpp:91
Arrayi< N > Array
Definition array.hpp:93
Array_< int, N > Arrayi
Definition array.hpp:85
This class extends std::array to implement event arrays. For more information, please refer here.
Definition array.hpp:24
ResultType rate() const
Definition array.hpp:41
ResultType duration() const
Definition array.hpp:33
Event_< ResultType > mean() const
Definition array.hpp:49
ResultType midTime() const
Definition array.hpp:79
ResultType meanTime() const
Definition array.hpp:71
cv::Point_< ResultType > meanPoint() const
Definition array.hpp:61
This class extends cv::Point_<T> for event data. For more information, please refer here.
Definition types.hpp:77
PolarityType p
Definition types.hpp:80
TimeType t
Definition types.hpp:79
Basic event-based vision structures based on OpenCV components.