openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

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