6#ifndef OPENEV_CORE_MATRICES_HPP
7#define OPENEV_CORE_MATRICES_HPP
13#include <opencv2/core/hal/interface.h>
14#include <opencv2/core/mat.hpp>
15#include <opencv2/core/mat.inl.hpp>
16#include <opencv2/core/traits.hpp>
21constexpr bool USING_MATRICES_HPP =
true;
30class Mat_ :
public cv::Mat_<T> {
34 void updateStats(
const Event &e) {
43 CounterType count()
const {
47 TimeType duration()
const {
48 return last_ - first_;
64 if(cv::Mat_<T>::empty()) {
67 if(cv::Mat_<T>::isContinuous()) {
68 std::memset(cv::Mat_<T>::data, 0, cv::Mat_<T>::total() * cv::Mat_<T>::elemSize());
71 cv::Mat_<T>::setTo(0);
77 CounterType count_{0};
100 template <
typename T>
102 return set(e.x, e.y);
111 template <
typename T>
116 static constexpr Tb
ON = std::numeric_limits<Tb>::max();
117 static constexpr Tb
OFF =
static_cast<Tb
>(0);
119 friend std::ostream &operator<<(std::ostream &os,
const Binary_ &binary) {
120 os <<
"Binary " << binary.cols <<
"x" << binary.rows;
125 template <
typename T>
126 inline Tb set(
const T x,
const T y) {
127 if constexpr(std::is_floating_point_v<T>) {
128 return *(this->
template ptr<Tb>(std::lround(y)) + std::lround(x)) =
ON;
130 return *(this->
template ptr<Tb>(y) + x) =
ON;
147template <
typename Tb>
157 template <
typename T>
159 return set(e.x, e.y, e.
p);
169 template <
typename T>
170 inline Tb
emplace(
const T x,
const T y,
const bool p) {
174 static constexpr Tb
POSITIVE = std::numeric_limits<Tb>::max();
175 static constexpr Tb
ZERO =
static_cast<Tb
>(0);
176 static constexpr Tb
NEGATIVE = std::numeric_limits<Tb>::min();
178 friend std::ostream &operator<<(std::ostream &os,
const Ternary_ &ternary) {
179 os <<
"Ternary " << ternary.cols <<
"x" << ternary.rows;
184 template <
typename T>
185 inline Tb set(
const T x,
const T y,
const bool p) {
186 if constexpr(std::is_floating_point_v<T>) {
187 return *(this->
template ptr<Tb>(std::lround(y)) + std::lround(x)) = (p ?
POSITIVE :
NEGATIVE);
210 template <
typename T>
212 return set(e.x, e.y, e.
t);
222 template <
typename T>
223 inline TimeType
emplace(
const T x,
const T y,
const TimeType t) {
227 friend std::ostream &operator<<(std::ostream &os,
const Time &time) {
228 os <<
"Time " << time.cols <<
"x" << time.rows;
233 template <
typename T>
234 inline TimeType set(
const T x,
const T y,
const TimeType t) {
235 if constexpr(std::is_floating_point_v<T>) {
236 return *(this->ptr<TimeType>(std::lround(y)) + std::lround(x)) = t;
238 return *(this->ptr<TimeType>(y) + x) = t;
258 template <
typename T>
260 return set(e.x, e.y, e.
p);
270 template <
typename T>
271 inline PolarityType
emplace(
const T x,
const T y,
const PolarityType p) {
275 friend std::ostream &operator<<(std::ostream &os,
const Polarity &polarity) {
276 os <<
"Polarity " << polarity.cols <<
"x" << polarity.rows;
281 template <
typename T>
282 inline PolarityType set(
const T x,
const T y,
const PolarityType p) {
283 if constexpr(std::is_floating_point_v<T>) {
284 return *(this->ptr<PolarityType>(std::lround(y)) + std::lround(x)) = p;
286 return *(this->ptr<PolarityType>(y) + x) = p;
306 template <
typename T>
308 return set(e.x, e.y, e.
p);
318 template <
typename T>
319 inline CounterType
emplace(
const T x,
const T y,
const bool p) {
323 friend std::ostream &operator<<(std::ostream &os,
const Counter &counter) {
324 os <<
"Counter " << counter.cols <<
"x" << counter.rows;
329 template <
typename T>
330 inline CounterType set(
const T x,
const T y,
const bool p) {
331 if constexpr(std::is_floating_point_v<T>) {
332 return *(this->ptr<CounterType>(std::lround(y)) + std::lround(x)) += (p ? +1 : -1);
334 return *(this->ptr<CounterType>(y) + x) += (p ? +1 : -1);
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
Spatial map marking whether any event has occurred at each pixel.
Definition matrices.hpp:91
Tb insert(const Event_< T > &e)
Insert an event, setting the pixel at (e.x, e.y) to ON.
Definition matrices.hpp:101
Tb emplace(const T x, const T y)
Set the pixel at (x, y) to ON without constructing an Event_.
Definition matrices.hpp:112
static constexpr uchar ON
Definition matrices.hpp:116
static constexpr uchar OFF
Definition matrices.hpp:117
Spatial map accumulating signed event counts per pixel.
Definition matrices.hpp:297
CounterType insert(const Event_< T > &e)
Insert an event, incrementing (p=true) or decrementing (p=false) the counter at (e....
Definition matrices.hpp:307
CounterType emplace(const T x, const T y, const bool p)
Increment or decrement the counter at (x, y) without constructing an Event_.
Definition matrices.hpp:319
Definition matrices.hpp:30
void clear()
Reset all pixels.
Definition matrices.hpp:63
void resetStats()
Reset statistics (count, first timestamp, last timestamp).
Definition matrices.hpp:54
Spatial map storing the polarity of the most recent event at each pixel.
Definition matrices.hpp:249
PolarityType emplace(const T x, const T y, const PolarityType p)
Store polarity p at (x, y) without constructing an Event_.
Definition matrices.hpp:271
PolarityType insert(const Event_< T > &e)
Insert an event, storing e.p at pixel (e.x, e.y).
Definition matrices.hpp:259
Spatial map encoding event polarity at each pixel.
Definition matrices.hpp:148
Tb insert(const Event_< T > &e)
Insert an event, writing POSITIVE or NEGATIVE at (e.x, e.y) based on e.p.
Definition matrices.hpp:158
static constexpr char ZERO
Definition matrices.hpp:175
Tb emplace(const T x, const T y, const bool p)
Write polarity p at (x, y) without constructing an Event_.
Definition matrices.hpp:170
static constexpr char NEGATIVE
Definition matrices.hpp:176
static constexpr char POSITIVE
Definition matrices.hpp:174
Spatial map storing the timestamp of the most recent event at each pixel.
Definition matrices.hpp:201
TimeType insert(const Event_< T > &e)
Insert an event, storing e.t at pixel (e.x, e.y).
Definition matrices.hpp:211
TimeType emplace(const T x, const T y, const TimeType t)
Store timestamp t at (x, y) without constructing an Event_.
Definition matrices.hpp:223
Basic event-based vision structures based on OpenCV components.
constexpr PolarityType POSITIVE
Definition types.hpp:29
Eventi Event
Definition types.hpp:252
constexpr PolarityType NEGATIVE
Definition types.hpp:30