EstervQrCode 1.1.1
Library for qr code manipulation
matx.inl.hpp
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 
5 #ifndef OPENCV_CORE_MATX_INL_HPP
6 #define OPENCV_CORE_MATX_INL_HPP
7 
8 #ifndef __cplusplus
9 # error matx.inl.hpp header must be compiled as C++
10 #endif
11 
12 #include "opencv2/core/matx.hpp"
13 
14 namespace cv
15 {
16 
17 //==============================================================================
18 // Helpers
19 
20 namespace internal
21 {
22 
23 template<typename _Tp, int m> struct Matx_DetOp
24 {
25  double operator ()(const Matx<_Tp, m, m>& a) const
26  {
28  double p = LU(temp.val, m*sizeof(_Tp), m, 0, 0, 0);
29  if( p == 0 )
30  return p;
31  for( int i = 0; i < m; i++ )
32  p *= temp(i, i);
33  return p;
34  }
35 };
36 
37 template<typename _Tp> struct Matx_DetOp<_Tp, 1>
38 {
39  double operator ()(const Matx<_Tp, 1, 1>& a) const
40  {
41  return a(0,0);
42  }
43 };
44 
45 template<typename _Tp> struct Matx_DetOp<_Tp, 2>
46 {
47  double operator ()(const Matx<_Tp, 2, 2>& a) const
48  {
49  return a(0,0)*a(1,1) - a(0,1)*a(1,0);
50  }
51 };
52 
53 template<typename _Tp> struct Matx_DetOp<_Tp, 3>
54 {
55  double operator ()(const Matx<_Tp, 3, 3>& a) const
56  {
57  return a(0,0)*(a(1,1)*a(2,2) - a(2,1)*a(1,2)) -
58  a(0,1)*(a(1,0)*a(2,2) - a(2,0)*a(1,2)) +
59  a(0,2)*(a(1,0)*a(2,1) - a(2,0)*a(1,1));
60  }
61 };
62 
63 template<typename _Tp> Vec<_Tp, 2> inline conjugate(const Vec<_Tp, 2>& v)
64 {
65  return Vec<_Tp, 2>(v[0], -v[1]);
66 }
67 
68 template<typename _Tp> Vec<_Tp, 4> inline conjugate(const Vec<_Tp, 4>& v)
69 {
70  return Vec<_Tp, 4>(v[0], -v[1], -v[2], -v[3]);
71 }
72 
73 } // internal::
74 
75 
76 //==============================================================================
77 // Matx
78 
79 template<typename _Tp, int m, int n> class DataType< Matx<_Tp, m, n> >
80 {
81 public:
84  typedef _Tp channel_type;
86 
87  enum { generic_type = 0,
88  channels = m * n,
89  fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
90 #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
93 #endif
94  };
95 };
96 
97 
98 namespace traits {
99 template<typename _Tp, int m, int n>
100 struct Depth< Matx<_Tp, m, n> > { enum { value = Depth<_Tp>::value }; };
101 template<typename _Tp, int m, int n>
102 struct Type< Matx<_Tp, m, n> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, n*m) }; };
103 } // namespace
104 
105 
107 template<typename _Tp, int m, int n> class MatxCommaInitializer
108 {
109 public:
111  template<typename T2> MatxCommaInitializer<_Tp, m, n>& operator , (T2 val);
113 
115  int idx;
116 };
117 
118 template<typename _Tp, typename _T2, int m, int n> static inline
120 {
122  return (commaInitializer, val);
123 }
124 
125 template<typename _Tp, int m, int n> inline
127  : dst(_mtx), idx(0)
128 {}
129 
130 template<typename _Tp, int m, int n> template<typename _T2> inline
132 {
133  CV_DbgAssert( idx < m*n );
134  dst->val[idx++] = saturate_cast<_Tp>(value);
135  return *this;
136 }
137 
138 template<typename _Tp, int m, int n> inline
140 {
141  CV_DbgAssert( idx == n*m );
142  return *dst;
143 }
144 
146 
147 template<typename _Tp, int m, int n> inline
149 {
150  for(int i = 0; i < channels; i++) val[i] = _Tp(0);
151 }
152 
153 template<typename _Tp, int m, int n> inline
155 {
156  val[0] = v0;
157  for(int i = 1; i < channels; i++) val[i] = _Tp(0);
158 }
159 
160 template<typename _Tp, int m, int n> inline
161 Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1)
162 {
163  CV_StaticAssert(channels >= 2, "Matx should have at least 2 elements.");
164  val[0] = v0; val[1] = v1;
165  for(int i = 2; i < channels; i++) val[i] = _Tp(0);
166 }
167 
168 template<typename _Tp, int m, int n> inline
169 Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2)
170 {
171  CV_StaticAssert(channels >= 3, "Matx should have at least 3 elements.");
172  val[0] = v0; val[1] = v1; val[2] = v2;
173  for(int i = 3; i < channels; i++) val[i] = _Tp(0);
174 }
175 
176 template<typename _Tp, int m, int n> inline
177 Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3)
178 {
179  CV_StaticAssert(channels >= 4, "Matx should have at least 4 elements.");
180  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
181  for(int i = 4; i < channels; i++) val[i] = _Tp(0);
182 }
183 
184 template<typename _Tp, int m, int n> inline
185 Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4)
186 {
187  CV_StaticAssert(channels >= 5, "Matx should have at least 5 elements.");
188  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; val[4] = v4;
189  for(int i = 5; i < channels; i++) val[i] = _Tp(0);
190 }
191 
192 template<typename _Tp, int m, int n> inline
193 Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5)
194 {
195  CV_StaticAssert(channels >= 6, "Matx should have at least 6 elements.");
196  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
197  val[4] = v4; val[5] = v5;
198  for(int i = 6; i < channels; i++) val[i] = _Tp(0);
199 }
200 
201 template<typename _Tp, int m, int n> inline
202 Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6)
203 {
204  CV_StaticAssert(channels >= 7, "Matx should have at least 7 elements.");
205  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
206  val[4] = v4; val[5] = v5; val[6] = v6;
207  for(int i = 7; i < channels; i++) val[i] = _Tp(0);
208 }
209 
210 template<typename _Tp, int m, int n> inline
211 Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7)
212 {
213  CV_StaticAssert(channels >= 8, "Matx should have at least 8 elements.");
214  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
215  val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
216  for(int i = 8; i < channels; i++) val[i] = _Tp(0);
217 }
218 
219 template<typename _Tp, int m, int n> inline
220 Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8)
221 {
222  CV_StaticAssert(channels >= 9, "Matx should have at least 9 elements.");
223  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
224  val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
225  val[8] = v8;
226  for(int i = 9; i < channels; i++) val[i] = _Tp(0);
227 }
228 
229 template<typename _Tp, int m, int n> inline
230 Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9)
231 {
232  CV_StaticAssert(channels >= 10, "Matx should have at least 10 elements.");
233  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
234  val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
235  val[8] = v8; val[9] = v9;
236  for(int i = 10; i < channels; i++) val[i] = _Tp(0);
237 }
238 
239 
240 template<typename _Tp, int m, int n> inline
241 Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11)
242 {
243  CV_StaticAssert(channels >= 12, "Matx should have at least 12 elements.");
244  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
245  val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
246  val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11;
247  for(int i = 12; i < channels; i++) val[i] = _Tp(0);
248 }
249 
250 template<typename _Tp, int m, int n> inline
251 Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13)
252 {
253  CV_StaticAssert(channels >= 14, "Matx should have at least 14 elements.");
254  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
255  val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
256  val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11;
257  val[12] = v12; val[13] = v13;
258  for (int i = 14; i < channels; i++) val[i] = _Tp(0);
259 }
260 
261 
262 template<typename _Tp, int m, int n> inline
263 Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13, _Tp v14, _Tp v15)
264 {
265  CV_StaticAssert(channels >= 16, "Matx should have at least 16 elements.");
266  val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3;
267  val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7;
268  val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11;
269  val[12] = v12; val[13] = v13; val[14] = v14; val[15] = v15;
270  for(int i = 16; i < channels; i++) val[i] = _Tp(0);
271 }
272 
273 // WARNING: unreachable code using Ninja
274 #if defined _MSC_VER && _MSC_VER >= 1920
275 #pragma warning(push)
276 #pragma warning(disable: 4702)
277 #endif
278 template<typename _Tp, int m, int n> inline
279 Matx<_Tp, m, n>::Matx(const _Tp* values)
280 {
281  for( int i = 0; i < channels; i++ ) val[i] = values[i];
282 }
283 #if defined _MSC_VER && _MSC_VER >= 1920
284 #pragma warning(pop)
285 #endif
286 
287 template<typename _Tp, int m, int n> inline
289 {
290  CV_DbgAssert(list.size() == channels);
291  int i = 0;
292  for(const auto& elem : list)
293  {
294  val[i++] = elem;
295  }
296 }
297 
298 template<typename _Tp, int m, int n> inline
300 {
302  for( int i = 0; i < m*n; i++ ) M.val[i] = alpha;
303  return M;
304 }
305 
306 template<typename _Tp, int m, int n> inline
308 {
309  return all(0);
310 }
311 
312 template<typename _Tp, int m, int n> inline
314 {
315  return all(1);
316 }
317 
318 template<typename _Tp, int m, int n> inline
320 {
322  for(int i = 0; i < shortdim; i++)
323  M(i,i) = 1;
324  return M;
325 }
326 
327 template<typename _Tp, int m, int n> inline
329 {
330  _Tp s = 0;
331  for( int i = 0; i < channels; i++ ) s += val[i]*M.val[i];
332  return s;
333 }
334 
335 template<typename _Tp, int m, int n> inline
337 {
338  double s = 0;
339  for( int i = 0; i < channels; i++ ) s += (double)val[i]*M.val[i];
340  return s;
341 }
342 
343 template<typename _Tp, int m, int n> inline
345 {
347  for(int i = 0; i < shortdim; i++)
348  M(i,i) = d(i, 0);
349  return M;
350 }
351 
352 template<typename _Tp, int m, int n> template<typename T2>
354 {
356  for( int i = 0; i < m*n; i++ ) M.val[i] = saturate_cast<T2>(val[i]);
357  return M;
358 }
359 
360 template<typename _Tp, int m, int n> template<int m1, int n1> inline
362 {
363  CV_StaticAssert(m1*n1 == m*n, "Input and destination matrices must have the same number of elements");
364  return (const Matx<_Tp, m1, n1>&)*this;
365 }
366 
367 template<typename _Tp, int m, int n>
368 template<int m1, int n1> inline
369 Matx<_Tp, m1, n1> Matx<_Tp, m, n>::get_minor(int base_row, int base_col) const
370 {
371  CV_DbgAssert(0 <= base_row && base_row+m1 <= m && 0 <= base_col && base_col+n1 <= n);
373  for( int di = 0; di < m1; di++ )
374  for( int dj = 0; dj < n1; dj++ )
375  s(di, dj) = (*this)(base_row+di, base_col+dj);
376  return s;
377 }
378 
379 template<typename _Tp, int m, int n> inline
381 {
382  CV_DbgAssert((unsigned)i < (unsigned)m);
383  return Matx<_Tp, 1, n>(&val[i*n]);
384 }
385 
386 template<typename _Tp, int m, int n> inline
388 {
389  CV_DbgAssert((unsigned)j < (unsigned)n);
391  for( int i = 0; i < m; i++ )
392  v.val[i] = val[i*n + j];
393  return v;
394 }
395 
396 template<typename _Tp, int m, int n> inline
398 {
400  for( int i = 0; i < shortdim; i++ )
401  d.val[i] = val[i*n + i];
402  return d;
403 }
404 
405 template<typename _Tp, int m, int n> inline
406 const _Tp& Matx<_Tp, m, n>::operator()(int row_idx, int col_idx) const
407 {
408  CV_DbgAssert( (unsigned)row_idx < (unsigned)m && (unsigned)col_idx < (unsigned)n );
409  return this->val[row_idx*n + col_idx];
410 }
411 
412 template<typename _Tp, int m, int n> inline
413 _Tp& Matx<_Tp, m, n>::operator ()(int row_idx, int col_idx)
414 {
415  CV_DbgAssert( (unsigned)row_idx < (unsigned)m && (unsigned)col_idx < (unsigned)n );
416  return val[row_idx*n + col_idx];
417 }
418 
419 template<typename _Tp, int m, int n> inline
420 const _Tp& Matx<_Tp, m, n>::operator ()(int i) const
421 {
422  CV_StaticAssert(m == 1 || n == 1, "Single index indexation requires matrix to be a column or a row");
423  CV_DbgAssert( (unsigned)i < (unsigned)(m+n-1) );
424  return val[i];
425 }
426 
427 template<typename _Tp, int m, int n> inline
429 {
430  CV_StaticAssert(m == 1 || n == 1, "Single index indexation requires matrix to be a column or a row");
431  CV_DbgAssert( (unsigned)i < (unsigned)(m+n-1) );
432  return val[i];
433 }
434 
435 template<typename _Tp, int m, int n> inline
436 Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp)
437 {
438  for( int i = 0; i < channels; i++ )
439  val[i] = saturate_cast<_Tp>(a.val[i] + b.val[i]);
440 }
441 
442 template<typename _Tp, int m, int n> inline
443 Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp)
444 {
445  for( int i = 0; i < channels; i++ )
446  val[i] = saturate_cast<_Tp>(a.val[i] - b.val[i]);
447 }
448 
449 template<typename _Tp, int m, int n> template<typename _T2> inline
450 Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp)
451 {
452  for( int i = 0; i < channels; i++ )
453  val[i] = saturate_cast<_Tp>(a.val[i] * alpha);
454 }
455 
456 template<typename _Tp, int m, int n> inline
457 Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp)
458 {
459  for( int i = 0; i < channels; i++ )
460  val[i] = saturate_cast<_Tp>(a.val[i] * b.val[i]);
461 }
462 
463 template<typename _Tp, int m, int n> inline
464 Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp)
465 {
466  for( int i = 0; i < channels; i++ )
467  val[i] = saturate_cast<_Tp>(a.val[i] / b.val[i]);
468 }
469 
470 template<typename _Tp, int m, int n> template<int l> inline
471 Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp)
472 {
473  for( int i = 0; i < m; i++ )
474  for( int j = 0; j < n; j++ )
475  {
476  _Tp s = 0;
477  for( int k = 0; k < l; k++ )
478  s += a(i, k) * b(k, j);
479  val[i*n + j] = s;
480  }
481 }
482 
483 template<typename _Tp, int m, int n> inline
485 {
486  for( int i = 0; i < m; i++ )
487  for( int j = 0; j < n; j++ )
488  val[i*n + j] = a(j, i);
489 }
490 
491 template<typename _Tp, int m, int n> inline
493 {
494  return Matx<_Tp, m, n>(*this, a, Matx_MulOp());
495 }
496 
497 template<typename _Tp, int m, int n> inline
499 {
500  return Matx<_Tp, m, n>(*this, a, Matx_DivOp());
501 }
502 
503 template<typename _Tp, int m, int n> inline
505 {
506  return Matx<_Tp, n, m>(*this, Matx_TOp());
507 }
508 
509 template<typename _Tp, int m, int n> inline
511 {
512  Matx<_Tp, n, 1> x = solve((const Matx<_Tp, m, 1>&)(rhs), method);
513  return (Vec<_Tp, n>&)(x);
514 }
515 
516 template<typename _Tp, int m> static inline
517 double determinant(const Matx<_Tp, m, m>& a)
518 {
520 }
521 
522 template<typename _Tp, int m, int n> static inline
523 double trace(const Matx<_Tp, m, n>& a)
524 {
525  _Tp s = 0;
526  for( int i = 0; i < std::min(m, n); i++ )
527  s += a(i,i);
528  return s;
529 }
530 
531 template<typename _Tp, int m, int n> static inline
532 double norm(const Matx<_Tp, m, n>& M)
533 {
534  return std::sqrt(normL2Sqr<_Tp, double>(M.val, m*n));
535 }
536 
537 template<typename _Tp, int m, int n> static inline
538 double norm(const Matx<_Tp, m, n>& M, int normType)
539 {
540  switch(normType) {
541  case NORM_INF:
542  return (double)normInf<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n);
543  case NORM_L1:
544  return (double)normL1<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n);
545  case NORM_L2SQR:
546  return (double)normL2Sqr<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n);
547  default:
548  case NORM_L2:
549  return std::sqrt((double)normL2Sqr<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n));
550  }
551 }
552 
553 template<typename _Tp1, typename _Tp2, int m, int n> static inline
555 {
556  for( int i = 0; i < m*n; i++ )
557  a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]);
558  return a;
559 }
560 
561 template<typename _Tp1, typename _Tp2, int m, int n> static inline
563 {
564  for( int i = 0; i < m*n; i++ )
565  a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]);
566  return a;
567 }
568 
569 template<typename _Tp, int m, int n> static inline
571 {
572  return Matx<_Tp, m, n>(a, b, Matx_AddOp());
573 }
574 
575 template<typename _Tp, int m, int n> static inline
577 {
578  return Matx<_Tp, m, n>(a, b, Matx_SubOp());
579 }
580 
581 template<typename _Tp, int m, int n> static inline
583 {
584  for( int i = 0; i < m*n; i++ )
585  a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha);
586  return a;
587 }
588 
589 template<typename _Tp, int m, int n> static inline
591 {
592  for( int i = 0; i < m*n; i++ )
593  a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha);
594  return a;
595 }
596 
597 template<typename _Tp, int m, int n> static inline
599 {
600  for( int i = 0; i < m*n; i++ )
601  a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha);
602  return a;
603 }
604 
605 template<typename _Tp, int m, int n> static inline
607 {
608  return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp());
609 }
610 
611 template<typename _Tp, int m, int n> static inline
613 {
614  return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp());
615 }
616 
617 template<typename _Tp, int m, int n> static inline
619 {
620  return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp());
621 }
622 
623 template<typename _Tp, int m, int n> static inline
625 {
626  return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp());
627 }
628 
629 template<typename _Tp, int m, int n> static inline
631 {
632  return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp());
633 }
634 
635 template<typename _Tp, int m, int n> static inline
637 {
638  return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp());
639 }
640 
641 template<typename _Tp, int m, int n> static inline
643 {
644  for( int i = 0; i < m*n; i++ )
645  a.val[i] = a.val[i] / alpha;
646  return a;
647 }
648 
649 template<typename _Tp, int m, int n> static inline
651 {
652  for( int i = 0; i < m*n; i++ )
653  a.val[i] = a.val[i] / alpha;
654  return a;
655 }
656 
657 template<typename _Tp, int m, int n> static inline
659 {
660  return Matx<_Tp, m, n>(a, 1.f/alpha, Matx_ScaleOp());
661 }
662 
663 template<typename _Tp, int m, int n> static inline
665 {
666  return Matx<_Tp, m, n>(a, 1./alpha, Matx_ScaleOp());
667 }
668 
669 template<typename _Tp, int m, int n> static inline
671 {
672  return Matx<_Tp, m, n>(a, -1, Matx_ScaleOp());
673 }
674 
675 template<typename _Tp, int m, int n, int l> static inline
677 {
678  return Matx<_Tp, m, n>(a, b, Matx_MatMulOp());
679 }
680 
681 template<typename _Tp, int m, int n> static inline
683 {
684  Matx<_Tp, m, 1> c(a, b, Matx_MatMulOp());
685  return (const Vec<_Tp, m>&)(c);
686 }
687 
688 template<typename _Tp, int m, int n> static inline
690 {
691  for( int i = 0; i < m*n; i++ )
692  if( a.val[i] != b.val[i] ) return false;
693  return true;
694 }
695 
696 template<typename _Tp, int m, int n> static inline
698 {
699  return !(a == b);
700 }
701 
702 //==============================================================================
703 // Vec
704 
705 template<typename _Tp, int cn> class DataType< Vec<_Tp, cn> >
706 {
707 public:
710  typedef _Tp channel_type;
712 
713  enum { generic_type = 0,
714  channels = cn,
715  fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
716 #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
719 #endif
720  _dummy_enum_finalizer = 0
721  };
722 };
723 
724 namespace traits {
725 template<typename _Tp, int cn>
726 struct Depth< Vec<_Tp, cn> > { enum { value = Depth<_Tp>::value }; };
727 template<typename _Tp, int cn>
728 struct Type< Vec<_Tp, cn> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, cn) }; };
729 } // namespace
730 
733 template<typename _Tp, int m> class VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1>
734 {
735 public:
737  template<typename T2> VecCommaInitializer<_Tp, m>& operator , (T2 val);
738  Vec<_Tp, m> operator *() const;
739 };
740 
741 template<typename _Tp, typename _T2, int cn> static inline
743 {
744  VecCommaInitializer<_Tp, cn> commaInitializer((Vec<_Tp, cn>*)&vec);
745  return (commaInitializer, val);
746 }
747 
748 template<typename _Tp, int cn> inline
750  : MatxCommaInitializer<_Tp, cn, 1>(_vec)
751 {}
752 
753 template<typename _Tp, int cn> template<typename _T2> inline
755 {
756  CV_DbgAssert( this->idx < cn );
757  this->dst->val[this->idx++] = saturate_cast<_Tp>(value);
758  return *this;
759 }
760 
761 template<typename _Tp, int cn> inline
763 {
764  CV_DbgAssert( this->idx == cn );
765  return *this->dst;
766 }
767 
768 
769 template<typename _Tp, int cn> inline
771 
772 template<typename _Tp, int cn> inline
774  : Matx<_Tp, cn, 1>(v0) {}
775 
776 template<typename _Tp, int cn> inline
777 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1)
778  : Matx<_Tp, cn, 1>(v0, v1) {}
779 
780 template<typename _Tp, int cn> inline
781 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2)
782  : Matx<_Tp, cn, 1>(v0, v1, v2) {}
783 
784 template<typename _Tp, int cn> inline
785 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3)
786  : Matx<_Tp, cn, 1>(v0, v1, v2, v3) {}
787 
788 template<typename _Tp, int cn> inline
789 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4)
790  : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4) {}
791 
792 template<typename _Tp, int cn> inline
793 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5)
794  : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5) {}
795 
796 template<typename _Tp, int cn> inline
797 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6)
798  : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6) {}
799 
800 template<typename _Tp, int cn> inline
801 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7)
802  : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7) {}
803 
804 template<typename _Tp, int cn> inline
805 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8)
806  : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8) {}
807 
808 template<typename _Tp, int cn> inline
809 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9)
810  : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9) {}
811 
812 template<typename _Tp, int cn> inline
813 Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13)
814  : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) {}
815 
816 template<typename _Tp, int cn> inline
817 Vec<_Tp, cn>::Vec(const _Tp* values)
818  : Matx<_Tp, cn, 1>(values) {}
819 
820 template<typename _Tp, int cn> inline
822  : Matx<_Tp, cn, 1>(list) {}
823 
824 template<typename _Tp, int cn> inline
826  : Matx<_Tp, cn, 1>(m.val) {}
827 
828 template<typename _Tp, int cn> inline
829 Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp op)
830  : Matx<_Tp, cn, 1>(a, b, op) {}
831 
832 template<typename _Tp, int cn> inline
833 Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp op)
834  : Matx<_Tp, cn, 1>(a, b, op) {}
835 
836 template<typename _Tp, int cn> template<typename _T2> inline
837 Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp op)
838  : Matx<_Tp, cn, 1>(a, alpha, op) {}
839 
840 template<typename _Tp, int cn> inline
842 {
843  Vec v;
844  for( int i = 0; i < cn; i++ ) v.val[i] = alpha;
845  return v;
846 }
847 
848 template<typename _Tp, int cn> inline
850 {
851  return Vec::all(1);
852 }
853 
854 template<typename _Tp, int cn> inline
856 {
857  return Vec::all(0);
858 }
859 
860 template<typename _Tp, int cn> inline
862 {
863  Vec<_Tp, cn> w;
864  for( int i = 0; i < cn; i++ ) w.val[i] = saturate_cast<_Tp>(this->val[i]*v.val[i]);
865  return w;
866 }
867 
868 template<> inline
870 {
871  return cv::internal::conjugate(*this);
872 }
873 
874 template<> inline
876 {
877  return cv::internal::conjugate(*this);
878 }
879 
880 template<> inline
882 {
883  return cv::internal::conjugate(*this);
884 }
885 
886 template<> inline
888 {
889  return cv::internal::conjugate(*this);
890 }
891 
892 template<typename _Tp, int cn> inline
894 {
895  CV_StaticAssert(cn == 3, "for arbitrary-size vector there is no cross-product defined");
896  return Vec<_Tp, cn>();
897 }
898 
899 template<> inline
901 {
902  return Vec<float,3>(this->val[1]*v.val[2] - this->val[2]*v.val[1],
903  this->val[2]*v.val[0] - this->val[0]*v.val[2],
904  this->val[0]*v.val[1] - this->val[1]*v.val[0]);
905 }
906 
907 template<> inline
909 {
910  return Vec<double,3>(this->val[1]*v.val[2] - this->val[2]*v.val[1],
911  this->val[2]*v.val[0] - this->val[0]*v.val[2],
912  this->val[0]*v.val[1] - this->val[1]*v.val[0]);
913 }
914 
915 template<typename _Tp, int cn> template<typename T2> inline
917 {
918  Vec<T2, cn> v;
919  for( int i = 0; i < cn; i++ ) v.val[i] = saturate_cast<T2>(this->val[i]);
920  return v;
921 }
922 
923 template<typename _Tp, int cn> inline
924 const _Tp& Vec<_Tp, cn>::operator [](int i) const
925 {
926  CV_DbgAssert( (unsigned)i < (unsigned)cn );
927  return this->val[i];
928 }
929 
930 template<typename _Tp, int cn> inline
932 {
933  CV_DbgAssert( (unsigned)i < (unsigned)cn );
934  return this->val[i];
935 }
936 
937 template<typename _Tp, int cn> inline
938 const _Tp& Vec<_Tp, cn>::operator ()(int i) const
939 {
940  CV_DbgAssert( (unsigned)i < (unsigned)cn );
941  return this->val[i];
942 }
943 
944 template<typename _Tp, int cn> inline
946 {
947  CV_DbgAssert( (unsigned)i < (unsigned)cn );
948  return this->val[i];
949 }
950 
951 template<typename _Tp, int cn> inline
953 {
954  double nv = norm(v);
955  return v * (nv ? 1./nv : 0.);
956 }
957 
958 template<typename _Tp1, typename _Tp2, int cn> static inline
960 {
961  for( int i = 0; i < cn; i++ )
962  a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]);
963  return a;
964 }
965 
966 template<typename _Tp1, typename _Tp2, int cn> static inline
968 {
969  for( int i = 0; i < cn; i++ )
970  a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]);
971  return a;
972 }
973 
974 template<typename _Tp, int cn> static inline
976 {
977  return Vec<_Tp, cn>(a, b, Matx_AddOp());
978 }
979 
980 template<typename _Tp, int cn> static inline
982 {
983  return Vec<_Tp, cn>(a, b, Matx_SubOp());
984 }
985 
986 template<typename _Tp, int cn> static inline
988 {
989  for( int i = 0; i < cn; i++ )
990  a[i] = saturate_cast<_Tp>(a[i]*alpha);
991  return a;
992 }
993 
994 template<typename _Tp, int cn> static inline
996 {
997  for( int i = 0; i < cn; i++ )
998  a[i] = saturate_cast<_Tp>(a[i]*alpha);
999  return a;
1000 }
1001 
1002 template<typename _Tp, int cn> static inline
1004 {
1005  for( int i = 0; i < cn; i++ )
1006  a[i] = saturate_cast<_Tp>(a[i]*alpha);
1007  return a;
1008 }
1009 
1010 template<typename _Tp, int cn> static inline
1012 {
1013  double ialpha = 1./alpha;
1014  for( int i = 0; i < cn; i++ )
1015  a[i] = saturate_cast<_Tp>(a[i]*ialpha);
1016  return a;
1017 }
1018 
1019 template<typename _Tp, int cn> static inline
1021 {
1022  float ialpha = 1.f/alpha;
1023  for( int i = 0; i < cn; i++ )
1024  a[i] = saturate_cast<_Tp>(a[i]*ialpha);
1025  return a;
1026 }
1027 
1028 template<typename _Tp, int cn> static inline
1030 {
1031  double ialpha = 1./alpha;
1032  for( int i = 0; i < cn; i++ )
1033  a[i] = saturate_cast<_Tp>(a[i]*ialpha);
1034  return a;
1035 }
1036 
1037 template<typename _Tp, int cn> static inline
1039 {
1040  return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp());
1041 }
1042 
1043 template<typename _Tp, int cn> static inline
1045 {
1046  return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp());
1047 }
1048 
1049 template<typename _Tp, int cn> static inline
1051 {
1052  return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp());
1053 }
1054 
1055 template<typename _Tp, int cn> static inline
1057 {
1058  return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp());
1059 }
1060 
1061 template<typename _Tp, int cn> static inline
1063 {
1064  return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp());
1065 }
1066 
1067 template<typename _Tp, int cn> static inline
1069 {
1070  return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp());
1071 }
1072 
1073 template<typename _Tp, int cn> static inline
1075 {
1076  return Vec<_Tp, cn>(a, 1./alpha, Matx_ScaleOp());
1077 }
1078 
1079 template<typename _Tp, int cn> static inline
1081 {
1082  return Vec<_Tp, cn>(a, 1.f/alpha, Matx_ScaleOp());
1083 }
1084 
1085 template<typename _Tp, int cn> static inline
1087 {
1088  return Vec<_Tp, cn>(a, 1./alpha, Matx_ScaleOp());
1089 }
1090 
1091 template<typename _Tp, int cn> static inline
1093 {
1094  Vec<_Tp,cn> t;
1095  for( int i = 0; i < cn; i++ ) t.val[i] = saturate_cast<_Tp>(-a.val[i]);
1096  return t;
1097 }
1098 
1099 template<typename _Tp> inline Vec<_Tp, 4> operator * (const Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2)
1100 {
1101  return Vec<_Tp, 4>(saturate_cast<_Tp>(v1[0]*v2[0] - v1[1]*v2[1] - v1[2]*v2[2] - v1[3]*v2[3]),
1102  saturate_cast<_Tp>(v1[0]*v2[1] + v1[1]*v2[0] + v1[2]*v2[3] - v1[3]*v2[2]),
1103  saturate_cast<_Tp>(v1[0]*v2[2] - v1[1]*v2[3] + v1[2]*v2[0] + v1[3]*v2[1]),
1104  saturate_cast<_Tp>(v1[0]*v2[3] + v1[1]*v2[2] - v1[2]*v2[1] + v1[3]*v2[0]));
1105 }
1106 
1107 template<typename _Tp> inline Vec<_Tp, 4>& operator *= (Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2)
1108 {
1109  v1 = v1 * v2;
1110  return v1;
1111 }
1112 
1113 } // cv::
1114 
1115 #endif // OPENCV_CORE_MATX_INL_HPP
_Tp channel_type
Definition: matx.inl.hpp:84
Matx< typename DataType< _Tp >::work_type, m, n > work_type
Definition: matx.inl.hpp:83
value_type vec_type
Definition: matx.inl.hpp:85
Matx< _Tp, m, n > value_type
Definition: matx.inl.hpp:82
_Tp channel_type
Definition: matx.inl.hpp:710
Vec< typename DataType< _Tp >::work_type, cn > work_type
Definition: matx.inl.hpp:709
Vec< _Tp, cn > value_type
Definition: matx.inl.hpp:708
value_type vec_type
Definition: matx.inl.hpp:711
Template "trait" class for OpenCV primitive data types.
Definition: traits.hpp:113
Comma-separated Matrix Initializer.
Definition: matx.inl.hpp:108
int idx
Definition: matx.inl.hpp:115
Matx< _Tp, m, n > * dst
Definition: matx.inl.hpp:114
MatxCommaInitializer< _Tp, m, n > & operator,(T2 val)
Matx< _Tp, m, n > operator*() const
Definition: matx.inl.hpp:139
MatxCommaInitializer(Matx< _Tp, m, n > *_mtx)
Definition: matx.inl.hpp:126
Template class for small matrices whose type and size are known at compilation time.
Definition: matx.hpp:100
Matx< _Tp, m, n > mul(const Matx< _Tp, m, n > &a) const
multiply two matrices element-wise
Definition: matx.inl.hpp:492
Matx()
default constructor
Definition: matx.inl.hpp:148
Matx< _Tp, n, m > t() const
transpose the matrix
Definition: matx.inl.hpp:504
static CV_NODISCARD_STD Matx ones()
Definition: matx.inl.hpp:313
Matx< _Tp, 1, n > row(int i) const
extract the matrix row
Definition: matx.inl.hpp:380
Matx< _Tp, m, 1 > col(int i) const
extract the matrix column
Definition: matx.inl.hpp:387
static CV_NODISCARD_STD Matx eye()
Definition: matx.inl.hpp:319
Matx< _Tp, n, l > solve(const Matx< _Tp, m, l > &rhs, int flags=DECOMP_LU) const
solve linear system
Matx< _Tp, m, n > div(const Matx< _Tp, m, n > &a) const
divide two matrices element-wise
Definition: matx.inl.hpp:498
Matx< _Tp, m1, n1 > reshape() const
change the matrix shape
Definition: matx.inl.hpp:361
static CV_NODISCARD_STD Matx zeros()
Definition: matx.inl.hpp:307
const _Tp & operator()(int row, int col) const
element access
Definition: matx.inl.hpp:406
static CV_NODISCARD_STD Matx all(_Tp alpha)
Definition: matx.inl.hpp:299
double ddot(const Matx< _Tp, m, n > &v) const
dot product computed in double-precision arithmetics
Definition: matx.inl.hpp:336
diag_type diag() const
extract the matrix diagonal
Definition: matx.inl.hpp:397
_Tp val[m *n]
matrix elements
Definition: matx.hpp:218
Matx< _Tp, m1, n1 > get_minor(int base_row, int base_col) const
extract part of the matrix
Definition: matx.inl.hpp:369
_Tp dot(const Matx< _Tp, m, n > &v) const
dot product computed with the default precision
Definition: matx.inl.hpp:328
Comma-separated Vec Initializer.
Definition: matx.inl.hpp:734
Vec< _Tp, m > operator*() const
Definition: matx.inl.hpp:762
VecCommaInitializer(Vec< _Tp, m > *_vec)
Definition: matx.inl.hpp:749
VecCommaInitializer< _Tp, m > & operator,(T2 val)
Template class for short numerical vectors, a partial case of Matx.
Definition: matx.hpp:369
static Vec zeros()
Definition: matx.inl.hpp:855
static Vec all(_Tp alpha)
Definition: matx.inl.hpp:841
Vec mul(const Vec< _Tp, cn > &v) const
per-element multiplication
Definition: matx.inl.hpp:861
Vec()
default constructor
Definition: matx.inl.hpp:770
const _Tp & operator[](int i) const
Definition: matx.inl.hpp:924
Vec cross(const Vec &v) const
Definition: matx.inl.hpp:893
static Vec ones()
Definition: matx.inl.hpp:849
const _Tp & operator()(int i) const
Definition: matx.inl.hpp:938
Vec conj() const
conjugation (makes sense for complex numbers and quaternions)
CV_EXPORTS_W bool solve(InputArray src1, InputArray src2, OutputArray dst, int flags=DECOMP_LU)
Solves one or more linear systems or least-squares problems.
@ NORM_L2
Definition: base.hpp:185
@ NORM_L1
Definition: base.hpp:176
@ NORM_L2SQR
Definition: base.hpp:194
@ NORM_INF
Definition: base.hpp:168
static double determinant(const Matx< _Tp, m, m > &a)
Vec< _Tp, cn > normalize(const Vec< _Tp, cn > &v)
Definition: matx.inl.hpp:952
static double trace(const Matx< _Tp, m, n > &a)
static bool operator!=(const Matx< _Tp, m, n > &a, const Matx< _Tp, m, n > &b)
static double norm(const Matx< _Tp, m, n > &M)
static bool operator==(const Matx< _Tp, m, n > &a, const Matx< _Tp, m, n > &b)
int CvScalar value
Definition: core_c.h:720
int int channels
Definition: core_c.h:100
const void * elem
Definition: core_c.h:1715
const int * idx
Definition: core_c.h:668
int int type
Definition: core_c.h:221
int depth
Definition: core_c.h:100
const CvArr CvArr * x
Definition: core_c.h:1195
double alpha
Definition: core_c.h:1093
#define CV_MAKETYPE(depth, cn)
Definition: interface.h:85
CV_INLINE v_reg< _Tp, n > & operator-=(v_reg< _Tp, n > &a, const v_reg< _Tp, n > &b)
CV_INLINE v_reg< _Tp, n > & operator*=(v_reg< _Tp, n > &a, const v_reg< _Tp, n > &b)
CV_INLINE v_reg< _Tp, n > & operator/=(v_reg< _Tp, n > &a, const v_reg< _Tp, n > &b)
CV_INLINE v_reg< _Tp, n > operator/(const v_reg< _Tp, n > &a, const v_reg< _Tp, n > &b)
Divide values.
CV_INLINE v_reg< _Tp, n > & operator+=(v_reg< _Tp, n > &a, const v_reg< _Tp, n > &b)
CV_EXPORTS int LU(float *A, size_t astep, int m, float *b, size_t bstep, int n)
static _AccTp normL2Sqr(const _Tp *a, int n)
Definition: base.hpp:404
#define CV_DbgAssert(expr)
Definition: base.hpp:375
std::ostream & operator<<(std::ostream &, const DualQuat< _Tp > &)
CvArr CvPoint2D32f double M
Definition: imgproc_c.h:270
const CvArr CvArr int method
Definition: imgproc_c.h:384
CvArr CvArr * temp
Definition: imgproc_c.h:329
CV_EXPORTS OutputArray int double double InputArray OutputArray int int bool double k
Definition: imgproc.hpp:2133
OutputArray dst
Definition: imgproc.hpp:3564
T min(T... args)
Vec< _Tp, 2 > conjugate(const Vec< _Tp, 2 > &v)
Definition: matx.inl.hpp:63
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441
DualQuat< T > operator+(const T a, const DualQuat< T > &q)
Definition: dualquaternion.inl.hpp:243
DualQuat< T > operator*(const T a, const DualQuat< T > &q)
Definition: dualquaternion.inl.hpp:274
DualQuat< T > operator-(const DualQuat< T > &q, const T a)
Definition: dualquaternion.inl.hpp:255
T sqrt(T... args)
Definition: matx.inl.hpp:24
double operator()(const Matx< _Tp, m, m > &a) const
Definition: matx.inl.hpp:25
Definition: traits.hpp:382
@ value
Definition: traits.hpp:382
Definition: traits.hpp:402
Definition: traits.hpp:386
@ value
Definition: traits.hpp:386