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>
28template <
typename MatType>
29inline void clearZero(MatType &mat) {
33 if(mat.isContinuous()) {
34 std::memset(mat.data, 0, mat.total() * mat.elemSize());
44 using cv::Mat_<Tb>::Mat_;
52 inline Tb emplace(
const T x,
const T y) {
57 detail::clearZero(*
this);
60 static constexpr Tb ON = std::numeric_limits<Tb>::max();
61 static constexpr Tb OFF =
static_cast<Tb
>(0);
63 friend std::ostream &operator<<(std::ostream &os,
const Binary_ &binary) {
64 os <<
"Binary " << binary.cols <<
"x" << binary.rows;
70 inline Tb set(
const T x,
const T y) {
71 if constexpr(std::is_floating_point_v<T>) {
72 return *(this->
template ptr<Tb>(std::lround(y)) + std::lround(x)) = ON;
74 return *(this->
template ptr<Tb>(y) + x) = ON;
83 using cv::Mat_<Tb>::Mat_;
87 return set(e.x, e.y, e.
p);
91 inline Tb emplace(
const T x,
const T y,
const bool p) {
96 detail::clearZero(*
this);
99 static constexpr Tb POSITIVE = std::numeric_limits<Tb>::max();
100 static constexpr Tb ZERO =
static_cast<Tb
>(0);
101 static constexpr Tb NEGATIVE = std::numeric_limits<Tb>::min();
103 friend std::ostream &operator<<(std::ostream &os,
const Ternary_ &ternary) {
104 os <<
"Ternary " << ternary.cols <<
"x" << ternary.rows;
109 template <
typename T>
110 inline Tb set(
const T x,
const T y,
const bool p) {
111 if constexpr(std::is_floating_point_v<T>) {
112 return *(this->
template ptr<Tb>(std::lround(y)) + std::lround(x)) = (p ? POSITIVE : NEGATIVE);
114 return *(this->
template ptr<Tb>(y) + x) = (p ? POSITIVE : NEGATIVE);
120class Time :
public cv::Mat_<TimeType> {
122 using cv::Mat_<TimeType>::Mat_;
124 template <
typename T>
125 inline TimeType insert(
const Event_<T> &e) {
126 return set(e.x, e.y, e.
t);
129 template <
typename T>
130 inline TimeType emplace(
const T x,
const T y,
const TimeType t) {
134 inline void clear() {
135 detail::clearZero(*
this);
138 friend std::ostream &operator<<(std::ostream &os,
const Time &time) {
139 os <<
"Time " << time.cols <<
"x" << time.rows;
144 template <
typename T>
145 inline TimeType set(
const T x,
const T y,
const TimeType t) {
146 if constexpr(std::is_floating_point_v<T>) {
147 return *(this->ptr<TimeType>(std::lround(y)) + std::lround(x)) = t;
149 return *(this->ptr<TimeType>(y) + x) = t;
156 using cv::Mat_<PolarityType>::Mat_;
158 template <
typename T>
159 inline PolarityType insert(
const Event_<T> &e) {
160 return set(e.x, e.y, e.
p);
163 template <
typename T>
164 inline PolarityType emplace(
const T x,
const T y,
const PolarityType p) {
168 inline void clear() {
169 detail::clearZero(*
this);
172 friend std::ostream &operator<<(std::ostream &os,
const Polarity &polarity) {
173 os <<
"Polarity " << polarity.cols <<
"x" << polarity.rows;
178 template <
typename T>
179 inline PolarityType set(
const T x,
const T y,
const PolarityType p) {
180 if constexpr(std::is_floating_point_v<T>) {
181 return *(this->ptr<PolarityType>(std::lround(y)) + std::lround(x)) = p;
183 return *(this->ptr<PolarityType>(y) + x) = p;
190 using cv::Mat_<CounterType>::Mat_;
192 template <
typename T>
193 inline CounterType insert(
const Event_<T> &e) {
194 return set(e.x, e.y, e.
p);
197 template <
typename T>
198 inline CounterType emplace(
const T x,
const T y,
const bool p) {
202 inline void clear() {
203 detail::clearZero(*
this);
206 friend std::ostream &operator<<(std::ostream &os,
const Counter &counter) {
207 os <<
"Counter " << counter.cols <<
"x" << counter.rows;
212 template <
typename T>
213 inline CounterType set(
const T x,
const T y,
const bool p) {
214 if constexpr(std::is_floating_point_v<T>) {
215 return *(this->ptr<CounterType>(std::lround(y)) + std::lround(x)) += (p ? +1 : -1);
217 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:62
PolarityType p
Definition types.hpp:65
TimeType t
Definition types.hpp:64
Definition matrices.hpp:42
Definition matrices.hpp:188
Definition matrices.hpp:154
Definition matrices.hpp:81
Definition matrices.hpp:120
Basic event-based vision structures based on OpenCV components.