OpenEV
Extending OpenCV to event-based vision
Loading...
Searching...
No Matches
circular.hpp
Go to the documentation of this file.
1
6#ifndef OPENEV_CONTAINERS_CIRCULAR_HPP
7#define OPENEV_CONTAINERS_CIRCULAR_HPP
8
10#include <boost/circular_buffer.hpp>
11#include <numeric>
12#include <opencv2/core/types.hpp>
13#include <utility>
14
15namespace ev {
16constexpr bool USING_CIRCULAR_HPP = true;
17
23template <typename T>
24class CircularBuffer_ : public boost::circular_buffer<Event_<T>> {
25 using boost::circular_buffer<Event_<T>>::circular_buffer;
26 using ResultType = TimeType;
27
28public:
35 template <typename... Args>
36 inline void emplace_back(Args &&...args) {
37 boost::circular_buffer<Event_<T>>::push_back(Event_<T>(std::forward<Args>(args)...));
38 }
39
46 template <typename... Args>
47 inline void emplace_front(Args &&...args) {
48 boost::circular_buffer<Event_<T>>::push_front(Event_<T>(std::forward<Args>(args)...));
49 }
50
55 [[nodiscard]] inline ResultType duration() const {
56 return boost::circular_buffer<ev::Event_<T>>::back().t - boost::circular_buffer<ev::Event_<T>>::front().t;
57 }
58
63 [[nodiscard]] inline ResultType rate() const {
64 return boost::circular_buffer<ev::Event_<T>>::size() / duration();
65 }
66
71 [[nodiscard]] inline Event_<ResultType> mean() const {
72 const ResultType x = std::accumulate(boost::circular_buffer<ev::Event_<T>>::begin(), boost::circular_buffer<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.x; }) / boost::circular_buffer<ev::Event_<T>>::size();
73 const ResultType y = std::accumulate(boost::circular_buffer<ev::Event_<T>>::begin(), boost::circular_buffer<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.y; }) / boost::circular_buffer<ev::Event_<T>>::size();
74 const ResultType t = std::accumulate(boost::circular_buffer<ev::Event_<T>>::begin(), boost::circular_buffer<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.t; }) / boost::circular_buffer<ev::Event_<T>>::size();
75 const ResultType p = std::accumulate(boost::circular_buffer<ev::Event_<T>>::begin(), boost::circular_buffer<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.p; }) / boost::circular_buffer<ev::Event_<T>>::size();
76 return {x, y, t, p > 0.5};
77 }
78
83 [[nodiscard]] inline cv::Point_<ResultType> meanPoint() const {
84 const ResultType x = std::accumulate(boost::circular_buffer<ev::Event_<T>>::begin(), boost::circular_buffer<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.x; }) / boost::circular_buffer<ev::Event_<T>>::size();
85 const ResultType y = std::accumulate(boost::circular_buffer<ev::Event_<T>>::begin(), boost::circular_buffer<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.y; }) / boost::circular_buffer<ev::Event_<T>>::size();
86 return {x, y};
87 }
88
93 [[nodiscard]] inline ResultType meanTime() const {
94 return std::accumulate(boost::circular_buffer<ev::Event_<T>>::begin(), boost::circular_buffer<ev::Event_<T>>::end(), 0.0, [](ResultType sum, const Event_<T> &e) { return sum + e.t; }) / boost::circular_buffer<ev::Event_<T>>::size();
95 }
96
101 [[nodiscard]] inline ResultType midTime() const {
102 return 0.5 * (boost::circular_buffer<ev::Event_<T>>::front().t + boost::circular_buffer<ev::Event_<T>>::back().t);
103 }
104};
110} // namespace ev
111
112#endif // OPENEV_CONTAINERS_CIRCULAR_HPP
CircularBufferi CircularBuffer
Definition circular.hpp:109
CircularBuffer_< float > CircularBufferf
Definition circular.hpp:107
CircularBuffer_< long > CircularBufferl
Definition circular.hpp:106
CircularBuffer_< int > CircularBufferi
Definition circular.hpp:105
CircularBuffer_< double > CircularBufferd
Definition circular.hpp:108
This class extends boost::circular_buffer to implement event circular buffers. For more information,...
Definition circular.hpp:24
Event_< ResultType > mean() const
Compute the mean of the events.
Definition circular.hpp:71
ResultType meanTime() const
Compute the mean time of the events.
Definition circular.hpp:93
void emplace_front(Args &&...args)
Construct an Event_<T> in-place at the front of the buffer.
Definition circular.hpp:47
void emplace_back(Args &&...args)
Construct an Event_<T> in-place at the back of the buffer.
Definition circular.hpp:36
ResultType duration() const
Time difference between the last and the first event.
Definition circular.hpp:55
cv::Point_< ResultType > meanPoint() const
Compute the mean x,y point of the events.
Definition circular.hpp:83
ResultType rate() const
Compute event rate as the ratio between the number of events and the time difference between the last...
Definition circular.hpp:63
ResultType midTime() const
Calculate the midpoint time between the oldest and the newest event.
Definition circular.hpp:101
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.