5 #define __CRT_STRINGIZE(_Value) #_Value 6 #define _CRT_STRINGIZE(_Value) __CRT_STRINGIZE(_Value) 8 #define __ATTRIBUTES__ " in \"" __FILE__ "\", line " _CRT_STRINGIZE(__LINE__) "" 9 #define DGM_ASSERT(_condition_) \ 11 if (!(_condition_)) { \ 12 printf("Assertion failed: %s", #_condition_ __ATTRIBUTES__); \ 17 #define DGM_ASSERT_MSG(_condition_, _format_, ...) \ 19 if (!(_condition_)) { \ 20 printf("Assertion failed: %s\n", #_condition_ __ATTRIBUTES__); \ 21 printf(_format_"\n", ##__VA_ARGS__); \ 26 #define DGM_IF_WARNING(_condition_, _format_, ...) \ 29 printf("WARNING: %s:\n", #_condition_ __ATTRIBUTES__); \ 30 printf(_format_"\n", ##__VA_ARGS__); \ 34 #define DGM_WARNING(_format_, ...) \ 36 printf("WARNING:%s:\n", __ATTRIBUTES__); \ 37 printf(_format_"\n", ##__VA_ARGS__); \ 40 #define SIGN(a) (((a) >= 0) ? 1 : -1) 51 u.x[1] = (int)(b * (u.x[1] - 1072632447) + 1072632447);
60 template<
typename T,
void (T::*SomeMethod)(byte b)>
64 DGM_ASSERT(m.type() == CV_8UC1);
66 for (
int y = 0; y < m.rows; y++) {
67 const byte *pM = m.ptr<byte>(y);
68 for (
int x = 0; x < m.cols; x++)
69 (
self.*SomeMethod)(pM[x]);
74 template<
typename T,
void (T::*SomeMethod)(byte b1, byte b2)>
78 DGM_ASSERT(m1.size() == m2.size());
79 DGM_ASSERT(m1.type() == m2.type());
80 DGM_ASSERT(m1.type() == CV_8UC1);
82 for (
int y = 0; y < m1.rows; y++) {
83 const byte *pM1 = m1.ptr<byte>(y);
84 const byte *pM2 = m2.ptr<byte>(y);
85 for (
int x = 0; x < m1.cols; x++)
86 (
self.*SomeMethod)(pM1[x], pM2[x]);
90 template<
typename T,
void (T::*SomeMethod)(byte b1, byte b2)>
94 DGM_ASSERT((m1.size() == m2.size()) && (m2.size() == mask.size()));
95 DGM_ASSERT((m1.type() == m2.type()) && mask.type() == CV_8UC1);
96 DGM_ASSERT(m1.type() == CV_8UC1);
98 for (
int y = 0; y < m1.rows; y++) {
99 const byte *pM1 = m1.ptr<byte>(y);
100 const byte *pM2 = m2.ptr<byte>(y);
101 const byte *pMask = mask.ptr<byte>(y);
102 for (
int x = 0; x < m1.cols; x++)
103 if (pMask[x]) (
self.*SomeMethod)(pM1[x], pM2[x]);
108 template<
typename T,
void (T::*SomeMethod)(const Mat &vec, byte b)>
112 DGM_ASSERT(m1.size() == m2.size());
113 DGM_ASSERT(m1.depth() == CV_8U);
114 DGM_ASSERT(m2.type() == CV_8UC1);
116 Mat vec(m1.channels(), 1, CV_8UC1);
117 for (
int y = 0; y < m2.rows; y++) {
118 const byte *pM1 = m1.ptr<byte>(y);
119 const byte *pM2 = m2.ptr<byte>(y);
120 for (
int x = 0; x < m2.cols; x++) {
121 for (
int f = 0; f < vec.rows; f++) vec.at<byte>(f, 0) = pM1[vec.rows * x + f];
122 (
self.*SomeMethod)(vec, pM2[x]);
127 template<
typename T,
void (T::*SomeMethod)(const Mat &vec, byte b)>
131 DGM_ASSERT(m1[0].size() == m2.size());
132 DGM_ASSERT(m1[0].type() == CV_8UC1);
133 DGM_ASSERT(m2.type() == CV_8UC1);
135 const word nFeatures =
static_cast<word
>(m1.size());
136 Mat vec(nFeatures, 1, CV_8UC1);
137 std::vector<const byte *> vM1(nFeatures);
138 for (
int y = 0; y < m2.rows; y++) {
139 for (
int f = 0; f < vec.rows; f++) vM1[f] = m1[f].ptr<byte>(y);
140 const byte *pM2 = m2.ptr<byte>(y);
141 for (
int x = 0; x < m2.cols; x++) {
142 for (
int f = 0; f < vec.rows; f++) vec.at<byte>(f, 0) = vM1[f][x];
143 (
self.*SomeMethod)(vec, pM2[x]);
149 template<
typename T,
void (T::*SomeMethod)(const Mat &vec, byte b1, byte b2)>
153 DGM_ASSERT(m1.size() == m2.size());
154 DGM_ASSERT(m1.size() == m3.size());
155 DGM_ASSERT(m1.depth() == CV_8U);
156 DGM_ASSERT(m2.type() == CV_8UC1);
157 DGM_ASSERT(m3.type() == CV_8UC1);
159 Mat vec(m1.channels(), 1, CV_8UC1);
160 for (
int y = 0; y < m2.rows; y++) {
161 const byte *pM1 = m1.ptr<byte>(y);
162 const byte *pM2 = m2.ptr<byte>(y);
163 const byte *pM3 = m3.ptr<byte>(y);
164 for (
int x = 0; x < m2.cols; x++) {
165 for (
int f = 0; f < vec.rows; f++) vec.at<byte>(f, 0) = pM1[vec.rows * x + f];
166 (
self.*SomeMethod)(vec, pM2[x], pM3[x]);
171 template<
typename T,
void (T::*SomeMethod)(const Mat &vec, byte b1, byte b2)>
172 inline void DGM_VECTORWISE2(T &
self,
const vec_mat_t &m1,
const Mat &m2,
const Mat &m3)
175 DGM_ASSERT(m1[0].size() == m2.size());
176 DGM_ASSERT(m1[0].size() == m3.size());
177 DGM_ASSERT(m1[0].type() == CV_8UC1);
178 DGM_ASSERT(m2.type() == CV_8UC1);
179 DGM_ASSERT(m3.type() == CV_8UC1);
181 const word nFeatures =
static_cast<word
>(m1.size());
182 Mat vec(nFeatures, 1, CV_8UC1);
183 std::vector<const byte *> vM1(nFeatures);
184 for (
int y = 0; y < m2.rows; y++) {
185 for (
int f = 0; f < vec.rows; f++) vM1[f] = m1[f].ptr<byte>(y);
186 const byte *pM2 = m2.ptr<byte>(y);
187 const byte *pM3 = m3.ptr<byte>(y);
188 for (
int x = 0; x < m2.cols; x++) {
189 for (
int f = 0; f < vec.rows; f++) vec.at<byte>(f, 0) = vM1[f][x];
190 (
self.*SomeMethod)(vec, pM2[x], pM3[x]);
void DGM_VECTORWISE1(T &self, const Mat &m1, const Mat &m2)
double fastPow(double a, double b)
void DGM_ELEMENTWISE2(T &self, const Mat &m1, const Mat &m2)
void DGM_ELEMENTWISE1(T &self, const Mat &m)
void DGM_VECTORWISE2(T &self, const Mat &m1, const Mat &m2, const Mat &m3)