| 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
| 4 | // |
| 5 | // By downloading, copying, installing or using the software you agree to this license. |
| 6 | // If you do not agree to this license, do not download, install, |
| 7 | // copy or use the software. |
| 8 | // |
| 9 | // |
| 10 | // License Agreement |
| 11 | // For Open Source Computer Vision Library |
| 12 | // |
| 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
| 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
| 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
| 16 | // Third party copyrights are property of their respective owners. |
| 17 | // |
| 18 | // Redistribution and use in source and binary forms, with or without modification, |
| 19 | // are permitted provided that the following conditions are met: |
| 20 | // |
| 21 | // * Redistribution's of source code must retain the above copyright notice, |
| 22 | // this list of conditions and the following disclaimer. |
| 23 | // |
| 24 | // * Redistribution's in binary form must reproduce the above copyright notice, |
| 25 | // this list of conditions and the following disclaimer in the documentation |
| 26 | // and/or other materials provided with the distribution. |
| 27 | // |
| 28 | // * The name of the copyright holders may not be used to endorse or promote products |
| 29 | // derived from this software without specific prior written permission. |
| 30 | // |
| 31 | // This software is provided by the copyright holders and contributors "as is" and |
| 32 | // any express or implied warranties, including, but not limited to, the implied |
| 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
| 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
| 35 | // indirect, incidental, special, exemplary, or consequential damages |
| 36 | // (including, but not limited to, procurement of substitute goods or services; |
| 37 | // loss of use, data, or profits; or business interruption) however caused |
| 38 | // and on any theory of liability, whether in contract, strict liability, |
| 39 | // or tort (including negligence or otherwise) arising in any way out of |
| 40 | // the use of this software, even if advised of the possibility of such damage. |
| 41 | // |
| 42 | //M*/ |
| 43 | |
| 44 | #ifndef OPENCV_CORE_MATX_HPP |
| 45 | #define OPENCV_CORE_MATX_HPP |
| 46 | |
| 47 | #ifndef __cplusplus |
| 48 | # error matx.hpp header must be compiled as C++ |
| 49 | #endif |
| 50 | |
| 51 | #include "opencv2/core/cvdef.h" |
| 52 | #include "opencv2/core/base.hpp" |
| 53 | #include "opencv2/core/traits.hpp" |
| 54 | #include "opencv2/core/saturate.hpp" |
| 55 | |
| 56 | #include <initializer_list> |
| 57 | |
| 58 | namespace cv |
| 59 | { |
| 60 | |
| 61 | //! @addtogroup core_basic |
| 62 | //! @{ |
| 63 | |
| 64 | //! @cond IGNORED |
| 65 | // FIXIT Remove this (especially CV_EXPORTS modifier) |
| 66 | struct CV_EXPORTS Matx_AddOp { Matx_AddOp() {} Matx_AddOp(const Matx_AddOp&) {} }; |
| 67 | struct CV_EXPORTS Matx_SubOp { Matx_SubOp() {} Matx_SubOp(const Matx_SubOp&) {} }; |
| 68 | struct CV_EXPORTS Matx_ScaleOp { Matx_ScaleOp() {} Matx_ScaleOp(const Matx_ScaleOp&) {} }; |
| 69 | struct CV_EXPORTS Matx_MulOp { Matx_MulOp() {} Matx_MulOp(const Matx_MulOp&) {} }; |
| 70 | struct CV_EXPORTS Matx_DivOp { Matx_DivOp() {} Matx_DivOp(const Matx_DivOp&) {} }; |
| 71 | struct CV_EXPORTS Matx_MatMulOp { Matx_MatMulOp() {} Matx_MatMulOp(const Matx_MatMulOp&) {} }; |
| 72 | struct CV_EXPORTS Matx_TOp { Matx_TOp() {} Matx_TOp(const Matx_TOp&) {} }; |
| 73 | //! @endcond |
| 74 | |
| 75 | ////////////////////////////// Small Matrix /////////////////////////// |
| 76 | |
| 77 | /** @brief Template class for small matrices whose type and size are known at compilation time |
| 78 | |
| 79 | If you need a more flexible type, use Mat . The elements of the matrix M are accessible using the |
| 80 | M(i,j) notation. Most of the common matrix operations (see also @ref MatrixExpressions ) are |
| 81 | available. To do an operation on Matx that is not implemented, you can easily convert the matrix to |
| 82 | Mat and backwards: |
| 83 | @code{.cpp} |
| 84 | Matx33f m(1, 2, 3, |
| 85 | 4, 5, 6, |
| 86 | 7, 8, 9); |
| 87 | cout << sum(Mat(m*m.t())) << endl; |
| 88 | @endcode |
| 89 | Except of the plain constructor which takes a list of elements, Matx can be initialized from a C-array: |
| 90 | @code{.cpp} |
| 91 | float values[] = { 1, 2, 3}; |
| 92 | Matx31f m(values); |
| 93 | @endcode |
| 94 | In case if C++11 features are available, std::initializer_list can be also used to initialize Matx: |
| 95 | @code{.cpp} |
| 96 | Matx31f m = { 1, 2, 3}; |
| 97 | @endcode |
| 98 | */ |
| 99 | template<typename _Tp, int m, int n> class Matx |
| 100 | { |
| 101 | public: |
| 102 | enum { |
| 103 | rows = m, |
| 104 | cols = n, |
| 105 | channels = rows*cols, |
| 106 | #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED |
| 107 | depth = traits::Type<_Tp>::value, |
| 108 | type = CV_MAKETYPE(depth, channels), |
| 109 | #endif |
| 110 | shortdim = (m < n ? m : n) |
| 111 | }; |
| 112 | |
| 113 | typedef _Tp value_type; |
| 114 | typedef Matx<_Tp, m, n> mat_type; |
| 115 | typedef Matx<_Tp, shortdim, 1> diag_type; |
| 116 | |
| 117 | //! default constructor |
| 118 | Matx(); |
| 119 | |
| 120 | explicit Matx(_Tp v0); //!< 1x1 matrix |
| 121 | Matx(_Tp v0, _Tp v1); //!< 1x2 or 2x1 matrix |
| 122 | Matx(_Tp v0, _Tp v1, _Tp v2); //!< 1x3 or 3x1 matrix |
| 123 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 1x4, 2x2 or 4x1 matrix |
| 124 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 1x5 or 5x1 matrix |
| 125 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 1x6, 2x3, 3x2 or 6x1 matrix |
| 126 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 1x7 or 7x1 matrix |
| 127 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 1x8, 2x4, 4x2 or 8x1 matrix |
| 128 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 1x9, 3x3 or 9x1 matrix |
| 129 | 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 |
| 130 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, |
| 131 | _Tp v4, _Tp v5, _Tp v6, _Tp v7, |
| 132 | _Tp v8, _Tp v9, _Tp v10, _Tp v11); //!< 1x12, 2x6, 3x4, 4x3, 6x2 or 12x1 matrix |
| 133 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, |
| 134 | _Tp v4, _Tp v5, _Tp v6, _Tp v7, |
| 135 | _Tp v8, _Tp v9, _Tp v10, _Tp v11, |
| 136 | _Tp v12, _Tp v13); //!< 1x14, 2x7, 7x2 or 14x1 matrix |
| 137 | Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, |
| 138 | _Tp v4, _Tp v5, _Tp v6, _Tp v7, |
| 139 | _Tp v8, _Tp v9, _Tp v10, _Tp v11, |
| 140 | _Tp v12, _Tp v13, _Tp v14, _Tp v15); //!< 1x16, 4x4 or 16x1 matrix |
| 141 | explicit Matx(const _Tp* vals); //!< initialize from a plain array |
| 142 | |
| 143 | Matx(std::initializer_list<_Tp>); //!< initialize from an initializer list |
| 144 | |
| 145 | CV_NODISCARD_STD static Matx all(_Tp alpha); |
| 146 | CV_NODISCARD_STD static Matx zeros(); |
| 147 | CV_NODISCARD_STD static Matx ones(); |
| 148 | CV_NODISCARD_STD static Matx eye(); |
| 149 | CV_NODISCARD_STD static Matx diag(const diag_type& d); |
| 150 | /** @brief Generates uniformly distributed random numbers |
| 151 | @param a Range boundary. |
| 152 | @param b The other range boundary (boundaries don't have to be ordered, the lower boundary is inclusive, |
| 153 | the upper one is exclusive). |
| 154 | */ |
| 155 | CV_NODISCARD_STD static Matx randu(_Tp a, _Tp b); |
| 156 | /** @brief Generates normally distributed random numbers |
| 157 | @param a Mean value. |
| 158 | @param b Standard deviation. |
| 159 | */ |
| 160 | CV_NODISCARD_STD static Matx randn(_Tp a, _Tp b); |
| 161 | |
| 162 | //! dot product computed with the default precision |
| 163 | _Tp dot(const Matx<_Tp, m, n>& v) const; |
| 164 | |
| 165 | //! dot product computed in double-precision arithmetics |
| 166 | double ddot(const Matx<_Tp, m, n>& v) const; |
| 167 | |
| 168 | //! conversion to another data type |
| 169 | template<typename T2> operator Matx<T2, m, n>() const; |
| 170 | |
| 171 | //! change the matrix shape |
| 172 | template<int m1, int n1> Matx<_Tp, m1, n1> reshape() const; |
| 173 | |
| 174 | //! extract part of the matrix |
| 175 | template<int m1, int n1> Matx<_Tp, m1, n1> get_minor(int base_row, int base_col) const; |
| 176 | |
| 177 | //! extract the matrix row |
| 178 | Matx<_Tp, 1, n> row(int i) const; |
| 179 | |
| 180 | //! extract the matrix column |
| 181 | Matx<_Tp, m, 1> col(int i) const; |
| 182 | |
| 183 | //! extract the matrix diagonal |
| 184 | diag_type diag() const; |
| 185 | |
| 186 | //! transpose the matrix |
| 187 | Matx<_Tp, n, m> t() const; |
| 188 | |
| 189 | //! invert the matrix |
| 190 | Matx<_Tp, n, m> inv(int method=DECOMP_LU, bool *p_is_ok = NULL) const; |
| 191 | |
| 192 | //! solve linear system |
| 193 | template<int l> Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const; |
| 194 | Vec<_Tp, n> solve(const Vec<_Tp, m>& rhs, int method) const; |
| 195 | |
| 196 | //! multiply two matrices element-wise |
| 197 | Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const; |
| 198 | |
| 199 | //! divide two matrices element-wise |
| 200 | Matx<_Tp, m, n> div(const Matx<_Tp, m, n>& a) const; |
| 201 | |
| 202 | //! element access |
| 203 | const _Tp& operator ()(int row, int col) const; |
| 204 | _Tp& operator ()(int row, int col); |
| 205 | |
| 206 | //! 1D element access |
| 207 | const _Tp& operator ()(int i) const; |
| 208 | _Tp& operator ()(int i); |
| 209 | |
| 210 | Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp); |
| 211 | Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp); |
| 212 | template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp); |
| 213 | Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp); |
| 214 | Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp); |
| 215 | template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp); |
| 216 | Matx(const Matx<_Tp, n, m>& a, Matx_TOp); |
| 217 | |
| 218 | _Tp val[m*n]; ///< matrix elements |
| 219 | }; |
| 220 | |
| 221 | typedef Matx<float, 1, 2> Matx12f; |
| 222 | typedef Matx<double, 1, 2> Matx12d; |
| 223 | typedef Matx<float, 1, 3> Matx13f; |
| 224 | typedef Matx<double, 1, 3> Matx13d; |
| 225 | typedef Matx<float, 1, 4> Matx14f; |
| 226 | typedef Matx<double, 1, 4> Matx14d; |
| 227 | typedef Matx<float, 1, 6> Matx16f; |
| 228 | typedef Matx<double, 1, 6> Matx16d; |
| 229 | |
| 230 | typedef Matx<float, 2, 1> Matx21f; |
| 231 | typedef Matx<double, 2, 1> Matx21d; |
| 232 | typedef Matx<float, 3, 1> Matx31f; |
| 233 | typedef Matx<double, 3, 1> Matx31d; |
| 234 | typedef Matx<float, 4, 1> Matx41f; |
| 235 | typedef Matx<double, 4, 1> Matx41d; |
| 236 | typedef Matx<float, 6, 1> Matx61f; |
| 237 | typedef Matx<double, 6, 1> Matx61d; |
| 238 | |
| 239 | typedef Matx<float, 2, 2> Matx22f; |
| 240 | typedef Matx<double, 2, 2> Matx22d; |
| 241 | typedef Matx<float, 2, 3> Matx23f; |
| 242 | typedef Matx<double, 2, 3> Matx23d; |
| 243 | typedef Matx<float, 3, 2> Matx32f; |
| 244 | typedef Matx<double, 3, 2> Matx32d; |
| 245 | |
| 246 | typedef Matx<float, 3, 3> Matx33f; |
| 247 | typedef Matx<double, 3, 3> Matx33d; |
| 248 | |
| 249 | typedef Matx<float, 3, 4> Matx34f; |
| 250 | typedef Matx<double, 3, 4> Matx34d; |
| 251 | typedef Matx<float, 4, 3> Matx43f; |
| 252 | typedef Matx<double, 4, 3> Matx43d; |
| 253 | |
| 254 | typedef Matx<float, 4, 4> Matx44f; |
| 255 | typedef Matx<double, 4, 4> Matx44d; |
| 256 | typedef Matx<float, 6, 6> Matx66f; |
| 257 | typedef Matx<double, 6, 6> Matx66d; |
| 258 | |
| 259 | template<typename _Tp, int m> static inline |
| 260 | double determinant(const Matx<_Tp, m, m>& a); |
| 261 | |
| 262 | template<typename _Tp, int m, int n> static inline |
| 263 | double trace(const Matx<_Tp, m, n>& a); |
| 264 | |
| 265 | template<typename _Tp, int m, int n> static inline |
| 266 | double norm(const Matx<_Tp, m, n>& M); |
| 267 | |
| 268 | template<typename _Tp, int m, int n> static inline |
| 269 | double norm(const Matx<_Tp, m, n>& M, int normType); |
| 270 | |
| 271 | template<typename _Tp1, typename _Tp2, int m, int n> static inline |
| 272 | Matx<_Tp1, m, n>& operator += (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b); |
| 273 | |
| 274 | template<typename _Tp1, typename _Tp2, int m, int n> static inline |
| 275 | Matx<_Tp1, m, n>& operator -= (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b); |
| 276 | |
| 277 | template<typename _Tp, int m, int n> static inline |
| 278 | Matx<_Tp, m, n> operator + (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b); |
| 279 | |
| 280 | template<typename _Tp, int m, int n> static inline |
| 281 | Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b); |
| 282 | |
| 283 | template<typename _Tp, int m, int n> static inline |
| 284 | Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, int alpha); |
| 285 | |
| 286 | template<typename _Tp, int m, int n> static inline |
| 287 | Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, float alpha); |
| 288 | |
| 289 | template<typename _Tp, int m, int n> static inline |
| 290 | Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, double alpha); |
| 291 | |
| 292 | template<typename _Tp, int m, int n> static inline |
| 293 | Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, int alpha); |
| 294 | |
| 295 | template<typename _Tp, int m, int n> static inline |
| 296 | Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, float alpha); |
| 297 | |
| 298 | template<typename _Tp, int m, int n> static inline |
| 299 | Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, double alpha); |
| 300 | |
| 301 | template<typename _Tp, int m, int n> static inline |
| 302 | Matx<_Tp, m, n> operator * (int alpha, const Matx<_Tp, m, n>& a); |
| 303 | |
| 304 | template<typename _Tp, int m, int n> static inline |
| 305 | Matx<_Tp, m, n> operator * (float alpha, const Matx<_Tp, m, n>& a); |
| 306 | |
| 307 | template<typename _Tp, int m, int n> static inline |
| 308 | Matx<_Tp, m, n> operator * (double alpha, const Matx<_Tp, m, n>& a); |
| 309 | |
| 310 | template<typename _Tp, int m, int n> static inline |
| 311 | Matx<_Tp, m, n>& operator /= (Matx<_Tp, m, n>& a, float alpha); |
| 312 | |
| 313 | template<typename _Tp, int m, int n> static inline |
| 314 | Matx<_Tp, m, n>& operator /= (Matx<_Tp, m, n>& a, double alpha); |
| 315 | |
| 316 | template<typename _Tp, int m, int n> static inline |
| 317 | Matx<_Tp, m, n> operator / (const Matx<_Tp, m, n>& a, float alpha); |
| 318 | |
| 319 | template<typename _Tp, int m, int n> static inline |
| 320 | Matx<_Tp, m, n> operator / (const Matx<_Tp, m, n>& a, double alpha); |
| 321 | |
| 322 | template<typename _Tp, int m, int n> static inline |
| 323 | Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a); |
| 324 | |
| 325 | template<typename _Tp, int m, int n, int l> static inline |
| 326 | Matx<_Tp, m, n> operator * (const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b); |
| 327 | |
| 328 | template<typename _Tp, int m, int n> static inline |
| 329 | Vec<_Tp, m> operator * (const Matx<_Tp, m, n>& a, const Vec<_Tp, n>& b); |
| 330 | |
| 331 | template<typename _Tp, int m, int n> static inline |
| 332 | bool operator == (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b); |
| 333 | |
| 334 | template<typename _Tp, int m, int n> static inline |
| 335 | bool operator != (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b); |
| 336 | |
| 337 | |
| 338 | /////////////////////// Vec (used as element of multi-channel images ///////////////////// |
| 339 | |
| 340 | /** @brief Template class for short numerical vectors, a partial case of Matx |
| 341 | |
| 342 | This template class represents short numerical vectors (of 1, 2, 3, 4 ... elements) on which you |
| 343 | can perform basic arithmetical operations, access individual elements using [] operator etc. The |
| 344 | vectors are allocated on stack, as opposite to std::valarray, std::vector, cv::Mat etc., which |
| 345 | elements are dynamically allocated in the heap. |
| 346 | |
| 347 | The template takes 2 parameters: |
| 348 | @tparam _Tp element type |
| 349 | @tparam cn the number of elements |
| 350 | |
| 351 | In addition to the universal notation like Vec<float, 3>, you can use shorter aliases |
| 352 | for the most popular specialized variants of Vec, e.g. Vec3f ~ Vec<float, 3>. |
| 353 | |
| 354 | It is possible to convert Vec\<T,2\> to/from Point_, Vec\<T,3\> to/from Point3_ , and Vec\<T,4\> |
| 355 | to CvScalar or Scalar_. Use operator[] to access the elements of Vec. |
| 356 | |
| 357 | All the expected vector operations are also implemented: |
| 358 | - v1 = v2 + v3 |
| 359 | - v1 = v2 - v3 |
| 360 | - v1 = v2 \* scale |
| 361 | - v1 = scale \* v2 |
| 362 | - v1 = -v2 |
| 363 | - v1 += v2 and other augmenting operations |
| 364 | - v1 == v2, v1 != v2 |
| 365 | - norm(v1) (euclidean norm) |
| 366 | The Vec class is commonly used to describe pixel types of multi-channel arrays. See Mat for details. |
| 367 | */ |
| 368 | template<typename _Tp, int cn> class Vec : public Matx<_Tp, cn, 1> |
| 369 | { |
| 370 | public: |
| 371 | typedef _Tp value_type; |
| 372 | enum { |
| 373 | channels = cn, |
| 374 | #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED |
| 375 | depth = Matx<_Tp, cn, 1>::depth, |
| 376 | type = CV_MAKETYPE(depth, channels), |
| 377 | #endif |
| 378 | _dummy_enum_finalizer = 0 |
| 379 | }; |
| 380 | |
| 381 | //! default constructor |
| 382 | Vec(); |
| 383 | |
| 384 | Vec(_Tp v0); //!< 1-element vector constructor |
| 385 | Vec(_Tp v0, _Tp v1); //!< 2-element vector constructor |
| 386 | Vec(_Tp v0, _Tp v1, _Tp v2); //!< 3-element vector constructor |
| 387 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 4-element vector constructor |
| 388 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 5-element vector constructor |
| 389 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 6-element vector constructor |
| 390 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 7-element vector constructor |
| 391 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 8-element vector constructor |
| 392 | Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 9-element vector constructor |
| 393 | 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 |
| 394 | 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 |
| 395 | explicit Vec(const _Tp* values); |
| 396 | |
| 397 | Vec(std::initializer_list<_Tp>); |
| 398 | |
| 399 | Vec(const Vec<_Tp, cn>& v); |
| 400 | |
| 401 | static Vec all(_Tp alpha); |
| 402 | static Vec ones(); |
| 403 | static Vec randn(_Tp a, _Tp b); |
| 404 | static Vec randu(_Tp a, _Tp b); |
| 405 | static Vec zeros(); |
| 406 | static Vec diag(_Tp alpha) = delete; |
| 407 | static Vec eye() = delete; |
| 408 | |
| 409 | //! per-element multiplication |
| 410 | Vec mul(const Vec<_Tp, cn>& v) const; |
| 411 | |
| 412 | //! conjugation (makes sense for complex numbers and quaternions) |
| 413 | Vec conj() const; |
| 414 | |
| 415 | /*! |
| 416 | cross product of the two 3D vectors. |
| 417 | |
| 418 | For other dimensionalities the exception is raised |
| 419 | */ |
| 420 | Vec cross(const Vec& v) const; |
| 421 | //! conversion to another data type |
| 422 | template<typename T2> operator Vec<T2, cn>() const; |
| 423 | |
| 424 | /*! element access */ |
| 425 | const _Tp& operator [](int i) const; |
| 426 | _Tp& operator[](int i); |
| 427 | const _Tp& operator ()(int i) const; |
| 428 | _Tp& operator ()(int i); |
| 429 | |
| 430 | Vec<_Tp, cn>& operator=(const Vec<_Tp, cn>& rhs) = default; |
| 431 | |
| 432 | Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp); |
| 433 | Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp); |
| 434 | template<typename _T2> Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp); |
| 435 | }; |
| 436 | |
| 437 | /** @name Shorter aliases for the most popular specializations of Vec<T,n> |
| 438 | @{ |
| 439 | */ |
| 440 | typedef Vec<uchar, 2> Vec2b; |
| 441 | typedef Vec<uchar, 3> Vec3b; |
| 442 | typedef Vec<uchar, 4> Vec4b; |
| 443 | |
| 444 | typedef Vec<short, 2> Vec2s; |
| 445 | typedef Vec<short, 3> Vec3s; |
| 446 | typedef Vec<short, 4> Vec4s; |
| 447 | |
| 448 | typedef Vec<ushort, 2> Vec2w; |
| 449 | typedef Vec<ushort, 3> Vec3w; |
| 450 | typedef Vec<ushort, 4> Vec4w; |
| 451 | |
| 452 | typedef Vec<int, 2> Vec2i; |
| 453 | typedef Vec<int, 3> Vec3i; |
| 454 | typedef Vec<int, 4> Vec4i; |
| 455 | typedef Vec<int, 6> Vec6i; |
| 456 | typedef Vec<int, 8> Vec8i; |
| 457 | |
| 458 | typedef Vec<float, 2> Vec2f; |
| 459 | typedef Vec<float, 3> Vec3f; |
| 460 | typedef Vec<float, 4> Vec4f; |
| 461 | typedef Vec<float, 6> Vec6f; |
| 462 | |
| 463 | typedef Vec<double, 2> Vec2d; |
| 464 | typedef Vec<double, 3> Vec3d; |
| 465 | typedef Vec<double, 4> Vec4d; |
| 466 | typedef Vec<double, 6> Vec6d; |
| 467 | /** @} */ |
| 468 | |
| 469 | template<typename _Tp, int cn> inline |
| 470 | Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& v); |
| 471 | |
| 472 | template<typename _Tp1, typename _Tp2, int cn> static inline |
| 473 | Vec<_Tp1, cn>& operator += (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b); |
| 474 | |
| 475 | template<typename _Tp1, typename _Tp2, int cn> static inline |
| 476 | Vec<_Tp1, cn>& operator -= (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b); |
| 477 | |
| 478 | template<typename _Tp, int cn> static inline |
| 479 | Vec<_Tp, cn> operator + (const Vec<_Tp, cn>& a, const Vec<_Tp, cn>& b); |
| 480 | |
| 481 | template<typename _Tp, int cn> static inline |
| 482 | Vec<_Tp, cn> operator - (const Vec<_Tp, cn>& a, const Vec<_Tp, cn>& b); |
| 483 | |
| 484 | template<typename _Tp, int cn> static inline |
| 485 | Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, int alpha); |
| 486 | |
| 487 | template<typename _Tp, int cn> static inline |
| 488 | Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, float alpha); |
| 489 | |
| 490 | template<typename _Tp, int cn> static inline |
| 491 | Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, double alpha); |
| 492 | |
| 493 | template<typename _Tp, int cn> static inline |
| 494 | Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, int alpha); |
| 495 | |
| 496 | template<typename _Tp, int cn> static inline |
| 497 | Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, float alpha); |
| 498 | |
| 499 | template<typename _Tp, int cn> static inline |
| 500 | Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, double alpha); |
| 501 | |
| 502 | template<typename _Tp, int cn> static inline |
| 503 | Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, int alpha); |
| 504 | |
| 505 | template<typename _Tp, int cn> static inline |
| 506 | Vec<_Tp, cn> operator * (int alpha, const Vec<_Tp, cn>& a); |
| 507 | |
| 508 | template<typename _Tp, int cn> static inline |
| 509 | Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, float alpha); |
| 510 | |
| 511 | template<typename _Tp, int cn> static inline |
| 512 | Vec<_Tp, cn> operator * (float alpha, const Vec<_Tp, cn>& a); |
| 513 | |
| 514 | template<typename _Tp, int cn> static inline |
| 515 | Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, double alpha); |
| 516 | |
| 517 | template<typename _Tp, int cn> static inline |
| 518 | Vec<_Tp, cn> operator * (double alpha, const Vec<_Tp, cn>& a); |
| 519 | |
| 520 | template<typename _Tp, int cn> static inline |
| 521 | Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, int alpha); |
| 522 | |
| 523 | template<typename _Tp, int cn> static inline |
| 524 | Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, float alpha); |
| 525 | |
| 526 | template<typename _Tp, int cn> static inline |
| 527 | Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, double alpha); |
| 528 | |
| 529 | template<typename _Tp, int cn> static inline |
| 530 | Vec<_Tp, cn> operator - (const Vec<_Tp, cn>& a); |
| 531 | |
| 532 | template<typename _Tp> inline |
| 533 | Vec<_Tp, 4> operator * (const Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2); |
| 534 | |
| 535 | template<typename _Tp> inline |
| 536 | Vec<_Tp, 4>& operator *= (Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2); |
| 537 | |
| 538 | //! @} core_basic |
| 539 | |
| 540 | } // cv |
| 541 | |
| 542 | #include "opencv2/core/matx.inl.hpp" |
| 543 | |
| 544 | #endif // OPENCV_CORE_MATX_HPP |
| 545 | |