53
53
#include " opencv2/core/traits.hpp"
54
54
#include " opencv2/core/saturate.hpp"
55
55
56
+ #ifdef CV_CXX11
57
+ #include < initializer_list>
58
+ #endif
59
+
56
60
namespace cv
57
61
{
58
62
@@ -77,12 +81,21 @@ If you need a more flexible type, use Mat . The elements of the matrix M are acc
77
81
M(i,j) notation. Most of the common matrix operations (see also @ref MatrixExpressions ) are
78
82
available. To do an operation on Matx that is not implemented, you can easily convert the matrix to
79
83
Mat and backwards:
80
- @code
84
+ @code{.cpp}
81
85
Matx33f m(1, 2, 3,
82
86
4, 5, 6,
83
87
7, 8, 9);
84
88
cout << sum(Mat(m*m.t())) << endl;
85
- @endcode
89
+ @endcode
90
+ Except of the plain constructor which takes a list of elements, Matx can be initialized from a C-array:
91
+ @code{.cpp}
92
+ float values[] = { 1, 2, 3};
93
+ Matx31f m(values);
94
+ @endcode
95
+ In case if C++11 features are avaliable, std::initializer_list can be also used to initizlize Matx:
96
+ @code{.cpp}
97
+ Matx31f m = { 1, 2, 3};
98
+ @endcode
86
99
*/
87
100
template <typename _Tp, int m, int n> class Matx
88
101
{
@@ -125,6 +138,10 @@ template<typename _Tp, int m, int n> class Matx
125
138
_Tp v12, _Tp v13, _Tp v14, _Tp v15); // !< 1x16, 4x4 or 16x1 matrix
126
139
explicit Matx (const _Tp* vals); // !< initialize from a plain array
127
140
141
+ #ifdef CV_CXX11
142
+ Matx (std::initializer_list<_Tp>); // !< initialize from an initializer list
143
+ #endif
144
+
128
145
static Matx all (_Tp alpha);
129
146
static Matx zeros ();
130
147
static Matx ones ();
@@ -327,6 +344,10 @@ template<typename _Tp, int cn> class Vec : public Matx<_Tp, cn, 1>
327
344
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); // !< 14-element vector constructor
328
345
explicit Vec (const _Tp* values);
329
346
347
+ #ifdef CV_CXX11
348
+ Vec (std::initializer_list<_Tp>);
349
+ #endif
350
+
330
351
Vec (const Vec<_Tp, cn>& v);
331
352
332
353
static Vec all (_Tp alpha);
@@ -616,6 +637,19 @@ Matx<_Tp, m, n>::Matx(const _Tp* values)
616
637
for ( int i = 0 ; i < channels; i++ ) val[i] = values[i];
617
638
}
618
639
640
+ #ifdef CV_CXX11
641
+ template <typename _Tp, int m, int n> inline
642
+ Matx<_Tp, m, n>::Matx(std::initializer_list<_Tp> list)
643
+ {
644
+ CV_DbgAssert (list.size () == channels);
645
+ int i = 0 ;
646
+ for (const auto & elem : list)
647
+ {
648
+ val[i++] = elem;
649
+ }
650
+ }
651
+ #endif
652
+
619
653
template <typename _Tp, int m, int n> inline
620
654
Matx<_Tp, m, n> Matx<_Tp, m, n>::all(_Tp alpha)
621
655
{
@@ -957,6 +991,12 @@ template<typename _Tp, int cn> inline
957
991
Vec<_Tp, cn>::Vec(const _Tp* values)
958
992
: Matx<_Tp, cn, 1 >(values) {}
959
993
994
+ #ifdef CV_CXX11
995
+ template <typename _Tp, int cn> inline
996
+ Vec<_Tp, cn>::Vec(std::initializer_list<_Tp> list)
997
+ : Matx<_Tp, cn, 1 >(list) {}
998
+ #endif
999
+
960
1000
template <typename _Tp, int cn> inline
961
1001
Vec<_Tp, cn>::Vec(const Vec<_Tp, cn>& m)
962
1002
: Matx<_Tp, cn, 1 >(m.val) {}
@@ -1081,7 +1121,7 @@ Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& v)
1081
1121
1082
1122
1083
1123
1084
- // ////////////////////////////// matx comma initializer //////////////////////////////////
1124
+ // ////////////////////////////// vec comma initializer //////////////////////////////////
1085
1125
1086
1126
1087
1127
template <typename _Tp, typename _T2, int cn> static inline
0 commit comments