OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
vector.hpp
Go to the documentation of this file.
1
6#ifndef OPENEV_CONTAINERS_VECTOR_HPP
7#define OPENEV_CONTAINERS_VECTOR_HPP
8
10#include <numeric>
11#include <opencv2/core/types.hpp>
12#include <vector>
13
14namespace ev {
15constexpr bool USING_VECTOR_HPP = true;
16
22template <typename T>
23class Vector_ : public std::vector<Event_<T>> {
24 using std::vector<Event_<T>>::vector;
25 using ResultType = TimeType;
26
27public:
32 [[nodiscard]] inline ResultType duration() const {
33 return std::vector<ev::Event_<T>>::back().t - std::vector<ev::Event_<T>>::front().t;
34 }
35
40 [[nodiscard]] inline ResultType rate() const {
41 return std::vector<ev::Event_<T>>::size() / duration();
42 }
43
48 [[nodiscard]] inline Event_<ResultType> mean() const {
49 const ResultType x = std::accumulate(std::vector<ev::Event_<T>>::begin(), std::vector<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.x; }) / std::vector<ev::Event_<T>>::size();
50 const ResultType y = std::accumulate(std::vector<ev::Event_<T>>::begin(), std::vector<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.y; }) / std::vector<ev::Event_<T>>::size();
51 const ResultType t = std::accumulate(std::vector<ev::Event_<T>>::begin(), std::vector<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.t; }) / std::vector<ev::Event_<T>>::size();
52 const ResultType p = std::accumulate(std::vector<ev::Event_<T>>::begin(), std::vector<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.p; }) / std::vector<ev::Event_<T>>::size();
53 return {x, y, t, p > 0.5};
54 }
55
60 [[nodiscard]] inline cv::Point_<ResultType> meanPoint() const {
61 const ResultType x = std::accumulate(std::vector<ev::Event_<T>>::begin(), std::vector<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.x; }) / std::vector<ev::Event_<T>>::size();
62 const ResultType y = std::accumulate(std::vector<ev::Event_<T>>::begin(), std::vector<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.y; }) / std::vector<ev::Event_<T>>::size();
63 return {x, y};
64 }
65
70 [[nodiscard]] inline ResultType meanTime() const {
71 return std::accumulate(std::vector<ev::Event_<T>>::begin(), std::vector<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.t; }) / std::vector<ev::Event_<T>>::size();
72 }
73
78 [[nodiscard]] inline ResultType midTime() const {
79 return 0.5 * (std::vector<ev::Event_<T>>::front().t + std::vector<ev::Event_<T>>::back().t);
80 }
81};
86using Vector = Vectori;
87} // namespace ev
88
89#endif // OPENEV_CONTAINERS_VECTOR_HPP
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
This class extends std::vector to implement event vectors. For more information, please refer here.
Definition vector.hpp:23
ResultType midTime() const
Calculate the midpoint time between the oldest and the newest event.
Definition vector.hpp:78
Event_< ResultType > mean() const
Compute the mean of the events.
Definition vector.hpp:48
ResultType rate() const
Compute event rate as the ratio between the number of events and the time difference between the last...
Definition vector.hpp:40
ResultType meanTime() const
Compute the mean time of the events.
Definition vector.hpp:70
cv::Point_< ResultType > meanPoint() const
Compute the mean x,y point of the events.
Definition vector.hpp:60
ResultType duration() const
Time difference between the last and the first event.
Definition vector.hpp:32
Basic event-based vision structures based on OpenCV components.
Vector_< double > Vectord
Definition vector.hpp:85
Vector_< float > Vectorf
Definition vector.hpp:84
Vector_< long > Vectorl
Definition vector.hpp:83
Vectori Vector
Definition vector.hpp:86
Vector_< int > Vectori
Definition vector.hpp:82