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 {
21template <typename T>
22class CircularBuffer_ : public boost::circular_buffer<Event_<T>> {
23 using boost::circular_buffer<Event_<T>>::circular_buffer;
24
25public:
27 template <typename... Args>
28 inline void emplace_back(Args &&...args) {
29 boost::circular_buffer<Event_<T>>::push_back(Event_<T>(std::forward<Args>(args)...));
30 }
31
32 template <typename... Args>
33 inline void emplace_front(Args &&...args) {
34 boost::circular_buffer<Event_<T>>::push_front(Event_<T>(std::forward<Args>(args)...));
35 }
37
42 [[nodiscard]] inline double duration() const {
43 return boost::circular_buffer<Event_<T>>::back().t - boost::circular_buffer<Event_<T>>::front().t;
44 }
45
50 [[nodiscard]] inline double rate() const {
51 return boost::circular_buffer<Event_<T>>::size() / duration();
52 }
53
58 [[nodiscard]] Eventd mean() const {
59 const double x = std::accumulate(boost::circular_buffer<Event_<T>>::begin(), boost::circular_buffer<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.x; }) / boost::circular_buffer<Event_<T>>::size();
60 const double y = std::accumulate(boost::circular_buffer<Event_<T>>::begin(), boost::circular_buffer<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.y; }) / boost::circular_buffer<Event_<T>>::size();
61 const double t = std::accumulate(boost::circular_buffer<Event_<T>>::begin(), boost::circular_buffer<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.t; }) / boost::circular_buffer<Event_<T>>::size();
62 const double p = std::accumulate(boost::circular_buffer<Event_<T>>::begin(), boost::circular_buffer<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.p; }) / boost::circular_buffer<Event_<T>>::size();
63 return {x, y, t, p > 0.5};
64 }
65
70 [[nodiscard]] inline cv::Point2d meanPoint() const {
71 const double x = std::accumulate(boost::circular_buffer<Event_<T>>::begin(), boost::circular_buffer<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.x; }) / boost::circular_buffer<Event_<T>>::size();
72 const double y = std::accumulate(boost::circular_buffer<Event_<T>>::begin(), boost::circular_buffer<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.y; }) / boost::circular_buffer<Event_<T>>::size();
73 return {x, y};
74 }
75
80 [[nodiscard]] inline double meanTime() const {
81 return std::accumulate(boost::circular_buffer<Event_<T>>::begin(), boost::circular_buffer<Event_<T>>::end(), 0.0, [](double sum, const Event_<T> &e) { return sum + e.t; }) / boost::circular_buffer<Event_<T>>::size();
82 }
83
88 [[nodiscard]] inline double midTime() const {
89 return 0.5 * (boost::circular_buffer<Event_<T>>::front().t + boost::circular_buffer<Event_<T>>::back().t);
90 }
91};
97} // namespace ev
98
99#endif // OPENEV_CONTAINERS_CIRCULAR_HPP
CircularBufferi CircularBuffer
Definition circular.hpp:96
CircularBuffer_< float > CircularBufferf
Definition circular.hpp:94
CircularBuffer_< long > CircularBufferl
Definition circular.hpp:93
CircularBuffer_< int > CircularBufferi
Definition circular.hpp:92
CircularBuffer_< double > CircularBufferd
Definition circular.hpp:95
This class extends boost::circular_buffer to implement event circular buffers. For more information,...
Definition circular.hpp:22
double rate() const
Compute event rate as the ratio between the number of events and the time difference between the last...
Definition circular.hpp:50
Eventd mean() const
Compute the mean of the events.
Definition circular.hpp:58
double midTime() const
Calculate the midpoint time between the oldest and the newest event.
Definition circular.hpp:88
double duration() const
Time difference between the last and the first event.
Definition circular.hpp:42
cv::Point2d meanPoint() const
Compute the mean x,y point of the events.
Definition circular.hpp:70
double meanTime() const
Compute the mean time of the events.
Definition circular.hpp:80
This class extends cv::Point_<T> for event data. For more information, please refer here.
Definition types.hpp:62
bool p
Definition types.hpp:65
double t
Definition types.hpp:64
Basic event-based vision structures based on OpenCV components.
Event_< double > Eventd
Definition types.hpp:243