Joe Verbout
/
main
opencv on mbed
opencv2/core/matx.hpp@0:ea44dc9ed014, 2016-03-31 (annotated)
- Committer:
- joeverbout
- Date:
- Thu Mar 31 21:16:38 2016 +0000
- Revision:
- 0:ea44dc9ed014
OpenCV on mbed attempt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joeverbout | 0:ea44dc9ed014 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2 | // |
joeverbout | 0:ea44dc9ed014 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
joeverbout | 0:ea44dc9ed014 | 4 | // |
joeverbout | 0:ea44dc9ed014 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
joeverbout | 0:ea44dc9ed014 | 6 | // If you do not agree to this license, do not download, install, |
joeverbout | 0:ea44dc9ed014 | 7 | // copy or use the software. |
joeverbout | 0:ea44dc9ed014 | 8 | // |
joeverbout | 0:ea44dc9ed014 | 9 | // |
joeverbout | 0:ea44dc9ed014 | 10 | // License Agreement |
joeverbout | 0:ea44dc9ed014 | 11 | // For Open Source Computer Vision Library |
joeverbout | 0:ea44dc9ed014 | 12 | // |
joeverbout | 0:ea44dc9ed014 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 16 | // Third party copyrights are property of their respective owners. |
joeverbout | 0:ea44dc9ed014 | 17 | // |
joeverbout | 0:ea44dc9ed014 | 18 | // Redistribution and use in source and binary forms, with or without modification, |
joeverbout | 0:ea44dc9ed014 | 19 | // are permitted provided that the following conditions are met: |
joeverbout | 0:ea44dc9ed014 | 20 | // |
joeverbout | 0:ea44dc9ed014 | 21 | // * Redistribution's of source code must retain the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 22 | // this list of conditions and the following disclaimer. |
joeverbout | 0:ea44dc9ed014 | 23 | // |
joeverbout | 0:ea44dc9ed014 | 24 | // * Redistribution's in binary form must reproduce the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 25 | // this list of conditions and the following disclaimer in the documentation |
joeverbout | 0:ea44dc9ed014 | 26 | // and/or other materials provided with the distribution. |
joeverbout | 0:ea44dc9ed014 | 27 | // |
joeverbout | 0:ea44dc9ed014 | 28 | // * The name of the copyright holders may not be used to endorse or promote products |
joeverbout | 0:ea44dc9ed014 | 29 | // derived from this software without specific prior written permission. |
joeverbout | 0:ea44dc9ed014 | 30 | // |
joeverbout | 0:ea44dc9ed014 | 31 | // This software is provided by the copyright holders and contributors "as is" and |
joeverbout | 0:ea44dc9ed014 | 32 | // any express or implied warranties, including, but not limited to, the implied |
joeverbout | 0:ea44dc9ed014 | 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
joeverbout | 0:ea44dc9ed014 | 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
joeverbout | 0:ea44dc9ed014 | 35 | // indirect, incidental, special, exemplary, or consequential damages |
joeverbout | 0:ea44dc9ed014 | 36 | // (including, but not limited to, procurement of substitute goods or services; |
joeverbout | 0:ea44dc9ed014 | 37 | // loss of use, data, or profits; or business interruption) however caused |
joeverbout | 0:ea44dc9ed014 | 38 | // and on any theory of liability, whether in contract, strict liability, |
joeverbout | 0:ea44dc9ed014 | 39 | // or tort (including negligence or otherwise) arising in any way out of |
joeverbout | 0:ea44dc9ed014 | 40 | // the use of this software, even if advised of the possibility of such damage. |
joeverbout | 0:ea44dc9ed014 | 41 | // |
joeverbout | 0:ea44dc9ed014 | 42 | //M*/ |
joeverbout | 0:ea44dc9ed014 | 43 | |
joeverbout | 0:ea44dc9ed014 | 44 | #ifndef __OPENCV_CORE_MATX_HPP__ |
joeverbout | 0:ea44dc9ed014 | 45 | #define __OPENCV_CORE_MATX_HPP__ |
joeverbout | 0:ea44dc9ed014 | 46 | |
joeverbout | 0:ea44dc9ed014 | 47 | #ifndef __cplusplus |
joeverbout | 0:ea44dc9ed014 | 48 | # error matx.hpp header must be compiled as C++ |
joeverbout | 0:ea44dc9ed014 | 49 | #endif |
joeverbout | 0:ea44dc9ed014 | 50 | |
joeverbout | 0:ea44dc9ed014 | 51 | #include "opencv2/core/cvdef.h" |
joeverbout | 0:ea44dc9ed014 | 52 | #include "opencv2/core/base.hpp" |
joeverbout | 0:ea44dc9ed014 | 53 | #include "opencv2/core/traits.hpp" |
joeverbout | 0:ea44dc9ed014 | 54 | #include "opencv2/core/saturate.hpp" |
joeverbout | 0:ea44dc9ed014 | 55 | |
joeverbout | 0:ea44dc9ed014 | 56 | namespace cv |
joeverbout | 0:ea44dc9ed014 | 57 | { |
joeverbout | 0:ea44dc9ed014 | 58 | |
joeverbout | 0:ea44dc9ed014 | 59 | //! @addtogroup core_basic |
joeverbout | 0:ea44dc9ed014 | 60 | //! @{ |
joeverbout | 0:ea44dc9ed014 | 61 | |
joeverbout | 0:ea44dc9ed014 | 62 | ////////////////////////////// Small Matrix /////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 63 | |
joeverbout | 0:ea44dc9ed014 | 64 | //! @cond IGNORED |
joeverbout | 0:ea44dc9ed014 | 65 | struct CV_EXPORTS Matx_AddOp {}; |
joeverbout | 0:ea44dc9ed014 | 66 | struct CV_EXPORTS Matx_SubOp {}; |
joeverbout | 0:ea44dc9ed014 | 67 | struct CV_EXPORTS Matx_ScaleOp {}; |
joeverbout | 0:ea44dc9ed014 | 68 | struct CV_EXPORTS Matx_MulOp {}; |
joeverbout | 0:ea44dc9ed014 | 69 | struct CV_EXPORTS Matx_DivOp {}; |
joeverbout | 0:ea44dc9ed014 | 70 | struct CV_EXPORTS Matx_MatMulOp {}; |
joeverbout | 0:ea44dc9ed014 | 71 | struct CV_EXPORTS Matx_TOp {}; |
joeverbout | 0:ea44dc9ed014 | 72 | //! @endcond |
joeverbout | 0:ea44dc9ed014 | 73 | |
joeverbout | 0:ea44dc9ed014 | 74 | /** @brief Template class for small matrices whose type and size are known at compilation time |
joeverbout | 0:ea44dc9ed014 | 75 | |
joeverbout | 0:ea44dc9ed014 | 76 | If you need a more flexible type, use Mat . The elements of the matrix M are accessible using the |
joeverbout | 0:ea44dc9ed014 | 77 | M(i,j) notation. Most of the common matrix operations (see also @ref MatrixExpressions ) are |
joeverbout | 0:ea44dc9ed014 | 78 | available. To do an operation on Matx that is not implemented, you can easily convert the matrix to |
joeverbout | 0:ea44dc9ed014 | 79 | Mat and backwards: |
joeverbout | 0:ea44dc9ed014 | 80 | @code |
joeverbout | 0:ea44dc9ed014 | 81 | Matx33f m(1, 2, 3, |
joeverbout | 0:ea44dc9ed014 | 82 | 4, 5, 6, |
joeverbout | 0:ea44dc9ed014 | 83 | 7, 8, 9); |
joeverbout | 0:ea44dc9ed014 | 84 | cout << sum(Mat(m*m.t())) << endl; |
joeverbout | 0:ea44dc9ed014 | 85 | @endcode |
joeverbout | 0:ea44dc9ed014 | 86 | */ |
joeverbout | 0:ea44dc9ed014 | 87 | template<typename _Tp, int m, int n> class Matx |
joeverbout | 0:ea44dc9ed014 | 88 | { |
joeverbout | 0:ea44dc9ed014 | 89 | public: |
joeverbout | 0:ea44dc9ed014 | 90 | enum { depth = DataType<_Tp>::depth, |
joeverbout | 0:ea44dc9ed014 | 91 | rows = m, |
joeverbout | 0:ea44dc9ed014 | 92 | cols = n, |
joeverbout | 0:ea44dc9ed014 | 93 | channels = rows*cols, |
joeverbout | 0:ea44dc9ed014 | 94 | type = CV_MAKETYPE(depth, channels), |
joeverbout | 0:ea44dc9ed014 | 95 | shortdim = (m < n ? m : n) |
joeverbout | 0:ea44dc9ed014 | 96 | }; |
joeverbout | 0:ea44dc9ed014 | 97 | |
joeverbout | 0:ea44dc9ed014 | 98 | typedef _Tp value_type; |
joeverbout | 0:ea44dc9ed014 | 99 | typedef Matx<_Tp, m, n> mat_type; |
joeverbout | 0:ea44dc9ed014 | 100 | typedef Matx<_Tp, shortdim, 1> diag_type; |
joeverbout | 0:ea44dc9ed014 | 101 | |
joeverbout | 0:ea44dc9ed014 | 102 | //! default constructor |
joeverbout | 0:ea44dc9ed014 | 103 | Matx(); |
joeverbout | 0:ea44dc9ed014 | 104 | |
joeverbout | 0:ea44dc9ed014 | 105 | Matx(_Tp v0); //!< 1x1 matrix |
joeverbout | 0:ea44dc9ed014 | 106 | Matx(_Tp v0, _Tp v1); //!< 1x2 or 2x1 matrix |
joeverbout | 0:ea44dc9ed014 | 107 | Matx(_Tp v0, _Tp v1, _Tp v2); //!< 1x3 or 3x1 matrix |
joeverbout | 0:ea44dc9ed014 | 108 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 1x4, 2x2 or 4x1 matrix |
joeverbout | 0:ea44dc9ed014 | 109 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 1x5 or 5x1 matrix |
joeverbout | 0:ea44dc9ed014 | 110 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 1x6, 2x3, 3x2 or 6x1 matrix |
joeverbout | 0:ea44dc9ed014 | 111 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 1x7 or 7x1 matrix |
joeverbout | 0:ea44dc9ed014 | 112 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 1x8, 2x4, 4x2 or 8x1 matrix |
joeverbout | 0:ea44dc9ed014 | 113 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 1x9, 3x3 or 9x1 matrix |
joeverbout | 0:ea44dc9ed014 | 114 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 1x10, 2x5 or 5x2 or 10x1 matrix |
joeverbout | 0:ea44dc9ed014 | 115 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, |
joeverbout | 0:ea44dc9ed014 | 116 | _Tp v4, _Tp v5, _Tp v6, _Tp v7, |
joeverbout | 0:ea44dc9ed014 | 117 | _Tp v8, _Tp v9, _Tp v10, _Tp v11); //!< 1x12, 2x6, 3x4, 4x3, 6x2 or 12x1 matrix |
joeverbout | 0:ea44dc9ed014 | 118 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, |
joeverbout | 0:ea44dc9ed014 | 119 | _Tp v4, _Tp v5, _Tp v6, _Tp v7, |
joeverbout | 0:ea44dc9ed014 | 120 | _Tp v8, _Tp v9, _Tp v10, _Tp v11, |
joeverbout | 0:ea44dc9ed014 | 121 | _Tp v12, _Tp v13); //!< 1x14, 2x7, 7x2 or 14x1 matrix |
joeverbout | 0:ea44dc9ed014 | 122 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, |
joeverbout | 0:ea44dc9ed014 | 123 | _Tp v4, _Tp v5, _Tp v6, _Tp v7, |
joeverbout | 0:ea44dc9ed014 | 124 | _Tp v8, _Tp v9, _Tp v10, _Tp v11, |
joeverbout | 0:ea44dc9ed014 | 125 | _Tp v12, _Tp v13, _Tp v14, _Tp v15); //!< 1x16, 4x4 or 16x1 matrix |
joeverbout | 0:ea44dc9ed014 | 126 | explicit Matx(const _Tp* vals); //!< initialize from a plain array |
joeverbout | 0:ea44dc9ed014 | 127 | |
joeverbout | 0:ea44dc9ed014 | 128 | static Matx all(_Tp alpha); |
joeverbout | 0:ea44dc9ed014 | 129 | static Matx zeros(); |
joeverbout | 0:ea44dc9ed014 | 130 | static Matx ones(); |
joeverbout | 0:ea44dc9ed014 | 131 | static Matx eye(); |
joeverbout | 0:ea44dc9ed014 | 132 | static Matx diag(const diag_type& d); |
joeverbout | 0:ea44dc9ed014 | 133 | static Matx randu(_Tp a, _Tp b); |
joeverbout | 0:ea44dc9ed014 | 134 | static Matx randn(_Tp a, _Tp b); |
joeverbout | 0:ea44dc9ed014 | 135 | |
joeverbout | 0:ea44dc9ed014 | 136 | //! dot product computed with the default precision |
joeverbout | 0:ea44dc9ed014 | 137 | _Tp dot(const Matx<_Tp, m, n>& v) const; |
joeverbout | 0:ea44dc9ed014 | 138 | |
joeverbout | 0:ea44dc9ed014 | 139 | //! dot product computed in double-precision arithmetics |
joeverbout | 0:ea44dc9ed014 | 140 | double ddot(const Matx<_Tp, m, n>& v) const; |
joeverbout | 0:ea44dc9ed014 | 141 | |
joeverbout | 0:ea44dc9ed014 | 142 | //! conversion to another data type |
joeverbout | 0:ea44dc9ed014 | 143 | template<typename T2> operator Matx<T2, m, n>() const; |
joeverbout | 0:ea44dc9ed014 | 144 | |
joeverbout | 0:ea44dc9ed014 | 145 | //! change the matrix shape |
joeverbout | 0:ea44dc9ed014 | 146 | template<int m1, int n1> Matx<_Tp, m1, n1> reshape() const; |
joeverbout | 0:ea44dc9ed014 | 147 | |
joeverbout | 0:ea44dc9ed014 | 148 | //! extract part of the matrix |
joeverbout | 0:ea44dc9ed014 | 149 | template<int m1, int n1> Matx<_Tp, m1, n1> get_minor(int i, int j) const; |
joeverbout | 0:ea44dc9ed014 | 150 | |
joeverbout | 0:ea44dc9ed014 | 151 | //! extract the matrix row |
joeverbout | 0:ea44dc9ed014 | 152 | Matx<_Tp, 1, n> row(int i) const; |
joeverbout | 0:ea44dc9ed014 | 153 | |
joeverbout | 0:ea44dc9ed014 | 154 | //! extract the matrix column |
joeverbout | 0:ea44dc9ed014 | 155 | Matx<_Tp, m, 1> col(int i) const; |
joeverbout | 0:ea44dc9ed014 | 156 | |
joeverbout | 0:ea44dc9ed014 | 157 | //! extract the matrix diagonal |
joeverbout | 0:ea44dc9ed014 | 158 | diag_type diag() const; |
joeverbout | 0:ea44dc9ed014 | 159 | |
joeverbout | 0:ea44dc9ed014 | 160 | //! transpose the matrix |
joeverbout | 0:ea44dc9ed014 | 161 | Matx<_Tp, n, m> t() const; |
joeverbout | 0:ea44dc9ed014 | 162 | |
joeverbout | 0:ea44dc9ed014 | 163 | //! invert the matrix |
joeverbout | 0:ea44dc9ed014 | 164 | Matx<_Tp, n, m> inv(int method=DECOMP_LU, bool *p_is_ok = NULL) const; |
joeverbout | 0:ea44dc9ed014 | 165 | |
joeverbout | 0:ea44dc9ed014 | 166 | //! solve linear system |
joeverbout | 0:ea44dc9ed014 | 167 | template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const; |
joeverbout | 0:ea44dc9ed014 | 168 | Vec<_Tp, n> solve(const Vec<_Tp, m>& rhs, int method) const; |
joeverbout | 0:ea44dc9ed014 | 169 | |
joeverbout | 0:ea44dc9ed014 | 170 | //! multiply two matrices element-wise |
joeverbout | 0:ea44dc9ed014 | 171 | Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const; |
joeverbout | 0:ea44dc9ed014 | 172 | |
joeverbout | 0:ea44dc9ed014 | 173 | //! divide two matrices element-wise |
joeverbout | 0:ea44dc9ed014 | 174 | Matx<_Tp, m, n> div(const Matx<_Tp, m, n>& a) const; |
joeverbout | 0:ea44dc9ed014 | 175 | |
joeverbout | 0:ea44dc9ed014 | 176 | //! element access |
joeverbout | 0:ea44dc9ed014 | 177 | const _Tp& operator ()(int i, int j) const; |
joeverbout | 0:ea44dc9ed014 | 178 | _Tp& operator ()(int i, int j); |
joeverbout | 0:ea44dc9ed014 | 179 | |
joeverbout | 0:ea44dc9ed014 | 180 | //! 1D element access |
joeverbout | 0:ea44dc9ed014 | 181 | const _Tp& operator ()(int i) const; |
joeverbout | 0:ea44dc9ed014 | 182 | _Tp& operator ()(int i); |
joeverbout | 0:ea44dc9ed014 | 183 | |
joeverbout | 0:ea44dc9ed014 | 184 | Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp); |
joeverbout | 0:ea44dc9ed014 | 185 | Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp); |
joeverbout | 0:ea44dc9ed014 | 186 | template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp); |
joeverbout | 0:ea44dc9ed014 | 187 | Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp); |
joeverbout | 0:ea44dc9ed014 | 188 | Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp); |
joeverbout | 0:ea44dc9ed014 | 189 | template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp); |
joeverbout | 0:ea44dc9ed014 | 190 | Matx(const Matx<_Tp, n, m>& a, Matx_TOp); |
joeverbout | 0:ea44dc9ed014 | 191 | |
joeverbout | 0:ea44dc9ed014 | 192 | _Tp val[m*n]; //< matrix elements |
joeverbout | 0:ea44dc9ed014 | 193 | }; |
joeverbout | 0:ea44dc9ed014 | 194 | |
joeverbout | 0:ea44dc9ed014 | 195 | typedef Matx<float, 1, 2> Matx12f; |
joeverbout | 0:ea44dc9ed014 | 196 | typedef Matx<double, 1, 2> Matx12d; |
joeverbout | 0:ea44dc9ed014 | 197 | typedef Matx<float, 1, 3> Matx13f; |
joeverbout | 0:ea44dc9ed014 | 198 | typedef Matx<double, 1, 3> Matx13d; |
joeverbout | 0:ea44dc9ed014 | 199 | typedef Matx<float, 1, 4> Matx14f; |
joeverbout | 0:ea44dc9ed014 | 200 | typedef Matx<double, 1, 4> Matx14d; |
joeverbout | 0:ea44dc9ed014 | 201 | typedef Matx<float, 1, 6> Matx16f; |
joeverbout | 0:ea44dc9ed014 | 202 | typedef Matx<double, 1, 6> Matx16d; |
joeverbout | 0:ea44dc9ed014 | 203 | |
joeverbout | 0:ea44dc9ed014 | 204 | typedef Matx<float, 2, 1> Matx21f; |
joeverbout | 0:ea44dc9ed014 | 205 | typedef Matx<double, 2, 1> Matx21d; |
joeverbout | 0:ea44dc9ed014 | 206 | typedef Matx<float, 3, 1> Matx31f; |
joeverbout | 0:ea44dc9ed014 | 207 | typedef Matx<double, 3, 1> Matx31d; |
joeverbout | 0:ea44dc9ed014 | 208 | typedef Matx<float, 4, 1> Matx41f; |
joeverbout | 0:ea44dc9ed014 | 209 | typedef Matx<double, 4, 1> Matx41d; |
joeverbout | 0:ea44dc9ed014 | 210 | typedef Matx<float, 6, 1> Matx61f; |
joeverbout | 0:ea44dc9ed014 | 211 | typedef Matx<double, 6, 1> Matx61d; |
joeverbout | 0:ea44dc9ed014 | 212 | |
joeverbout | 0:ea44dc9ed014 | 213 | typedef Matx<float, 2, 2> Matx22f; |
joeverbout | 0:ea44dc9ed014 | 214 | typedef Matx<double, 2, 2> Matx22d; |
joeverbout | 0:ea44dc9ed014 | 215 | typedef Matx<float, 2, 3> Matx23f; |
joeverbout | 0:ea44dc9ed014 | 216 | typedef Matx<double, 2, 3> Matx23d; |
joeverbout | 0:ea44dc9ed014 | 217 | typedef Matx<float, 3, 2> Matx32f; |
joeverbout | 0:ea44dc9ed014 | 218 | typedef Matx<double, 3, 2> Matx32d; |
joeverbout | 0:ea44dc9ed014 | 219 | |
joeverbout | 0:ea44dc9ed014 | 220 | typedef Matx<float, 3, 3> Matx33f; |
joeverbout | 0:ea44dc9ed014 | 221 | typedef Matx<double, 3, 3> Matx33d; |
joeverbout | 0:ea44dc9ed014 | 222 | |
joeverbout | 0:ea44dc9ed014 | 223 | typedef Matx<float, 3, 4> Matx34f; |
joeverbout | 0:ea44dc9ed014 | 224 | typedef Matx<double, 3, 4> Matx34d; |
joeverbout | 0:ea44dc9ed014 | 225 | typedef Matx<float, 4, 3> Matx43f; |
joeverbout | 0:ea44dc9ed014 | 226 | typedef Matx<double, 4, 3> Matx43d; |
joeverbout | 0:ea44dc9ed014 | 227 | |
joeverbout | 0:ea44dc9ed014 | 228 | typedef Matx<float, 4, 4> Matx44f; |
joeverbout | 0:ea44dc9ed014 | 229 | typedef Matx<double, 4, 4> Matx44d; |
joeverbout | 0:ea44dc9ed014 | 230 | typedef Matx<float, 6, 6> Matx66f; |
joeverbout | 0:ea44dc9ed014 | 231 | typedef Matx<double, 6, 6> Matx66d; |
joeverbout | 0:ea44dc9ed014 | 232 | |
joeverbout | 0:ea44dc9ed014 | 233 | /*! |
joeverbout | 0:ea44dc9ed014 | 234 | traits |
joeverbout | 0:ea44dc9ed014 | 235 | */ |
joeverbout | 0:ea44dc9ed014 | 236 | template<typename _Tp, int m, int n> class DataType< Matx<_Tp, m, n> > |
joeverbout | 0:ea44dc9ed014 | 237 | { |
joeverbout | 0:ea44dc9ed014 | 238 | public: |
joeverbout | 0:ea44dc9ed014 | 239 | typedef Matx<_Tp, m, n> value_type; |
joeverbout | 0:ea44dc9ed014 | 240 | typedef Matx<typename DataType<_Tp>::work_type, m, n> work_type; |
joeverbout | 0:ea44dc9ed014 | 241 | typedef _Tp channel_type; |
joeverbout | 0:ea44dc9ed014 | 242 | typedef value_type vec_type; |
joeverbout | 0:ea44dc9ed014 | 243 | |
joeverbout | 0:ea44dc9ed014 | 244 | enum { generic_type = 0, |
joeverbout | 0:ea44dc9ed014 | 245 | depth = DataType<channel_type>::depth, |
joeverbout | 0:ea44dc9ed014 | 246 | channels = m * n, |
joeverbout | 0:ea44dc9ed014 | 247 | fmt = DataType<channel_type>::fmt + ((channels - 1) << 8), |
joeverbout | 0:ea44dc9ed014 | 248 | type = CV_MAKETYPE(depth, channels) |
joeverbout | 0:ea44dc9ed014 | 249 | }; |
joeverbout | 0:ea44dc9ed014 | 250 | }; |
joeverbout | 0:ea44dc9ed014 | 251 | |
joeverbout | 0:ea44dc9ed014 | 252 | /** @brief Comma-separated Matrix Initializer |
joeverbout | 0:ea44dc9ed014 | 253 | */ |
joeverbout | 0:ea44dc9ed014 | 254 | template<typename _Tp, int m, int n> class MatxCommaInitializer |
joeverbout | 0:ea44dc9ed014 | 255 | { |
joeverbout | 0:ea44dc9ed014 | 256 | public: |
joeverbout | 0:ea44dc9ed014 | 257 | MatxCommaInitializer(Matx<_Tp, m, n>* _mtx); |
joeverbout | 0:ea44dc9ed014 | 258 | template<typename T2> MatxCommaInitializer<_Tp, m, n>& operator , (T2 val); |
joeverbout | 0:ea44dc9ed014 | 259 | Matx<_Tp, m, n> operator *() const; |
joeverbout | 0:ea44dc9ed014 | 260 | |
joeverbout | 0:ea44dc9ed014 | 261 | Matx<_Tp, m, n>* dst; |
joeverbout | 0:ea44dc9ed014 | 262 | int idx; |
joeverbout | 0:ea44dc9ed014 | 263 | }; |
joeverbout | 0:ea44dc9ed014 | 264 | |
joeverbout | 0:ea44dc9ed014 | 265 | /* |
joeverbout | 0:ea44dc9ed014 | 266 | Utility methods |
joeverbout | 0:ea44dc9ed014 | 267 | */ |
joeverbout | 0:ea44dc9ed014 | 268 | template<typename _Tp, int m> static double determinant(const Matx<_Tp, m, m>& a); |
joeverbout | 0:ea44dc9ed014 | 269 | template<typename _Tp, int m, int n> static double trace(const Matx<_Tp, m, n>& a); |
joeverbout | 0:ea44dc9ed014 | 270 | template<typename _Tp, int m, int n> static double norm(const Matx<_Tp, m, n>& M); |
joeverbout | 0:ea44dc9ed014 | 271 | template<typename _Tp, int m, int n> static double norm(const Matx<_Tp, m, n>& M, int normType); |
joeverbout | 0:ea44dc9ed014 | 272 | |
joeverbout | 0:ea44dc9ed014 | 273 | |
joeverbout | 0:ea44dc9ed014 | 274 | |
joeverbout | 0:ea44dc9ed014 | 275 | /////////////////////// Vec (used as element of multi-channel images ///////////////////// |
joeverbout | 0:ea44dc9ed014 | 276 | |
joeverbout | 0:ea44dc9ed014 | 277 | /** @brief Template class for short numerical vectors, a partial case of Matx |
joeverbout | 0:ea44dc9ed014 | 278 | |
joeverbout | 0:ea44dc9ed014 | 279 | This template class represents short numerical vectors (of 1, 2, 3, 4 ... elements) on which you |
joeverbout | 0:ea44dc9ed014 | 280 | can perform basic arithmetical operations, access individual elements using [] operator etc. The |
joeverbout | 0:ea44dc9ed014 | 281 | vectors are allocated on stack, as opposite to std::valarray, std::vector, cv::Mat etc., which |
joeverbout | 0:ea44dc9ed014 | 282 | elements are dynamically allocated in the heap. |
joeverbout | 0:ea44dc9ed014 | 283 | |
joeverbout | 0:ea44dc9ed014 | 284 | The template takes 2 parameters: |
joeverbout | 0:ea44dc9ed014 | 285 | @tparam _Tp element type |
joeverbout | 0:ea44dc9ed014 | 286 | @tparam cn the number of elements |
joeverbout | 0:ea44dc9ed014 | 287 | |
joeverbout | 0:ea44dc9ed014 | 288 | In addition to the universal notation like Vec<float, 3>, you can use shorter aliases |
joeverbout | 0:ea44dc9ed014 | 289 | for the most popular specialized variants of Vec, e.g. Vec3f ~ Vec<float, 3>. |
joeverbout | 0:ea44dc9ed014 | 290 | |
joeverbout | 0:ea44dc9ed014 | 291 | It is possible to convert Vec\<T,2\> to/from Point_, Vec\<T,3\> to/from Point3_ , and Vec\<T,4\> |
joeverbout | 0:ea44dc9ed014 | 292 | to CvScalar or Scalar_. Use operator[] to access the elements of Vec. |
joeverbout | 0:ea44dc9ed014 | 293 | |
joeverbout | 0:ea44dc9ed014 | 294 | All the expected vector operations are also implemented: |
joeverbout | 0:ea44dc9ed014 | 295 | - v1 = v2 + v3 |
joeverbout | 0:ea44dc9ed014 | 296 | - v1 = v2 - v3 |
joeverbout | 0:ea44dc9ed014 | 297 | - v1 = v2 \* scale |
joeverbout | 0:ea44dc9ed014 | 298 | - v1 = scale \* v2 |
joeverbout | 0:ea44dc9ed014 | 299 | - v1 = -v2 |
joeverbout | 0:ea44dc9ed014 | 300 | - v1 += v2 and other augmenting operations |
joeverbout | 0:ea44dc9ed014 | 301 | - v1 == v2, v1 != v2 |
joeverbout | 0:ea44dc9ed014 | 302 | - norm(v1) (euclidean norm) |
joeverbout | 0:ea44dc9ed014 | 303 | The Vec class is commonly used to describe pixel types of multi-channel arrays. See Mat for details. |
joeverbout | 0:ea44dc9ed014 | 304 | */ |
joeverbout | 0:ea44dc9ed014 | 305 | template<typename _Tp, int cn> class Vec : public Matx<_Tp, cn, 1> |
joeverbout | 0:ea44dc9ed014 | 306 | { |
joeverbout | 0:ea44dc9ed014 | 307 | public: |
joeverbout | 0:ea44dc9ed014 | 308 | typedef _Tp value_type; |
joeverbout | 0:ea44dc9ed014 | 309 | enum { depth = Matx<_Tp, cn, 1>::depth, |
joeverbout | 0:ea44dc9ed014 | 310 | channels = cn, |
joeverbout | 0:ea44dc9ed014 | 311 | type = CV_MAKETYPE(depth, channels) |
joeverbout | 0:ea44dc9ed014 | 312 | }; |
joeverbout | 0:ea44dc9ed014 | 313 | |
joeverbout | 0:ea44dc9ed014 | 314 | //! default constructor |
joeverbout | 0:ea44dc9ed014 | 315 | Vec(); |
joeverbout | 0:ea44dc9ed014 | 316 | |
joeverbout | 0:ea44dc9ed014 | 317 | Vec(_Tp v0); //!< 1-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 318 | Vec(_Tp v0, _Tp v1); //!< 2-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 319 | Vec(_Tp v0, _Tp v1, _Tp v2); //!< 3-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 320 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 4-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 321 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 5-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 322 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 6-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 323 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 7-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 324 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 8-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 325 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 9-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 326 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 10-element vector constructor |
joeverbout | 0:ea44dc9ed014 | 327 | 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 |
joeverbout | 0:ea44dc9ed014 | 328 | explicit Vec(const _Tp* values); |
joeverbout | 0:ea44dc9ed014 | 329 | |
joeverbout | 0:ea44dc9ed014 | 330 | Vec(const Vec<_Tp, cn>& v); |
joeverbout | 0:ea44dc9ed014 | 331 | |
joeverbout | 0:ea44dc9ed014 | 332 | static Vec all(_Tp alpha); |
joeverbout | 0:ea44dc9ed014 | 333 | |
joeverbout | 0:ea44dc9ed014 | 334 | //! per-element multiplication |
joeverbout | 0:ea44dc9ed014 | 335 | Vec mul(const Vec<_Tp, cn>& v) const; |
joeverbout | 0:ea44dc9ed014 | 336 | |
joeverbout | 0:ea44dc9ed014 | 337 | //! conjugation (makes sense for complex numbers and quaternions) |
joeverbout | 0:ea44dc9ed014 | 338 | Vec conj() const; |
joeverbout | 0:ea44dc9ed014 | 339 | |
joeverbout | 0:ea44dc9ed014 | 340 | /*! |
joeverbout | 0:ea44dc9ed014 | 341 | cross product of the two 3D vectors. |
joeverbout | 0:ea44dc9ed014 | 342 | |
joeverbout | 0:ea44dc9ed014 | 343 | For other dimensionalities the exception is raised |
joeverbout | 0:ea44dc9ed014 | 344 | */ |
joeverbout | 0:ea44dc9ed014 | 345 | Vec cross(const Vec& v) const; |
joeverbout | 0:ea44dc9ed014 | 346 | //! conversion to another data type |
joeverbout | 0:ea44dc9ed014 | 347 | template<typename T2> operator Vec<T2, cn>() const; |
joeverbout | 0:ea44dc9ed014 | 348 | |
joeverbout | 0:ea44dc9ed014 | 349 | /*! element access */ |
joeverbout | 0:ea44dc9ed014 | 350 | const _Tp& operator [](int i) const; |
joeverbout | 0:ea44dc9ed014 | 351 | _Tp& operator[](int i); |
joeverbout | 0:ea44dc9ed014 | 352 | const _Tp& operator ()(int i) const; |
joeverbout | 0:ea44dc9ed014 | 353 | _Tp& operator ()(int i); |
joeverbout | 0:ea44dc9ed014 | 354 | |
joeverbout | 0:ea44dc9ed014 | 355 | Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp); |
joeverbout | 0:ea44dc9ed014 | 356 | Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp); |
joeverbout | 0:ea44dc9ed014 | 357 | template<typename _T2> Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp); |
joeverbout | 0:ea44dc9ed014 | 358 | }; |
joeverbout | 0:ea44dc9ed014 | 359 | |
joeverbout | 0:ea44dc9ed014 | 360 | /** @name Shorter aliases for the most popular specializations of Vec<T,n> |
joeverbout | 0:ea44dc9ed014 | 361 | @{ |
joeverbout | 0:ea44dc9ed014 | 362 | */ |
joeverbout | 0:ea44dc9ed014 | 363 | typedef Vec<uchar, 2> Vec2b; |
joeverbout | 0:ea44dc9ed014 | 364 | typedef Vec<uchar, 3> Vec3b; |
joeverbout | 0:ea44dc9ed014 | 365 | typedef Vec<uchar, 4> Vec4b; |
joeverbout | 0:ea44dc9ed014 | 366 | |
joeverbout | 0:ea44dc9ed014 | 367 | typedef Vec<short, 2> Vec2s; |
joeverbout | 0:ea44dc9ed014 | 368 | typedef Vec<short, 3> Vec3s; |
joeverbout | 0:ea44dc9ed014 | 369 | typedef Vec<short, 4> Vec4s; |
joeverbout | 0:ea44dc9ed014 | 370 | |
joeverbout | 0:ea44dc9ed014 | 371 | typedef Vec<ushort, 2> Vec2w; |
joeverbout | 0:ea44dc9ed014 | 372 | typedef Vec<ushort, 3> Vec3w; |
joeverbout | 0:ea44dc9ed014 | 373 | typedef Vec<ushort, 4> Vec4w; |
joeverbout | 0:ea44dc9ed014 | 374 | |
joeverbout | 0:ea44dc9ed014 | 375 | typedef Vec<int, 2> Vec2i; |
joeverbout | 0:ea44dc9ed014 | 376 | typedef Vec<int, 3> Vec3i; |
joeverbout | 0:ea44dc9ed014 | 377 | typedef Vec<int, 4> Vec4i; |
joeverbout | 0:ea44dc9ed014 | 378 | typedef Vec<int, 6> Vec6i; |
joeverbout | 0:ea44dc9ed014 | 379 | typedef Vec<int, 8> Vec8i; |
joeverbout | 0:ea44dc9ed014 | 380 | |
joeverbout | 0:ea44dc9ed014 | 381 | typedef Vec<float, 2> Vec2f; |
joeverbout | 0:ea44dc9ed014 | 382 | typedef Vec<float, 3> Vec3f; |
joeverbout | 0:ea44dc9ed014 | 383 | typedef Vec<float, 4> Vec4f; |
joeverbout | 0:ea44dc9ed014 | 384 | typedef Vec<float, 6> Vec6f; |
joeverbout | 0:ea44dc9ed014 | 385 | |
joeverbout | 0:ea44dc9ed014 | 386 | typedef Vec<double, 2> Vec2d; |
joeverbout | 0:ea44dc9ed014 | 387 | typedef Vec<double, 3> Vec3d; |
joeverbout | 0:ea44dc9ed014 | 388 | typedef Vec<double, 4> Vec4d; |
joeverbout | 0:ea44dc9ed014 | 389 | typedef Vec<double, 6> Vec6d; |
joeverbout | 0:ea44dc9ed014 | 390 | /** @} */ |
joeverbout | 0:ea44dc9ed014 | 391 | |
joeverbout | 0:ea44dc9ed014 | 392 | /*! |
joeverbout | 0:ea44dc9ed014 | 393 | traits |
joeverbout | 0:ea44dc9ed014 | 394 | */ |
joeverbout | 0:ea44dc9ed014 | 395 | template<typename _Tp, int cn> class DataType< Vec<_Tp, cn> > |
joeverbout | 0:ea44dc9ed014 | 396 | { |
joeverbout | 0:ea44dc9ed014 | 397 | public: |
joeverbout | 0:ea44dc9ed014 | 398 | typedef Vec<_Tp, cn> value_type; |
joeverbout | 0:ea44dc9ed014 | 399 | typedef Vec<typename DataType<_Tp>::work_type, cn> work_type; |
joeverbout | 0:ea44dc9ed014 | 400 | typedef _Tp channel_type; |
joeverbout | 0:ea44dc9ed014 | 401 | typedef value_type vec_type; |
joeverbout | 0:ea44dc9ed014 | 402 | |
joeverbout | 0:ea44dc9ed014 | 403 | enum { generic_type = 0, |
joeverbout | 0:ea44dc9ed014 | 404 | depth = DataType<channel_type>::depth, |
joeverbout | 0:ea44dc9ed014 | 405 | channels = cn, |
joeverbout | 0:ea44dc9ed014 | 406 | fmt = DataType<channel_type>::fmt + ((channels - 1) << 8), |
joeverbout | 0:ea44dc9ed014 | 407 | type = CV_MAKETYPE(depth, channels) |
joeverbout | 0:ea44dc9ed014 | 408 | }; |
joeverbout | 0:ea44dc9ed014 | 409 | }; |
joeverbout | 0:ea44dc9ed014 | 410 | |
joeverbout | 0:ea44dc9ed014 | 411 | /** @brief Comma-separated Vec Initializer |
joeverbout | 0:ea44dc9ed014 | 412 | */ |
joeverbout | 0:ea44dc9ed014 | 413 | template<typename _Tp, int m> class VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1> |
joeverbout | 0:ea44dc9ed014 | 414 | { |
joeverbout | 0:ea44dc9ed014 | 415 | public: |
joeverbout | 0:ea44dc9ed014 | 416 | VecCommaInitializer(Vec<_Tp, m>* _vec); |
joeverbout | 0:ea44dc9ed014 | 417 | template<typename T2> VecCommaInitializer<_Tp, m>& operator , (T2 val); |
joeverbout | 0:ea44dc9ed014 | 418 | Vec<_Tp, m> operator *() const; |
joeverbout | 0:ea44dc9ed014 | 419 | }; |
joeverbout | 0:ea44dc9ed014 | 420 | |
joeverbout | 0:ea44dc9ed014 | 421 | template<typename _Tp, int cn> static Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& v); |
joeverbout | 0:ea44dc9ed014 | 422 | |
joeverbout | 0:ea44dc9ed014 | 423 | //! @} core_basic |
joeverbout | 0:ea44dc9ed014 | 424 | |
joeverbout | 0:ea44dc9ed014 | 425 | //! @cond IGNORED |
joeverbout | 0:ea44dc9ed014 | 426 | |
joeverbout | 0:ea44dc9ed014 | 427 | ///////////////////////////////////// helper classes ///////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 428 | namespace internal |
joeverbout | 0:ea44dc9ed014 | 429 | { |
joeverbout | 0:ea44dc9ed014 | 430 | |
joeverbout | 0:ea44dc9ed014 | 431 | template<typename _Tp, int m> struct Matx_DetOp |
joeverbout | 0:ea44dc9ed014 | 432 | { |
joeverbout | 0:ea44dc9ed014 | 433 | double operator ()(const Matx<_Tp, m, m>& a) const |
joeverbout | 0:ea44dc9ed014 | 434 | { |
joeverbout | 0:ea44dc9ed014 | 435 | Matx<_Tp, m, m> temp = a; |
joeverbout | 0:ea44dc9ed014 | 436 | double p = LU(temp.val, m*sizeof(_Tp), m, 0, 0, 0); |
joeverbout | 0:ea44dc9ed014 | 437 | if( p == 0 ) |
joeverbout | 0:ea44dc9ed014 | 438 | return p; |
joeverbout | 0:ea44dc9ed014 | 439 | for( int i = 0; i < m; i++ ) |
joeverbout | 0:ea44dc9ed014 | 440 | p *= temp(i, i); |
joeverbout | 0:ea44dc9ed014 | 441 | return 1./p; |
joeverbout | 0:ea44dc9ed014 | 442 | } |
joeverbout | 0:ea44dc9ed014 | 443 | }; |
joeverbout | 0:ea44dc9ed014 | 444 | |
joeverbout | 0:ea44dc9ed014 | 445 | template<typename _Tp> struct Matx_DetOp<_Tp, 1> |
joeverbout | 0:ea44dc9ed014 | 446 | { |
joeverbout | 0:ea44dc9ed014 | 447 | double operator ()(const Matx<_Tp, 1, 1>& a) const |
joeverbout | 0:ea44dc9ed014 | 448 | { |
joeverbout | 0:ea44dc9ed014 | 449 | return a(0,0); |
joeverbout | 0:ea44dc9ed014 | 450 | } |
joeverbout | 0:ea44dc9ed014 | 451 | }; |
joeverbout | 0:ea44dc9ed014 | 452 | |
joeverbout | 0:ea44dc9ed014 | 453 | template<typename _Tp> struct Matx_DetOp<_Tp, 2> |
joeverbout | 0:ea44dc9ed014 | 454 | { |
joeverbout | 0:ea44dc9ed014 | 455 | double operator ()(const Matx<_Tp, 2, 2>& a) const |
joeverbout | 0:ea44dc9ed014 | 456 | { |
joeverbout | 0:ea44dc9ed014 | 457 | return a(0,0)*a(1,1) - a(0,1)*a(1,0); |
joeverbout | 0:ea44dc9ed014 | 458 | } |
joeverbout | 0:ea44dc9ed014 | 459 | }; |
joeverbout | 0:ea44dc9ed014 | 460 | |
joeverbout | 0:ea44dc9ed014 | 461 | template<typename _Tp> struct Matx_DetOp<_Tp, 3> |
joeverbout | 0:ea44dc9ed014 | 462 | { |
joeverbout | 0:ea44dc9ed014 | 463 | double operator ()(const Matx<_Tp, 3, 3>& a) const |
joeverbout | 0:ea44dc9ed014 | 464 | { |
joeverbout | 0:ea44dc9ed014 | 465 | return a(0,0)*(a(1,1)*a(2,2) - a(2,1)*a(1,2)) - |
joeverbout | 0:ea44dc9ed014 | 466 | a(0,1)*(a(1,0)*a(2,2) - a(2,0)*a(1,2)) + |
joeverbout | 0:ea44dc9ed014 | 467 | a(0,2)*(a(1,0)*a(2,1) - a(2,0)*a(1,1)); |
joeverbout | 0:ea44dc9ed014 | 468 | } |
joeverbout | 0:ea44dc9ed014 | 469 | }; |
joeverbout | 0:ea44dc9ed014 | 470 | |
joeverbout | 0:ea44dc9ed014 | 471 | template<typename _Tp> Vec<_Tp, 2> inline conjugate(const Vec<_Tp, 2>& v) |
joeverbout | 0:ea44dc9ed014 | 472 | { |
joeverbout | 0:ea44dc9ed014 | 473 | return Vec<_Tp, 2>(v[0], -v[1]); |
joeverbout | 0:ea44dc9ed014 | 474 | } |
joeverbout | 0:ea44dc9ed014 | 475 | |
joeverbout | 0:ea44dc9ed014 | 476 | template<typename _Tp> Vec<_Tp, 4> inline conjugate(const Vec<_Tp, 4>& v) |
joeverbout | 0:ea44dc9ed014 | 477 | { |
joeverbout | 0:ea44dc9ed014 | 478 | return Vec<_Tp, 4>(v[0], -v[1], -v[2], -v[3]); |
joeverbout | 0:ea44dc9ed014 | 479 | } |
joeverbout | 0:ea44dc9ed014 | 480 | |
joeverbout | 0:ea44dc9ed014 | 481 | } // internal |
joeverbout | 0:ea44dc9ed014 | 482 | |
joeverbout | 0:ea44dc9ed014 | 483 | |
joeverbout | 0:ea44dc9ed014 | 484 | |
joeverbout | 0:ea44dc9ed014 | 485 | ////////////////////////////////// Matx Implementation /////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 486 | |
joeverbout | 0:ea44dc9ed014 | 487 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 488 | Matx<_Tp, m, n>::Matx() |
joeverbout | 0:ea44dc9ed014 | 489 | { |
joeverbout | 0:ea44dc9ed014 | 490 | for(int i = 0; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 491 | } |
joeverbout | 0:ea44dc9ed014 | 492 | |
joeverbout | 0:ea44dc9ed014 | 493 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 494 | Matx<_Tp, m, n>::Matx(_Tp v0) |
joeverbout | 0:ea44dc9ed014 | 495 | { |
joeverbout | 0:ea44dc9ed014 | 496 | val[0] = v0; |
joeverbout | 0:ea44dc9ed014 | 497 | for(int i = 1; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 498 | } |
joeverbout | 0:ea44dc9ed014 | 499 | |
joeverbout | 0:ea44dc9ed014 | 500 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 501 | Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1) |
joeverbout | 0:ea44dc9ed014 | 502 | { |
joeverbout | 0:ea44dc9ed014 | 503 | CV_StaticAssert(channels >= 2, "Matx should have at least 2 elements."); |
joeverbout | 0:ea44dc9ed014 | 504 | val[0] = v0; val[1] = v1; |
joeverbout | 0:ea44dc9ed014 | 505 | for(int i = 2; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 506 | } |
joeverbout | 0:ea44dc9ed014 | 507 | |
joeverbout | 0:ea44dc9ed014 | 508 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 509 | Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2) |
joeverbout | 0:ea44dc9ed014 | 510 | { |
joeverbout | 0:ea44dc9ed014 | 511 | CV_StaticAssert(channels >= 3, "Matx should have at least 3 elements."); |
joeverbout | 0:ea44dc9ed014 | 512 | val[0] = v0; val[1] = v1; val[2] = v2; |
joeverbout | 0:ea44dc9ed014 | 513 | for(int i = 3; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 514 | } |
joeverbout | 0:ea44dc9ed014 | 515 | |
joeverbout | 0:ea44dc9ed014 | 516 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 517 | Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3) |
joeverbout | 0:ea44dc9ed014 | 518 | { |
joeverbout | 0:ea44dc9ed014 | 519 | CV_StaticAssert(channels >= 4, "Matx should have at least 4 elements."); |
joeverbout | 0:ea44dc9ed014 | 520 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; |
joeverbout | 0:ea44dc9ed014 | 521 | for(int i = 4; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 522 | } |
joeverbout | 0:ea44dc9ed014 | 523 | |
joeverbout | 0:ea44dc9ed014 | 524 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 525 | Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4) |
joeverbout | 0:ea44dc9ed014 | 526 | { |
joeverbout | 0:ea44dc9ed014 | 527 | CV_StaticAssert(channels >= 5, "Matx should have at least 5 elements."); |
joeverbout | 0:ea44dc9ed014 | 528 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; val[4] = v4; |
joeverbout | 0:ea44dc9ed014 | 529 | for(int i = 5; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 530 | } |
joeverbout | 0:ea44dc9ed014 | 531 | |
joeverbout | 0:ea44dc9ed014 | 532 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 533 | Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5) |
joeverbout | 0:ea44dc9ed014 | 534 | { |
joeverbout | 0:ea44dc9ed014 | 535 | CV_StaticAssert(channels >= 6, "Matx should have at least 6 elements."); |
joeverbout | 0:ea44dc9ed014 | 536 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; |
joeverbout | 0:ea44dc9ed014 | 537 | val[4] = v4; val[5] = v5; |
joeverbout | 0:ea44dc9ed014 | 538 | for(int i = 6; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 539 | } |
joeverbout | 0:ea44dc9ed014 | 540 | |
joeverbout | 0:ea44dc9ed014 | 541 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 542 | Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6) |
joeverbout | 0:ea44dc9ed014 | 543 | { |
joeverbout | 0:ea44dc9ed014 | 544 | CV_StaticAssert(channels >= 7, "Matx should have at least 7 elements."); |
joeverbout | 0:ea44dc9ed014 | 545 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; |
joeverbout | 0:ea44dc9ed014 | 546 | val[4] = v4; val[5] = v5; val[6] = v6; |
joeverbout | 0:ea44dc9ed014 | 547 | for(int i = 7; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 548 | } |
joeverbout | 0:ea44dc9ed014 | 549 | |
joeverbout | 0:ea44dc9ed014 | 550 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 551 | Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7) |
joeverbout | 0:ea44dc9ed014 | 552 | { |
joeverbout | 0:ea44dc9ed014 | 553 | CV_StaticAssert(channels >= 8, "Matx should have at least 8 elements."); |
joeverbout | 0:ea44dc9ed014 | 554 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; |
joeverbout | 0:ea44dc9ed014 | 555 | val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; |
joeverbout | 0:ea44dc9ed014 | 556 | for(int i = 8; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 557 | } |
joeverbout | 0:ea44dc9ed014 | 558 | |
joeverbout | 0:ea44dc9ed014 | 559 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 560 | Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8) |
joeverbout | 0:ea44dc9ed014 | 561 | { |
joeverbout | 0:ea44dc9ed014 | 562 | CV_StaticAssert(channels >= 9, "Matx should have at least 9 elements."); |
joeverbout | 0:ea44dc9ed014 | 563 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; |
joeverbout | 0:ea44dc9ed014 | 564 | val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; |
joeverbout | 0:ea44dc9ed014 | 565 | val[8] = v8; |
joeverbout | 0:ea44dc9ed014 | 566 | for(int i = 9; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 567 | } |
joeverbout | 0:ea44dc9ed014 | 568 | |
joeverbout | 0:ea44dc9ed014 | 569 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 570 | 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) |
joeverbout | 0:ea44dc9ed014 | 571 | { |
joeverbout | 0:ea44dc9ed014 | 572 | CV_StaticAssert(channels >= 10, "Matx should have at least 10 elements."); |
joeverbout | 0:ea44dc9ed014 | 573 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; |
joeverbout | 0:ea44dc9ed014 | 574 | val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; |
joeverbout | 0:ea44dc9ed014 | 575 | val[8] = v8; val[9] = v9; |
joeverbout | 0:ea44dc9ed014 | 576 | for(int i = 10; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 577 | } |
joeverbout | 0:ea44dc9ed014 | 578 | |
joeverbout | 0:ea44dc9ed014 | 579 | |
joeverbout | 0:ea44dc9ed014 | 580 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 581 | 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) |
joeverbout | 0:ea44dc9ed014 | 582 | { |
joeverbout | 0:ea44dc9ed014 | 583 | CV_StaticAssert(channels >= 12, "Matx should have at least 12 elements."); |
joeverbout | 0:ea44dc9ed014 | 584 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; |
joeverbout | 0:ea44dc9ed014 | 585 | val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; |
joeverbout | 0:ea44dc9ed014 | 586 | val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; |
joeverbout | 0:ea44dc9ed014 | 587 | for(int i = 12; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 588 | } |
joeverbout | 0:ea44dc9ed014 | 589 | |
joeverbout | 0:ea44dc9ed014 | 590 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 591 | 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) |
joeverbout | 0:ea44dc9ed014 | 592 | { |
joeverbout | 0:ea44dc9ed014 | 593 | CV_StaticAssert(channels == 14, "Matx should have at least 14 elements."); |
joeverbout | 0:ea44dc9ed014 | 594 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; |
joeverbout | 0:ea44dc9ed014 | 595 | val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; |
joeverbout | 0:ea44dc9ed014 | 596 | val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; |
joeverbout | 0:ea44dc9ed014 | 597 | val[12] = v12; val[13] = v13; |
joeverbout | 0:ea44dc9ed014 | 598 | } |
joeverbout | 0:ea44dc9ed014 | 599 | |
joeverbout | 0:ea44dc9ed014 | 600 | |
joeverbout | 0:ea44dc9ed014 | 601 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 602 | 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) |
joeverbout | 0:ea44dc9ed014 | 603 | { |
joeverbout | 0:ea44dc9ed014 | 604 | CV_StaticAssert(channels >= 16, "Matx should have at least 16 elements."); |
joeverbout | 0:ea44dc9ed014 | 605 | val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; |
joeverbout | 0:ea44dc9ed014 | 606 | val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; |
joeverbout | 0:ea44dc9ed014 | 607 | val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; |
joeverbout | 0:ea44dc9ed014 | 608 | val[12] = v12; val[13] = v13; val[14] = v14; val[15] = v15; |
joeverbout | 0:ea44dc9ed014 | 609 | for(int i = 16; i < channels; i++) val[i] = _Tp(0); |
joeverbout | 0:ea44dc9ed014 | 610 | } |
joeverbout | 0:ea44dc9ed014 | 611 | |
joeverbout | 0:ea44dc9ed014 | 612 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 613 | Matx<_Tp, m, n>::Matx(const _Tp* values) |
joeverbout | 0:ea44dc9ed014 | 614 | { |
joeverbout | 0:ea44dc9ed014 | 615 | for( int i = 0; i < channels; i++ ) val[i] = values[i]; |
joeverbout | 0:ea44dc9ed014 | 616 | } |
joeverbout | 0:ea44dc9ed014 | 617 | |
joeverbout | 0:ea44dc9ed014 | 618 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 619 | Matx<_Tp, m, n> Matx<_Tp, m, n>::all(_Tp alpha) |
joeverbout | 0:ea44dc9ed014 | 620 | { |
joeverbout | 0:ea44dc9ed014 | 621 | Matx<_Tp, m, n> M; |
joeverbout | 0:ea44dc9ed014 | 622 | for( int i = 0; i < m*n; i++ ) M.val[i] = alpha; |
joeverbout | 0:ea44dc9ed014 | 623 | return M; |
joeverbout | 0:ea44dc9ed014 | 624 | } |
joeverbout | 0:ea44dc9ed014 | 625 | |
joeverbout | 0:ea44dc9ed014 | 626 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 627 | Matx<_Tp,m,n> Matx<_Tp,m,n>::zeros() |
joeverbout | 0:ea44dc9ed014 | 628 | { |
joeverbout | 0:ea44dc9ed014 | 629 | return all(0); |
joeverbout | 0:ea44dc9ed014 | 630 | } |
joeverbout | 0:ea44dc9ed014 | 631 | |
joeverbout | 0:ea44dc9ed014 | 632 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 633 | Matx<_Tp,m,n> Matx<_Tp,m,n>::ones() |
joeverbout | 0:ea44dc9ed014 | 634 | { |
joeverbout | 0:ea44dc9ed014 | 635 | return all(1); |
joeverbout | 0:ea44dc9ed014 | 636 | } |
joeverbout | 0:ea44dc9ed014 | 637 | |
joeverbout | 0:ea44dc9ed014 | 638 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 639 | Matx<_Tp,m,n> Matx<_Tp,m,n>::eye() |
joeverbout | 0:ea44dc9ed014 | 640 | { |
joeverbout | 0:ea44dc9ed014 | 641 | Matx<_Tp,m,n> M; |
joeverbout | 0:ea44dc9ed014 | 642 | for(int i = 0; i < shortdim; i++) |
joeverbout | 0:ea44dc9ed014 | 643 | M(i,i) = 1; |
joeverbout | 0:ea44dc9ed014 | 644 | return M; |
joeverbout | 0:ea44dc9ed014 | 645 | } |
joeverbout | 0:ea44dc9ed014 | 646 | |
joeverbout | 0:ea44dc9ed014 | 647 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 648 | _Tp Matx<_Tp, m, n>::dot(const Matx<_Tp, m, n>& M) const |
joeverbout | 0:ea44dc9ed014 | 649 | { |
joeverbout | 0:ea44dc9ed014 | 650 | _Tp s = 0; |
joeverbout | 0:ea44dc9ed014 | 651 | for( int i = 0; i < channels; i++ ) s += val[i]*M.val[i]; |
joeverbout | 0:ea44dc9ed014 | 652 | return s; |
joeverbout | 0:ea44dc9ed014 | 653 | } |
joeverbout | 0:ea44dc9ed014 | 654 | |
joeverbout | 0:ea44dc9ed014 | 655 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 656 | double Matx<_Tp, m, n>::ddot(const Matx<_Tp, m, n>& M) const |
joeverbout | 0:ea44dc9ed014 | 657 | { |
joeverbout | 0:ea44dc9ed014 | 658 | double s = 0; |
joeverbout | 0:ea44dc9ed014 | 659 | for( int i = 0; i < channels; i++ ) s += (double)val[i]*M.val[i]; |
joeverbout | 0:ea44dc9ed014 | 660 | return s; |
joeverbout | 0:ea44dc9ed014 | 661 | } |
joeverbout | 0:ea44dc9ed014 | 662 | |
joeverbout | 0:ea44dc9ed014 | 663 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 664 | Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const typename Matx<_Tp,m,n>::diag_type& d) |
joeverbout | 0:ea44dc9ed014 | 665 | { |
joeverbout | 0:ea44dc9ed014 | 666 | Matx<_Tp,m,n> M; |
joeverbout | 0:ea44dc9ed014 | 667 | for(int i = 0; i < shortdim; i++) |
joeverbout | 0:ea44dc9ed014 | 668 | M(i,i) = d(i, 0); |
joeverbout | 0:ea44dc9ed014 | 669 | return M; |
joeverbout | 0:ea44dc9ed014 | 670 | } |
joeverbout | 0:ea44dc9ed014 | 671 | |
joeverbout | 0:ea44dc9ed014 | 672 | template<typename _Tp, int m, int n> template<typename T2> |
joeverbout | 0:ea44dc9ed014 | 673 | inline Matx<_Tp, m, n>::operator Matx<T2, m, n>() const |
joeverbout | 0:ea44dc9ed014 | 674 | { |
joeverbout | 0:ea44dc9ed014 | 675 | Matx<T2, m, n> M; |
joeverbout | 0:ea44dc9ed014 | 676 | for( int i = 0; i < m*n; i++ ) M.val[i] = saturate_cast<T2>(val[i]); |
joeverbout | 0:ea44dc9ed014 | 677 | return M; |
joeverbout | 0:ea44dc9ed014 | 678 | } |
joeverbout | 0:ea44dc9ed014 | 679 | |
joeverbout | 0:ea44dc9ed014 | 680 | template<typename _Tp, int m, int n> template<int m1, int n1> inline |
joeverbout | 0:ea44dc9ed014 | 681 | Matx<_Tp, m1, n1> Matx<_Tp, m, n>::reshape() const |
joeverbout | 0:ea44dc9ed014 | 682 | { |
joeverbout | 0:ea44dc9ed014 | 683 | CV_StaticAssert(m1*n1 == m*n, "Input and destnarion matrices must have the same number of elements"); |
joeverbout | 0:ea44dc9ed014 | 684 | return (const Matx<_Tp, m1, n1>&)*this; |
joeverbout | 0:ea44dc9ed014 | 685 | } |
joeverbout | 0:ea44dc9ed014 | 686 | |
joeverbout | 0:ea44dc9ed014 | 687 | template<typename _Tp, int m, int n> |
joeverbout | 0:ea44dc9ed014 | 688 | template<int m1, int n1> inline |
joeverbout | 0:ea44dc9ed014 | 689 | Matx<_Tp, m1, n1> Matx<_Tp, m, n>::get_minor(int i, int j) const |
joeverbout | 0:ea44dc9ed014 | 690 | { |
joeverbout | 0:ea44dc9ed014 | 691 | CV_DbgAssert(0 <= i && i+m1 <= m && 0 <= j && j+n1 <= n); |
joeverbout | 0:ea44dc9ed014 | 692 | Matx<_Tp, m1, n1> s; |
joeverbout | 0:ea44dc9ed014 | 693 | for( int di = 0; di < m1; di++ ) |
joeverbout | 0:ea44dc9ed014 | 694 | for( int dj = 0; dj < n1; dj++ ) |
joeverbout | 0:ea44dc9ed014 | 695 | s(di, dj) = (*this)(i+di, j+dj); |
joeverbout | 0:ea44dc9ed014 | 696 | return s; |
joeverbout | 0:ea44dc9ed014 | 697 | } |
joeverbout | 0:ea44dc9ed014 | 698 | |
joeverbout | 0:ea44dc9ed014 | 699 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 700 | Matx<_Tp, 1, n> Matx<_Tp, m, n>::row(int i) const |
joeverbout | 0:ea44dc9ed014 | 701 | { |
joeverbout | 0:ea44dc9ed014 | 702 | CV_DbgAssert((unsigned)i < (unsigned)m); |
joeverbout | 0:ea44dc9ed014 | 703 | return Matx<_Tp, 1, n>(&val[i*n]); |
joeverbout | 0:ea44dc9ed014 | 704 | } |
joeverbout | 0:ea44dc9ed014 | 705 | |
joeverbout | 0:ea44dc9ed014 | 706 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 707 | Matx<_Tp, m, 1> Matx<_Tp, m, n>::col(int j) const |
joeverbout | 0:ea44dc9ed014 | 708 | { |
joeverbout | 0:ea44dc9ed014 | 709 | CV_DbgAssert((unsigned)j < (unsigned)n); |
joeverbout | 0:ea44dc9ed014 | 710 | Matx<_Tp, m, 1> v; |
joeverbout | 0:ea44dc9ed014 | 711 | for( int i = 0; i < m; i++ ) |
joeverbout | 0:ea44dc9ed014 | 712 | v.val[i] = val[i*n + j]; |
joeverbout | 0:ea44dc9ed014 | 713 | return v; |
joeverbout | 0:ea44dc9ed014 | 714 | } |
joeverbout | 0:ea44dc9ed014 | 715 | |
joeverbout | 0:ea44dc9ed014 | 716 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 717 | typename Matx<_Tp, m, n>::diag_type Matx<_Tp, m, n>::diag() const |
joeverbout | 0:ea44dc9ed014 | 718 | { |
joeverbout | 0:ea44dc9ed014 | 719 | diag_type d; |
joeverbout | 0:ea44dc9ed014 | 720 | for( int i = 0; i < shortdim; i++ ) |
joeverbout | 0:ea44dc9ed014 | 721 | d.val[i] = val[i*n + i]; |
joeverbout | 0:ea44dc9ed014 | 722 | return d; |
joeverbout | 0:ea44dc9ed014 | 723 | } |
joeverbout | 0:ea44dc9ed014 | 724 | |
joeverbout | 0:ea44dc9ed014 | 725 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 726 | const _Tp& Matx<_Tp, m, n>::operator()(int i, int j) const |
joeverbout | 0:ea44dc9ed014 | 727 | { |
joeverbout | 0:ea44dc9ed014 | 728 | CV_DbgAssert( (unsigned)i < (unsigned)m && (unsigned)j < (unsigned)n ); |
joeverbout | 0:ea44dc9ed014 | 729 | return this->val[i*n + j]; |
joeverbout | 0:ea44dc9ed014 | 730 | } |
joeverbout | 0:ea44dc9ed014 | 731 | |
joeverbout | 0:ea44dc9ed014 | 732 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 733 | _Tp& Matx<_Tp, m, n>::operator ()(int i, int j) |
joeverbout | 0:ea44dc9ed014 | 734 | { |
joeverbout | 0:ea44dc9ed014 | 735 | CV_DbgAssert( (unsigned)i < (unsigned)m && (unsigned)j < (unsigned)n ); |
joeverbout | 0:ea44dc9ed014 | 736 | return val[i*n + j]; |
joeverbout | 0:ea44dc9ed014 | 737 | } |
joeverbout | 0:ea44dc9ed014 | 738 | |
joeverbout | 0:ea44dc9ed014 | 739 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 740 | const _Tp& Matx<_Tp, m, n>::operator ()(int i) const |
joeverbout | 0:ea44dc9ed014 | 741 | { |
joeverbout | 0:ea44dc9ed014 | 742 | CV_StaticAssert(m == 1 || n == 1, "Single index indexation requires matrix to be a column or a row"); |
joeverbout | 0:ea44dc9ed014 | 743 | CV_DbgAssert( (unsigned)i < (unsigned)(m+n-1) ); |
joeverbout | 0:ea44dc9ed014 | 744 | return val[i]; |
joeverbout | 0:ea44dc9ed014 | 745 | } |
joeverbout | 0:ea44dc9ed014 | 746 | |
joeverbout | 0:ea44dc9ed014 | 747 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 748 | _Tp& Matx<_Tp, m, n>::operator ()(int i) |
joeverbout | 0:ea44dc9ed014 | 749 | { |
joeverbout | 0:ea44dc9ed014 | 750 | CV_StaticAssert(m == 1 || n == 1, "Single index indexation requires matrix to be a column or a row"); |
joeverbout | 0:ea44dc9ed014 | 751 | CV_DbgAssert( (unsigned)i < (unsigned)(m+n-1) ); |
joeverbout | 0:ea44dc9ed014 | 752 | return val[i]; |
joeverbout | 0:ea44dc9ed014 | 753 | } |
joeverbout | 0:ea44dc9ed014 | 754 | |
joeverbout | 0:ea44dc9ed014 | 755 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 756 | Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp) |
joeverbout | 0:ea44dc9ed014 | 757 | { |
joeverbout | 0:ea44dc9ed014 | 758 | for( int i = 0; i < channels; i++ ) |
joeverbout | 0:ea44dc9ed014 | 759 | val[i] = saturate_cast<_Tp>(a.val[i] + b.val[i]); |
joeverbout | 0:ea44dc9ed014 | 760 | } |
joeverbout | 0:ea44dc9ed014 | 761 | |
joeverbout | 0:ea44dc9ed014 | 762 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 763 | Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp) |
joeverbout | 0:ea44dc9ed014 | 764 | { |
joeverbout | 0:ea44dc9ed014 | 765 | for( int i = 0; i < channels; i++ ) |
joeverbout | 0:ea44dc9ed014 | 766 | val[i] = saturate_cast<_Tp>(a.val[i] - b.val[i]); |
joeverbout | 0:ea44dc9ed014 | 767 | } |
joeverbout | 0:ea44dc9ed014 | 768 | |
joeverbout | 0:ea44dc9ed014 | 769 | template<typename _Tp, int m, int n> template<typename _T2> inline |
joeverbout | 0:ea44dc9ed014 | 770 | Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp) |
joeverbout | 0:ea44dc9ed014 | 771 | { |
joeverbout | 0:ea44dc9ed014 | 772 | for( int i = 0; i < channels; i++ ) |
joeverbout | 0:ea44dc9ed014 | 773 | val[i] = saturate_cast<_Tp>(a.val[i] * alpha); |
joeverbout | 0:ea44dc9ed014 | 774 | } |
joeverbout | 0:ea44dc9ed014 | 775 | |
joeverbout | 0:ea44dc9ed014 | 776 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 777 | Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp) |
joeverbout | 0:ea44dc9ed014 | 778 | { |
joeverbout | 0:ea44dc9ed014 | 779 | for( int i = 0; i < channels; i++ ) |
joeverbout | 0:ea44dc9ed014 | 780 | val[i] = saturate_cast<_Tp>(a.val[i] * b.val[i]); |
joeverbout | 0:ea44dc9ed014 | 781 | } |
joeverbout | 0:ea44dc9ed014 | 782 | |
joeverbout | 0:ea44dc9ed014 | 783 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 784 | Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp) |
joeverbout | 0:ea44dc9ed014 | 785 | { |
joeverbout | 0:ea44dc9ed014 | 786 | for( int i = 0; i < channels; i++ ) |
joeverbout | 0:ea44dc9ed014 | 787 | val[i] = saturate_cast<_Tp>(a.val[i] / b.val[i]); |
joeverbout | 0:ea44dc9ed014 | 788 | } |
joeverbout | 0:ea44dc9ed014 | 789 | |
joeverbout | 0:ea44dc9ed014 | 790 | template<typename _Tp, int m, int n> template<int l> inline |
joeverbout | 0:ea44dc9ed014 | 791 | Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp) |
joeverbout | 0:ea44dc9ed014 | 792 | { |
joeverbout | 0:ea44dc9ed014 | 793 | for( int i = 0; i < m; i++ ) |
joeverbout | 0:ea44dc9ed014 | 794 | for( int j = 0; j < n; j++ ) |
joeverbout | 0:ea44dc9ed014 | 795 | { |
joeverbout | 0:ea44dc9ed014 | 796 | _Tp s = 0; |
joeverbout | 0:ea44dc9ed014 | 797 | for( int k = 0; k < l; k++ ) |
joeverbout | 0:ea44dc9ed014 | 798 | s += a(i, k) * b(k, j); |
joeverbout | 0:ea44dc9ed014 | 799 | val[i*n + j] = s; |
joeverbout | 0:ea44dc9ed014 | 800 | } |
joeverbout | 0:ea44dc9ed014 | 801 | } |
joeverbout | 0:ea44dc9ed014 | 802 | |
joeverbout | 0:ea44dc9ed014 | 803 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 804 | Matx<_Tp,m,n>::Matx(const Matx<_Tp, n, m>& a, Matx_TOp) |
joeverbout | 0:ea44dc9ed014 | 805 | { |
joeverbout | 0:ea44dc9ed014 | 806 | for( int i = 0; i < m; i++ ) |
joeverbout | 0:ea44dc9ed014 | 807 | for( int j = 0; j < n; j++ ) |
joeverbout | 0:ea44dc9ed014 | 808 | val[i*n + j] = a(j, i); |
joeverbout | 0:ea44dc9ed014 | 809 | } |
joeverbout | 0:ea44dc9ed014 | 810 | |
joeverbout | 0:ea44dc9ed014 | 811 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 812 | Matx<_Tp, m, n> Matx<_Tp, m, n>::mul(const Matx<_Tp, m, n>& a) const |
joeverbout | 0:ea44dc9ed014 | 813 | { |
joeverbout | 0:ea44dc9ed014 | 814 | return Matx<_Tp, m, n>(*this, a, Matx_MulOp()); |
joeverbout | 0:ea44dc9ed014 | 815 | } |
joeverbout | 0:ea44dc9ed014 | 816 | |
joeverbout | 0:ea44dc9ed014 | 817 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 818 | Matx<_Tp, m, n> Matx<_Tp, m, n>::div(const Matx<_Tp, m, n>& a) const |
joeverbout | 0:ea44dc9ed014 | 819 | { |
joeverbout | 0:ea44dc9ed014 | 820 | return Matx<_Tp, m, n>(*this, a, Matx_DivOp()); |
joeverbout | 0:ea44dc9ed014 | 821 | } |
joeverbout | 0:ea44dc9ed014 | 822 | |
joeverbout | 0:ea44dc9ed014 | 823 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 824 | Matx<_Tp, n, m> Matx<_Tp, m, n>::t() const |
joeverbout | 0:ea44dc9ed014 | 825 | { |
joeverbout | 0:ea44dc9ed014 | 826 | return Matx<_Tp, n, m>(*this, Matx_TOp()); |
joeverbout | 0:ea44dc9ed014 | 827 | } |
joeverbout | 0:ea44dc9ed014 | 828 | |
joeverbout | 0:ea44dc9ed014 | 829 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 830 | Vec<_Tp, n> Matx<_Tp, m, n>::solve(const Vec<_Tp, m>& rhs, int method) const |
joeverbout | 0:ea44dc9ed014 | 831 | { |
joeverbout | 0:ea44dc9ed014 | 832 | Matx<_Tp, n, 1> x = solve((const Matx<_Tp, m, 1>&)(rhs), method); |
joeverbout | 0:ea44dc9ed014 | 833 | return (Vec<_Tp, n>&)(x); |
joeverbout | 0:ea44dc9ed014 | 834 | } |
joeverbout | 0:ea44dc9ed014 | 835 | |
joeverbout | 0:ea44dc9ed014 | 836 | template<typename _Tp, int m> static inline |
joeverbout | 0:ea44dc9ed014 | 837 | double determinant(const Matx<_Tp, m, m>& a) |
joeverbout | 0:ea44dc9ed014 | 838 | { |
joeverbout | 0:ea44dc9ed014 | 839 | return cv::internal::Matx_DetOp<_Tp, m>()(a); |
joeverbout | 0:ea44dc9ed014 | 840 | } |
joeverbout | 0:ea44dc9ed014 | 841 | |
joeverbout | 0:ea44dc9ed014 | 842 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 843 | double trace(const Matx<_Tp, m, n>& a) |
joeverbout | 0:ea44dc9ed014 | 844 | { |
joeverbout | 0:ea44dc9ed014 | 845 | _Tp s = 0; |
joeverbout | 0:ea44dc9ed014 | 846 | for( int i = 0; i < std::min(m, n); i++ ) |
joeverbout | 0:ea44dc9ed014 | 847 | s += a(i,i); |
joeverbout | 0:ea44dc9ed014 | 848 | return s; |
joeverbout | 0:ea44dc9ed014 | 849 | } |
joeverbout | 0:ea44dc9ed014 | 850 | |
joeverbout | 0:ea44dc9ed014 | 851 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 852 | double norm(const Matx<_Tp, m, n>& M) |
joeverbout | 0:ea44dc9ed014 | 853 | { |
joeverbout | 0:ea44dc9ed014 | 854 | return std::sqrt(normL2Sqr<_Tp, double>(M.val, m*n)); |
joeverbout | 0:ea44dc9ed014 | 855 | } |
joeverbout | 0:ea44dc9ed014 | 856 | |
joeverbout | 0:ea44dc9ed014 | 857 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 858 | double norm(const Matx<_Tp, m, n>& M, int normType) |
joeverbout | 0:ea44dc9ed014 | 859 | { |
joeverbout | 0:ea44dc9ed014 | 860 | switch(normType) { |
joeverbout | 0:ea44dc9ed014 | 861 | case NORM_INF: |
joeverbout | 0:ea44dc9ed014 | 862 | return (double)normInf<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n); |
joeverbout | 0:ea44dc9ed014 | 863 | case NORM_L1: |
joeverbout | 0:ea44dc9ed014 | 864 | return (double)normL1<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n); |
joeverbout | 0:ea44dc9ed014 | 865 | case NORM_L2SQR: |
joeverbout | 0:ea44dc9ed014 | 866 | return (double)normL2Sqr<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n); |
joeverbout | 0:ea44dc9ed014 | 867 | default: |
joeverbout | 0:ea44dc9ed014 | 868 | case NORM_L2: |
joeverbout | 0:ea44dc9ed014 | 869 | return std::sqrt((double)normL2Sqr<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n)); |
joeverbout | 0:ea44dc9ed014 | 870 | } |
joeverbout | 0:ea44dc9ed014 | 871 | } |
joeverbout | 0:ea44dc9ed014 | 872 | |
joeverbout | 0:ea44dc9ed014 | 873 | |
joeverbout | 0:ea44dc9ed014 | 874 | |
joeverbout | 0:ea44dc9ed014 | 875 | //////////////////////////////// matx comma initializer ////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 876 | |
joeverbout | 0:ea44dc9ed014 | 877 | template<typename _Tp, typename _T2, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 878 | MatxCommaInitializer<_Tp, m, n> operator << (const Matx<_Tp, m, n>& mtx, _T2 val) |
joeverbout | 0:ea44dc9ed014 | 879 | { |
joeverbout | 0:ea44dc9ed014 | 880 | MatxCommaInitializer<_Tp, m, n> commaInitializer((Matx<_Tp, m, n>*)&mtx); |
joeverbout | 0:ea44dc9ed014 | 881 | return (commaInitializer, val); |
joeverbout | 0:ea44dc9ed014 | 882 | } |
joeverbout | 0:ea44dc9ed014 | 883 | |
joeverbout | 0:ea44dc9ed014 | 884 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 885 | MatxCommaInitializer<_Tp, m, n>::MatxCommaInitializer(Matx<_Tp, m, n>* _mtx) |
joeverbout | 0:ea44dc9ed014 | 886 | : dst(_mtx), idx(0) |
joeverbout | 0:ea44dc9ed014 | 887 | {} |
joeverbout | 0:ea44dc9ed014 | 888 | |
joeverbout | 0:ea44dc9ed014 | 889 | template<typename _Tp, int m, int n> template<typename _T2> inline |
joeverbout | 0:ea44dc9ed014 | 890 | MatxCommaInitializer<_Tp, m, n>& MatxCommaInitializer<_Tp, m, n>::operator , (_T2 value) |
joeverbout | 0:ea44dc9ed014 | 891 | { |
joeverbout | 0:ea44dc9ed014 | 892 | CV_DbgAssert( idx < m*n ); |
joeverbout | 0:ea44dc9ed014 | 893 | dst->val[idx++] = saturate_cast<_Tp>(value); |
joeverbout | 0:ea44dc9ed014 | 894 | return *this; |
joeverbout | 0:ea44dc9ed014 | 895 | } |
joeverbout | 0:ea44dc9ed014 | 896 | |
joeverbout | 0:ea44dc9ed014 | 897 | template<typename _Tp, int m, int n> inline |
joeverbout | 0:ea44dc9ed014 | 898 | Matx<_Tp, m, n> MatxCommaInitializer<_Tp, m, n>::operator *() const |
joeverbout | 0:ea44dc9ed014 | 899 | { |
joeverbout | 0:ea44dc9ed014 | 900 | CV_DbgAssert( idx == n*m ); |
joeverbout | 0:ea44dc9ed014 | 901 | return *dst; |
joeverbout | 0:ea44dc9ed014 | 902 | } |
joeverbout | 0:ea44dc9ed014 | 903 | |
joeverbout | 0:ea44dc9ed014 | 904 | |
joeverbout | 0:ea44dc9ed014 | 905 | |
joeverbout | 0:ea44dc9ed014 | 906 | /////////////////////////////////// Vec Implementation /////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 907 | |
joeverbout | 0:ea44dc9ed014 | 908 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 909 | Vec<_Tp, cn>::Vec() {} |
joeverbout | 0:ea44dc9ed014 | 910 | |
joeverbout | 0:ea44dc9ed014 | 911 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 912 | Vec<_Tp, cn>::Vec(_Tp v0) |
joeverbout | 0:ea44dc9ed014 | 913 | : Matx<_Tp, cn, 1>(v0) {} |
joeverbout | 0:ea44dc9ed014 | 914 | |
joeverbout | 0:ea44dc9ed014 | 915 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 916 | Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1) |
joeverbout | 0:ea44dc9ed014 | 917 | : Matx<_Tp, cn, 1>(v0, v1) {} |
joeverbout | 0:ea44dc9ed014 | 918 | |
joeverbout | 0:ea44dc9ed014 | 919 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 920 | Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2) |
joeverbout | 0:ea44dc9ed014 | 921 | : Matx<_Tp, cn, 1>(v0, v1, v2) {} |
joeverbout | 0:ea44dc9ed014 | 922 | |
joeverbout | 0:ea44dc9ed014 | 923 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 924 | Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3) |
joeverbout | 0:ea44dc9ed014 | 925 | : Matx<_Tp, cn, 1>(v0, v1, v2, v3) {} |
joeverbout | 0:ea44dc9ed014 | 926 | |
joeverbout | 0:ea44dc9ed014 | 927 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 928 | Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4) |
joeverbout | 0:ea44dc9ed014 | 929 | : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4) {} |
joeverbout | 0:ea44dc9ed014 | 930 | |
joeverbout | 0:ea44dc9ed014 | 931 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 932 | Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5) |
joeverbout | 0:ea44dc9ed014 | 933 | : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5) {} |
joeverbout | 0:ea44dc9ed014 | 934 | |
joeverbout | 0:ea44dc9ed014 | 935 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 936 | Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6) |
joeverbout | 0:ea44dc9ed014 | 937 | : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6) {} |
joeverbout | 0:ea44dc9ed014 | 938 | |
joeverbout | 0:ea44dc9ed014 | 939 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 940 | Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7) |
joeverbout | 0:ea44dc9ed014 | 941 | : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7) {} |
joeverbout | 0:ea44dc9ed014 | 942 | |
joeverbout | 0:ea44dc9ed014 | 943 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 944 | Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8) |
joeverbout | 0:ea44dc9ed014 | 945 | : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8) {} |
joeverbout | 0:ea44dc9ed014 | 946 | |
joeverbout | 0:ea44dc9ed014 | 947 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 948 | Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9) |
joeverbout | 0:ea44dc9ed014 | 949 | : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9) {} |
joeverbout | 0:ea44dc9ed014 | 950 | |
joeverbout | 0:ea44dc9ed014 | 951 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 952 | 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) |
joeverbout | 0:ea44dc9ed014 | 953 | : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) {} |
joeverbout | 0:ea44dc9ed014 | 954 | |
joeverbout | 0:ea44dc9ed014 | 955 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 956 | Vec<_Tp, cn>::Vec(const _Tp* values) |
joeverbout | 0:ea44dc9ed014 | 957 | : Matx<_Tp, cn, 1>(values) {} |
joeverbout | 0:ea44dc9ed014 | 958 | |
joeverbout | 0:ea44dc9ed014 | 959 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 960 | Vec<_Tp, cn>::Vec(const Vec<_Tp, cn>& m) |
joeverbout | 0:ea44dc9ed014 | 961 | : Matx<_Tp, cn, 1>(m.val) {} |
joeverbout | 0:ea44dc9ed014 | 962 | |
joeverbout | 0:ea44dc9ed014 | 963 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 964 | Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp op) |
joeverbout | 0:ea44dc9ed014 | 965 | : Matx<_Tp, cn, 1>(a, b, op) {} |
joeverbout | 0:ea44dc9ed014 | 966 | |
joeverbout | 0:ea44dc9ed014 | 967 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 968 | Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp op) |
joeverbout | 0:ea44dc9ed014 | 969 | : Matx<_Tp, cn, 1>(a, b, op) {} |
joeverbout | 0:ea44dc9ed014 | 970 | |
joeverbout | 0:ea44dc9ed014 | 971 | template<typename _Tp, int cn> template<typename _T2> inline |
joeverbout | 0:ea44dc9ed014 | 972 | Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp op) |
joeverbout | 0:ea44dc9ed014 | 973 | : Matx<_Tp, cn, 1>(a, alpha, op) {} |
joeverbout | 0:ea44dc9ed014 | 974 | |
joeverbout | 0:ea44dc9ed014 | 975 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 976 | Vec<_Tp, cn> Vec<_Tp, cn>::all(_Tp alpha) |
joeverbout | 0:ea44dc9ed014 | 977 | { |
joeverbout | 0:ea44dc9ed014 | 978 | Vec v; |
joeverbout | 0:ea44dc9ed014 | 979 | for( int i = 0; i < cn; i++ ) v.val[i] = alpha; |
joeverbout | 0:ea44dc9ed014 | 980 | return v; |
joeverbout | 0:ea44dc9ed014 | 981 | } |
joeverbout | 0:ea44dc9ed014 | 982 | |
joeverbout | 0:ea44dc9ed014 | 983 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 984 | Vec<_Tp, cn> Vec<_Tp, cn>::mul(const Vec<_Tp, cn>& v) const |
joeverbout | 0:ea44dc9ed014 | 985 | { |
joeverbout | 0:ea44dc9ed014 | 986 | Vec<_Tp, cn> w; |
joeverbout | 0:ea44dc9ed014 | 987 | for( int i = 0; i < cn; i++ ) w.val[i] = saturate_cast<_Tp>(this->val[i]*v.val[i]); |
joeverbout | 0:ea44dc9ed014 | 988 | return w; |
joeverbout | 0:ea44dc9ed014 | 989 | } |
joeverbout | 0:ea44dc9ed014 | 990 | |
joeverbout | 0:ea44dc9ed014 | 991 | template<> inline |
joeverbout | 0:ea44dc9ed014 | 992 | Vec<float, 2> Vec<float, 2>::conj() const |
joeverbout | 0:ea44dc9ed014 | 993 | { |
joeverbout | 0:ea44dc9ed014 | 994 | return cv::internal::conjugate(*this); |
joeverbout | 0:ea44dc9ed014 | 995 | } |
joeverbout | 0:ea44dc9ed014 | 996 | |
joeverbout | 0:ea44dc9ed014 | 997 | template<> inline |
joeverbout | 0:ea44dc9ed014 | 998 | Vec<double, 2> Vec<double, 2>::conj() const |
joeverbout | 0:ea44dc9ed014 | 999 | { |
joeverbout | 0:ea44dc9ed014 | 1000 | return cv::internal::conjugate(*this); |
joeverbout | 0:ea44dc9ed014 | 1001 | } |
joeverbout | 0:ea44dc9ed014 | 1002 | |
joeverbout | 0:ea44dc9ed014 | 1003 | template<> inline |
joeverbout | 0:ea44dc9ed014 | 1004 | Vec<float, 4> Vec<float, 4>::conj() const |
joeverbout | 0:ea44dc9ed014 | 1005 | { |
joeverbout | 0:ea44dc9ed014 | 1006 | return cv::internal::conjugate(*this); |
joeverbout | 0:ea44dc9ed014 | 1007 | } |
joeverbout | 0:ea44dc9ed014 | 1008 | |
joeverbout | 0:ea44dc9ed014 | 1009 | template<> inline |
joeverbout | 0:ea44dc9ed014 | 1010 | Vec<double, 4> Vec<double, 4>::conj() const |
joeverbout | 0:ea44dc9ed014 | 1011 | { |
joeverbout | 0:ea44dc9ed014 | 1012 | return cv::internal::conjugate(*this); |
joeverbout | 0:ea44dc9ed014 | 1013 | } |
joeverbout | 0:ea44dc9ed014 | 1014 | |
joeverbout | 0:ea44dc9ed014 | 1015 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 1016 | Vec<_Tp, cn> Vec<_Tp, cn>::cross(const Vec<_Tp, cn>&) const |
joeverbout | 0:ea44dc9ed014 | 1017 | { |
joeverbout | 0:ea44dc9ed014 | 1018 | CV_StaticAssert(cn == 3, "for arbitrary-size vector there is no cross-product defined"); |
joeverbout | 0:ea44dc9ed014 | 1019 | return Vec<_Tp, cn>(); |
joeverbout | 0:ea44dc9ed014 | 1020 | } |
joeverbout | 0:ea44dc9ed014 | 1021 | |
joeverbout | 0:ea44dc9ed014 | 1022 | template<> inline |
joeverbout | 0:ea44dc9ed014 | 1023 | Vec<float, 3> Vec<float, 3>::cross(const Vec<float, 3>& v) const |
joeverbout | 0:ea44dc9ed014 | 1024 | { |
joeverbout | 0:ea44dc9ed014 | 1025 | return Vec<float,3>(val[1]*v.val[2] - val[2]*v.val[1], |
joeverbout | 0:ea44dc9ed014 | 1026 | val[2]*v.val[0] - val[0]*v.val[2], |
joeverbout | 0:ea44dc9ed014 | 1027 | val[0]*v.val[1] - val[1]*v.val[0]); |
joeverbout | 0:ea44dc9ed014 | 1028 | } |
joeverbout | 0:ea44dc9ed014 | 1029 | |
joeverbout | 0:ea44dc9ed014 | 1030 | template<> inline |
joeverbout | 0:ea44dc9ed014 | 1031 | Vec<double, 3> Vec<double, 3>::cross(const Vec<double, 3>& v) const |
joeverbout | 0:ea44dc9ed014 | 1032 | { |
joeverbout | 0:ea44dc9ed014 | 1033 | return Vec<double,3>(val[1]*v.val[2] - val[2]*v.val[1], |
joeverbout | 0:ea44dc9ed014 | 1034 | val[2]*v.val[0] - val[0]*v.val[2], |
joeverbout | 0:ea44dc9ed014 | 1035 | val[0]*v.val[1] - val[1]*v.val[0]); |
joeverbout | 0:ea44dc9ed014 | 1036 | } |
joeverbout | 0:ea44dc9ed014 | 1037 | |
joeverbout | 0:ea44dc9ed014 | 1038 | template<typename _Tp, int cn> template<typename T2> inline |
joeverbout | 0:ea44dc9ed014 | 1039 | Vec<_Tp, cn>::operator Vec<T2, cn>() const |
joeverbout | 0:ea44dc9ed014 | 1040 | { |
joeverbout | 0:ea44dc9ed014 | 1041 | Vec<T2, cn> v; |
joeverbout | 0:ea44dc9ed014 | 1042 | for( int i = 0; i < cn; i++ ) v.val[i] = saturate_cast<T2>(this->val[i]); |
joeverbout | 0:ea44dc9ed014 | 1043 | return v; |
joeverbout | 0:ea44dc9ed014 | 1044 | } |
joeverbout | 0:ea44dc9ed014 | 1045 | |
joeverbout | 0:ea44dc9ed014 | 1046 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 1047 | const _Tp& Vec<_Tp, cn>::operator [](int i) const |
joeverbout | 0:ea44dc9ed014 | 1048 | { |
joeverbout | 0:ea44dc9ed014 | 1049 | CV_DbgAssert( (unsigned)i < (unsigned)cn ); |
joeverbout | 0:ea44dc9ed014 | 1050 | return this->val[i]; |
joeverbout | 0:ea44dc9ed014 | 1051 | } |
joeverbout | 0:ea44dc9ed014 | 1052 | |
joeverbout | 0:ea44dc9ed014 | 1053 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 1054 | _Tp& Vec<_Tp, cn>::operator [](int i) |
joeverbout | 0:ea44dc9ed014 | 1055 | { |
joeverbout | 0:ea44dc9ed014 | 1056 | CV_DbgAssert( (unsigned)i < (unsigned)cn ); |
joeverbout | 0:ea44dc9ed014 | 1057 | return this->val[i]; |
joeverbout | 0:ea44dc9ed014 | 1058 | } |
joeverbout | 0:ea44dc9ed014 | 1059 | |
joeverbout | 0:ea44dc9ed014 | 1060 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 1061 | const _Tp& Vec<_Tp, cn>::operator ()(int i) const |
joeverbout | 0:ea44dc9ed014 | 1062 | { |
joeverbout | 0:ea44dc9ed014 | 1063 | CV_DbgAssert( (unsigned)i < (unsigned)cn ); |
joeverbout | 0:ea44dc9ed014 | 1064 | return this->val[i]; |
joeverbout | 0:ea44dc9ed014 | 1065 | } |
joeverbout | 0:ea44dc9ed014 | 1066 | |
joeverbout | 0:ea44dc9ed014 | 1067 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 1068 | _Tp& Vec<_Tp, cn>::operator ()(int i) |
joeverbout | 0:ea44dc9ed014 | 1069 | { |
joeverbout | 0:ea44dc9ed014 | 1070 | CV_DbgAssert( (unsigned)i < (unsigned)cn ); |
joeverbout | 0:ea44dc9ed014 | 1071 | return this->val[i]; |
joeverbout | 0:ea44dc9ed014 | 1072 | } |
joeverbout | 0:ea44dc9ed014 | 1073 | |
joeverbout | 0:ea44dc9ed014 | 1074 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 1075 | Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& v) |
joeverbout | 0:ea44dc9ed014 | 1076 | { |
joeverbout | 0:ea44dc9ed014 | 1077 | double nv = norm(v); |
joeverbout | 0:ea44dc9ed014 | 1078 | return v * (nv ? 1./nv : 0.); |
joeverbout | 0:ea44dc9ed014 | 1079 | } |
joeverbout | 0:ea44dc9ed014 | 1080 | |
joeverbout | 0:ea44dc9ed014 | 1081 | |
joeverbout | 0:ea44dc9ed014 | 1082 | |
joeverbout | 0:ea44dc9ed014 | 1083 | //////////////////////////////// matx comma initializer ////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 1084 | |
joeverbout | 0:ea44dc9ed014 | 1085 | |
joeverbout | 0:ea44dc9ed014 | 1086 | template<typename _Tp, typename _T2, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1087 | VecCommaInitializer<_Tp, cn> operator << (const Vec<_Tp, cn>& vec, _T2 val) |
joeverbout | 0:ea44dc9ed014 | 1088 | { |
joeverbout | 0:ea44dc9ed014 | 1089 | VecCommaInitializer<_Tp, cn> commaInitializer((Vec<_Tp, cn>*)&vec); |
joeverbout | 0:ea44dc9ed014 | 1090 | return (commaInitializer, val); |
joeverbout | 0:ea44dc9ed014 | 1091 | } |
joeverbout | 0:ea44dc9ed014 | 1092 | |
joeverbout | 0:ea44dc9ed014 | 1093 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 1094 | VecCommaInitializer<_Tp, cn>::VecCommaInitializer(Vec<_Tp, cn>* _vec) |
joeverbout | 0:ea44dc9ed014 | 1095 | : MatxCommaInitializer<_Tp, cn, 1>(_vec) |
joeverbout | 0:ea44dc9ed014 | 1096 | {} |
joeverbout | 0:ea44dc9ed014 | 1097 | |
joeverbout | 0:ea44dc9ed014 | 1098 | template<typename _Tp, int cn> template<typename _T2> inline |
joeverbout | 0:ea44dc9ed014 | 1099 | VecCommaInitializer<_Tp, cn>& VecCommaInitializer<_Tp, cn>::operator , (_T2 value) |
joeverbout | 0:ea44dc9ed014 | 1100 | { |
joeverbout | 0:ea44dc9ed014 | 1101 | CV_DbgAssert( this->idx < cn ); |
joeverbout | 0:ea44dc9ed014 | 1102 | this->dst->val[this->idx++] = saturate_cast<_Tp>(value); |
joeverbout | 0:ea44dc9ed014 | 1103 | return *this; |
joeverbout | 0:ea44dc9ed014 | 1104 | } |
joeverbout | 0:ea44dc9ed014 | 1105 | |
joeverbout | 0:ea44dc9ed014 | 1106 | template<typename _Tp, int cn> inline |
joeverbout | 0:ea44dc9ed014 | 1107 | Vec<_Tp, cn> VecCommaInitializer<_Tp, cn>::operator *() const |
joeverbout | 0:ea44dc9ed014 | 1108 | { |
joeverbout | 0:ea44dc9ed014 | 1109 | CV_DbgAssert( this->idx == cn ); |
joeverbout | 0:ea44dc9ed014 | 1110 | return *this->dst; |
joeverbout | 0:ea44dc9ed014 | 1111 | } |
joeverbout | 0:ea44dc9ed014 | 1112 | |
joeverbout | 0:ea44dc9ed014 | 1113 | //! @endcond |
joeverbout | 0:ea44dc9ed014 | 1114 | |
joeverbout | 0:ea44dc9ed014 | 1115 | ///////////////////////////// Matx out-of-class operators //////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 1116 | |
joeverbout | 0:ea44dc9ed014 | 1117 | //! @relates cv::Matx |
joeverbout | 0:ea44dc9ed014 | 1118 | //! @{ |
joeverbout | 0:ea44dc9ed014 | 1119 | |
joeverbout | 0:ea44dc9ed014 | 1120 | template<typename _Tp1, typename _Tp2, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1121 | Matx<_Tp1, m, n>& operator += (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b) |
joeverbout | 0:ea44dc9ed014 | 1122 | { |
joeverbout | 0:ea44dc9ed014 | 1123 | for( int i = 0; i < m*n; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1124 | a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]); |
joeverbout | 0:ea44dc9ed014 | 1125 | return a; |
joeverbout | 0:ea44dc9ed014 | 1126 | } |
joeverbout | 0:ea44dc9ed014 | 1127 | |
joeverbout | 0:ea44dc9ed014 | 1128 | template<typename _Tp1, typename _Tp2, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1129 | Matx<_Tp1, m, n>& operator -= (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b) |
joeverbout | 0:ea44dc9ed014 | 1130 | { |
joeverbout | 0:ea44dc9ed014 | 1131 | for( int i = 0; i < m*n; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1132 | a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]); |
joeverbout | 0:ea44dc9ed014 | 1133 | return a; |
joeverbout | 0:ea44dc9ed014 | 1134 | } |
joeverbout | 0:ea44dc9ed014 | 1135 | |
joeverbout | 0:ea44dc9ed014 | 1136 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1137 | Matx<_Tp, m, n> operator + (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) |
joeverbout | 0:ea44dc9ed014 | 1138 | { |
joeverbout | 0:ea44dc9ed014 | 1139 | return Matx<_Tp, m, n>(a, b, Matx_AddOp()); |
joeverbout | 0:ea44dc9ed014 | 1140 | } |
joeverbout | 0:ea44dc9ed014 | 1141 | |
joeverbout | 0:ea44dc9ed014 | 1142 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1143 | Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) |
joeverbout | 0:ea44dc9ed014 | 1144 | { |
joeverbout | 0:ea44dc9ed014 | 1145 | return Matx<_Tp, m, n>(a, b, Matx_SubOp()); |
joeverbout | 0:ea44dc9ed014 | 1146 | } |
joeverbout | 0:ea44dc9ed014 | 1147 | |
joeverbout | 0:ea44dc9ed014 | 1148 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1149 | Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, int alpha) |
joeverbout | 0:ea44dc9ed014 | 1150 | { |
joeverbout | 0:ea44dc9ed014 | 1151 | for( int i = 0; i < m*n; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1152 | a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); |
joeverbout | 0:ea44dc9ed014 | 1153 | return a; |
joeverbout | 0:ea44dc9ed014 | 1154 | } |
joeverbout | 0:ea44dc9ed014 | 1155 | |
joeverbout | 0:ea44dc9ed014 | 1156 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1157 | Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, float alpha) |
joeverbout | 0:ea44dc9ed014 | 1158 | { |
joeverbout | 0:ea44dc9ed014 | 1159 | for( int i = 0; i < m*n; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1160 | a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); |
joeverbout | 0:ea44dc9ed014 | 1161 | return a; |
joeverbout | 0:ea44dc9ed014 | 1162 | } |
joeverbout | 0:ea44dc9ed014 | 1163 | |
joeverbout | 0:ea44dc9ed014 | 1164 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1165 | Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, double alpha) |
joeverbout | 0:ea44dc9ed014 | 1166 | { |
joeverbout | 0:ea44dc9ed014 | 1167 | for( int i = 0; i < m*n; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1168 | a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); |
joeverbout | 0:ea44dc9ed014 | 1169 | return a; |
joeverbout | 0:ea44dc9ed014 | 1170 | } |
joeverbout | 0:ea44dc9ed014 | 1171 | |
joeverbout | 0:ea44dc9ed014 | 1172 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1173 | Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, int alpha) |
joeverbout | 0:ea44dc9ed014 | 1174 | { |
joeverbout | 0:ea44dc9ed014 | 1175 | return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1176 | } |
joeverbout | 0:ea44dc9ed014 | 1177 | |
joeverbout | 0:ea44dc9ed014 | 1178 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1179 | Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, float alpha) |
joeverbout | 0:ea44dc9ed014 | 1180 | { |
joeverbout | 0:ea44dc9ed014 | 1181 | return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1182 | } |
joeverbout | 0:ea44dc9ed014 | 1183 | |
joeverbout | 0:ea44dc9ed014 | 1184 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1185 | Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, double alpha) |
joeverbout | 0:ea44dc9ed014 | 1186 | { |
joeverbout | 0:ea44dc9ed014 | 1187 | return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1188 | } |
joeverbout | 0:ea44dc9ed014 | 1189 | |
joeverbout | 0:ea44dc9ed014 | 1190 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1191 | Matx<_Tp, m, n> operator * (int alpha, const Matx<_Tp, m, n>& a) |
joeverbout | 0:ea44dc9ed014 | 1192 | { |
joeverbout | 0:ea44dc9ed014 | 1193 | return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1194 | } |
joeverbout | 0:ea44dc9ed014 | 1195 | |
joeverbout | 0:ea44dc9ed014 | 1196 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1197 | Matx<_Tp, m, n> operator * (float alpha, const Matx<_Tp, m, n>& a) |
joeverbout | 0:ea44dc9ed014 | 1198 | { |
joeverbout | 0:ea44dc9ed014 | 1199 | return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1200 | } |
joeverbout | 0:ea44dc9ed014 | 1201 | |
joeverbout | 0:ea44dc9ed014 | 1202 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1203 | Matx<_Tp, m, n> operator * (double alpha, const Matx<_Tp, m, n>& a) |
joeverbout | 0:ea44dc9ed014 | 1204 | { |
joeverbout | 0:ea44dc9ed014 | 1205 | return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1206 | } |
joeverbout | 0:ea44dc9ed014 | 1207 | |
joeverbout | 0:ea44dc9ed014 | 1208 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1209 | Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a) |
joeverbout | 0:ea44dc9ed014 | 1210 | { |
joeverbout | 0:ea44dc9ed014 | 1211 | return Matx<_Tp, m, n>(a, -1, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1212 | } |
joeverbout | 0:ea44dc9ed014 | 1213 | |
joeverbout | 0:ea44dc9ed014 | 1214 | template<typename _Tp, int m, int n, int l> static inline |
joeverbout | 0:ea44dc9ed014 | 1215 | Matx<_Tp, m, n> operator * (const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b) |
joeverbout | 0:ea44dc9ed014 | 1216 | { |
joeverbout | 0:ea44dc9ed014 | 1217 | return Matx<_Tp, m, n>(a, b, Matx_MatMulOp()); |
joeverbout | 0:ea44dc9ed014 | 1218 | } |
joeverbout | 0:ea44dc9ed014 | 1219 | |
joeverbout | 0:ea44dc9ed014 | 1220 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1221 | Vec<_Tp, m> operator * (const Matx<_Tp, m, n>& a, const Vec<_Tp, n>& b) |
joeverbout | 0:ea44dc9ed014 | 1222 | { |
joeverbout | 0:ea44dc9ed014 | 1223 | Matx<_Tp, m, 1> c(a, b, Matx_MatMulOp()); |
joeverbout | 0:ea44dc9ed014 | 1224 | return (const Vec<_Tp, m>&)(c); |
joeverbout | 0:ea44dc9ed014 | 1225 | } |
joeverbout | 0:ea44dc9ed014 | 1226 | |
joeverbout | 0:ea44dc9ed014 | 1227 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1228 | bool operator == (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) |
joeverbout | 0:ea44dc9ed014 | 1229 | { |
joeverbout | 0:ea44dc9ed014 | 1230 | for( int i = 0; i < m*n; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1231 | if( a.val[i] != b.val[i] ) return false; |
joeverbout | 0:ea44dc9ed014 | 1232 | return true; |
joeverbout | 0:ea44dc9ed014 | 1233 | } |
joeverbout | 0:ea44dc9ed014 | 1234 | |
joeverbout | 0:ea44dc9ed014 | 1235 | template<typename _Tp, int m, int n> static inline |
joeverbout | 0:ea44dc9ed014 | 1236 | bool operator != (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) |
joeverbout | 0:ea44dc9ed014 | 1237 | { |
joeverbout | 0:ea44dc9ed014 | 1238 | return !(a == b); |
joeverbout | 0:ea44dc9ed014 | 1239 | } |
joeverbout | 0:ea44dc9ed014 | 1240 | |
joeverbout | 0:ea44dc9ed014 | 1241 | //! @} |
joeverbout | 0:ea44dc9ed014 | 1242 | |
joeverbout | 0:ea44dc9ed014 | 1243 | ////////////////////////////// Vec out-of-class operators //////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 1244 | |
joeverbout | 0:ea44dc9ed014 | 1245 | //! @relates cv::Vec |
joeverbout | 0:ea44dc9ed014 | 1246 | //! @{ |
joeverbout | 0:ea44dc9ed014 | 1247 | |
joeverbout | 0:ea44dc9ed014 | 1248 | template<typename _Tp1, typename _Tp2, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1249 | Vec<_Tp1, cn>& operator += (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b) |
joeverbout | 0:ea44dc9ed014 | 1250 | { |
joeverbout | 0:ea44dc9ed014 | 1251 | for( int i = 0; i < cn; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1252 | a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]); |
joeverbout | 0:ea44dc9ed014 | 1253 | return a; |
joeverbout | 0:ea44dc9ed014 | 1254 | } |
joeverbout | 0:ea44dc9ed014 | 1255 | |
joeverbout | 0:ea44dc9ed014 | 1256 | template<typename _Tp1, typename _Tp2, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1257 | Vec<_Tp1, cn>& operator -= (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b) |
joeverbout | 0:ea44dc9ed014 | 1258 | { |
joeverbout | 0:ea44dc9ed014 | 1259 | for( int i = 0; i < cn; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1260 | a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]); |
joeverbout | 0:ea44dc9ed014 | 1261 | return a; |
joeverbout | 0:ea44dc9ed014 | 1262 | } |
joeverbout | 0:ea44dc9ed014 | 1263 | |
joeverbout | 0:ea44dc9ed014 | 1264 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1265 | Vec<_Tp, cn> operator + (const Vec<_Tp, cn>& a, const Vec<_Tp, cn>& b) |
joeverbout | 0:ea44dc9ed014 | 1266 | { |
joeverbout | 0:ea44dc9ed014 | 1267 | return Vec<_Tp, cn>(a, b, Matx_AddOp()); |
joeverbout | 0:ea44dc9ed014 | 1268 | } |
joeverbout | 0:ea44dc9ed014 | 1269 | |
joeverbout | 0:ea44dc9ed014 | 1270 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1271 | Vec<_Tp, cn> operator - (const Vec<_Tp, cn>& a, const Vec<_Tp, cn>& b) |
joeverbout | 0:ea44dc9ed014 | 1272 | { |
joeverbout | 0:ea44dc9ed014 | 1273 | return Vec<_Tp, cn>(a, b, Matx_SubOp()); |
joeverbout | 0:ea44dc9ed014 | 1274 | } |
joeverbout | 0:ea44dc9ed014 | 1275 | |
joeverbout | 0:ea44dc9ed014 | 1276 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1277 | Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, int alpha) |
joeverbout | 0:ea44dc9ed014 | 1278 | { |
joeverbout | 0:ea44dc9ed014 | 1279 | for( int i = 0; i < cn; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1280 | a[i] = saturate_cast<_Tp>(a[i]*alpha); |
joeverbout | 0:ea44dc9ed014 | 1281 | return a; |
joeverbout | 0:ea44dc9ed014 | 1282 | } |
joeverbout | 0:ea44dc9ed014 | 1283 | |
joeverbout | 0:ea44dc9ed014 | 1284 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1285 | Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, float alpha) |
joeverbout | 0:ea44dc9ed014 | 1286 | { |
joeverbout | 0:ea44dc9ed014 | 1287 | for( int i = 0; i < cn; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1288 | a[i] = saturate_cast<_Tp>(a[i]*alpha); |
joeverbout | 0:ea44dc9ed014 | 1289 | return a; |
joeverbout | 0:ea44dc9ed014 | 1290 | } |
joeverbout | 0:ea44dc9ed014 | 1291 | |
joeverbout | 0:ea44dc9ed014 | 1292 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1293 | Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, double alpha) |
joeverbout | 0:ea44dc9ed014 | 1294 | { |
joeverbout | 0:ea44dc9ed014 | 1295 | for( int i = 0; i < cn; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1296 | a[i] = saturate_cast<_Tp>(a[i]*alpha); |
joeverbout | 0:ea44dc9ed014 | 1297 | return a; |
joeverbout | 0:ea44dc9ed014 | 1298 | } |
joeverbout | 0:ea44dc9ed014 | 1299 | |
joeverbout | 0:ea44dc9ed014 | 1300 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1301 | Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, int alpha) |
joeverbout | 0:ea44dc9ed014 | 1302 | { |
joeverbout | 0:ea44dc9ed014 | 1303 | double ialpha = 1./alpha; |
joeverbout | 0:ea44dc9ed014 | 1304 | for( int i = 0; i < cn; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1305 | a[i] = saturate_cast<_Tp>(a[i]*ialpha); |
joeverbout | 0:ea44dc9ed014 | 1306 | return a; |
joeverbout | 0:ea44dc9ed014 | 1307 | } |
joeverbout | 0:ea44dc9ed014 | 1308 | |
joeverbout | 0:ea44dc9ed014 | 1309 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1310 | Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, float alpha) |
joeverbout | 0:ea44dc9ed014 | 1311 | { |
joeverbout | 0:ea44dc9ed014 | 1312 | float ialpha = 1.f/alpha; |
joeverbout | 0:ea44dc9ed014 | 1313 | for( int i = 0; i < cn; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1314 | a[i] = saturate_cast<_Tp>(a[i]*ialpha); |
joeverbout | 0:ea44dc9ed014 | 1315 | return a; |
joeverbout | 0:ea44dc9ed014 | 1316 | } |
joeverbout | 0:ea44dc9ed014 | 1317 | |
joeverbout | 0:ea44dc9ed014 | 1318 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1319 | Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, double alpha) |
joeverbout | 0:ea44dc9ed014 | 1320 | { |
joeverbout | 0:ea44dc9ed014 | 1321 | double ialpha = 1./alpha; |
joeverbout | 0:ea44dc9ed014 | 1322 | for( int i = 0; i < cn; i++ ) |
joeverbout | 0:ea44dc9ed014 | 1323 | a[i] = saturate_cast<_Tp>(a[i]*ialpha); |
joeverbout | 0:ea44dc9ed014 | 1324 | return a; |
joeverbout | 0:ea44dc9ed014 | 1325 | } |
joeverbout | 0:ea44dc9ed014 | 1326 | |
joeverbout | 0:ea44dc9ed014 | 1327 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1328 | Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, int alpha) |
joeverbout | 0:ea44dc9ed014 | 1329 | { |
joeverbout | 0:ea44dc9ed014 | 1330 | return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1331 | } |
joeverbout | 0:ea44dc9ed014 | 1332 | |
joeverbout | 0:ea44dc9ed014 | 1333 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1334 | Vec<_Tp, cn> operator * (int alpha, const Vec<_Tp, cn>& a) |
joeverbout | 0:ea44dc9ed014 | 1335 | { |
joeverbout | 0:ea44dc9ed014 | 1336 | return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1337 | } |
joeverbout | 0:ea44dc9ed014 | 1338 | |
joeverbout | 0:ea44dc9ed014 | 1339 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1340 | Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, float alpha) |
joeverbout | 0:ea44dc9ed014 | 1341 | { |
joeverbout | 0:ea44dc9ed014 | 1342 | return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1343 | } |
joeverbout | 0:ea44dc9ed014 | 1344 | |
joeverbout | 0:ea44dc9ed014 | 1345 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1346 | Vec<_Tp, cn> operator * (float alpha, const Vec<_Tp, cn>& a) |
joeverbout | 0:ea44dc9ed014 | 1347 | { |
joeverbout | 0:ea44dc9ed014 | 1348 | return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1349 | } |
joeverbout | 0:ea44dc9ed014 | 1350 | |
joeverbout | 0:ea44dc9ed014 | 1351 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1352 | Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, double alpha) |
joeverbout | 0:ea44dc9ed014 | 1353 | { |
joeverbout | 0:ea44dc9ed014 | 1354 | return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1355 | } |
joeverbout | 0:ea44dc9ed014 | 1356 | |
joeverbout | 0:ea44dc9ed014 | 1357 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1358 | Vec<_Tp, cn> operator * (double alpha, const Vec<_Tp, cn>& a) |
joeverbout | 0:ea44dc9ed014 | 1359 | { |
joeverbout | 0:ea44dc9ed014 | 1360 | return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1361 | } |
joeverbout | 0:ea44dc9ed014 | 1362 | |
joeverbout | 0:ea44dc9ed014 | 1363 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1364 | Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, int alpha) |
joeverbout | 0:ea44dc9ed014 | 1365 | { |
joeverbout | 0:ea44dc9ed014 | 1366 | return Vec<_Tp, cn>(a, 1./alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1367 | } |
joeverbout | 0:ea44dc9ed014 | 1368 | |
joeverbout | 0:ea44dc9ed014 | 1369 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1370 | Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, float alpha) |
joeverbout | 0:ea44dc9ed014 | 1371 | { |
joeverbout | 0:ea44dc9ed014 | 1372 | return Vec<_Tp, cn>(a, 1.f/alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1373 | } |
joeverbout | 0:ea44dc9ed014 | 1374 | |
joeverbout | 0:ea44dc9ed014 | 1375 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1376 | Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, double alpha) |
joeverbout | 0:ea44dc9ed014 | 1377 | { |
joeverbout | 0:ea44dc9ed014 | 1378 | return Vec<_Tp, cn>(a, 1./alpha, Matx_ScaleOp()); |
joeverbout | 0:ea44dc9ed014 | 1379 | } |
joeverbout | 0:ea44dc9ed014 | 1380 | |
joeverbout | 0:ea44dc9ed014 | 1381 | template<typename _Tp, int cn> static inline |
joeverbout | 0:ea44dc9ed014 | 1382 | Vec<_Tp, cn> operator - (const Vec<_Tp, cn>& a) |
joeverbout | 0:ea44dc9ed014 | 1383 | { |
joeverbout | 0:ea44dc9ed014 | 1384 | Vec<_Tp,cn> t; |
joeverbout | 0:ea44dc9ed014 | 1385 | for( int i = 0; i < cn; i++ ) t.val[i] = saturate_cast<_Tp>(-a.val[i]); |
joeverbout | 0:ea44dc9ed014 | 1386 | return t; |
joeverbout | 0:ea44dc9ed014 | 1387 | } |
joeverbout | 0:ea44dc9ed014 | 1388 | |
joeverbout | 0:ea44dc9ed014 | 1389 | template<typename _Tp> inline Vec<_Tp, 4> operator * (const Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2) |
joeverbout | 0:ea44dc9ed014 | 1390 | { |
joeverbout | 0:ea44dc9ed014 | 1391 | return Vec<_Tp, 4>(saturate_cast<_Tp>(v1[0]*v2[0] - v1[1]*v2[1] - v1[2]*v2[2] - v1[3]*v2[3]), |
joeverbout | 0:ea44dc9ed014 | 1392 | saturate_cast<_Tp>(v1[0]*v2[1] + v1[1]*v2[0] + v1[2]*v2[3] - v1[3]*v2[2]), |
joeverbout | 0:ea44dc9ed014 | 1393 | saturate_cast<_Tp>(v1[0]*v2[2] - v1[1]*v2[3] + v1[2]*v2[0] + v1[3]*v2[1]), |
joeverbout | 0:ea44dc9ed014 | 1394 | saturate_cast<_Tp>(v1[0]*v2[3] + v1[1]*v2[2] - v1[2]*v2[1] + v1[3]*v2[0])); |
joeverbout | 0:ea44dc9ed014 | 1395 | } |
joeverbout | 0:ea44dc9ed014 | 1396 | |
joeverbout | 0:ea44dc9ed014 | 1397 | template<typename _Tp> inline Vec<_Tp, 4>& operator *= (Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2) |
joeverbout | 0:ea44dc9ed014 | 1398 | { |
joeverbout | 0:ea44dc9ed014 | 1399 | v1 = v1 * v2; |
joeverbout | 0:ea44dc9ed014 | 1400 | return v1; |
joeverbout | 0:ea44dc9ed014 | 1401 | } |
joeverbout | 0:ea44dc9ed014 | 1402 | |
joeverbout | 0:ea44dc9ed014 | 1403 | //! @} |
joeverbout | 0:ea44dc9ed014 | 1404 | |
joeverbout | 0:ea44dc9ed014 | 1405 | } // cv |
joeverbout | 0:ea44dc9ed014 | 1406 | |
joeverbout | 0:ea44dc9ed014 | 1407 | #endif // __OPENCV_CORE_MATX_HPP__ |
joeverbout | 0:ea44dc9ed014 | 1408 |