6#ifndef OPENEV_CONTAINERS_CIRCULAR_HPP
7#define OPENEV_CONTAINERS_CIRCULAR_HPP
10#include <boost/circular_buffer.hpp>
12#include <opencv2/core/types.hpp>
16constexpr bool USING_CIRCULAR_HPP =
true;
25 using boost::circular_buffer<
Event_<T>>::circular_buffer;
26 using ResultType = TimeType;
35 template <
typename... Args>
37 boost::circular_buffer<Event_<T>>::push_back(
Event_<T>(std::forward<Args>(args)...));
46 template <
typename... Args>
48 boost::circular_buffer<Event_<T>>::push_front(
Event_<T>(std::forward<Args>(args)...));
55 [[nodiscard]]
inline ResultType
duration()
const {
56 return boost::circular_buffer<ev::Event_<T>>::back().t - boost::circular_buffer<ev::Event_<T>>::front().t;
63 [[nodiscard]]
inline ResultType
rate()
const {
64 return boost::circular_buffer<ev::Event_<T>>::size() /
duration();
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};
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();
93 [[nodiscard]]
inline ResultType
meanTime()
const {
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);
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.