opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /*M///////////////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 2 //
joeverbout 0:ea44dc9ed014 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
joeverbout 0:ea44dc9ed014 4 //
joeverbout 0:ea44dc9ed014 5 // By downloading, copying, installing or using the software you agree to this license.
joeverbout 0:ea44dc9ed014 6 // If you do not agree to this license, do not download, install,
joeverbout 0:ea44dc9ed014 7 // copy or use the software.
joeverbout 0:ea44dc9ed014 8 //
joeverbout 0:ea44dc9ed014 9 //
joeverbout 0:ea44dc9ed014 10 // License Agreement
joeverbout 0:ea44dc9ed014 11 // For Open Source Computer Vision Library
joeverbout 0:ea44dc9ed014 12 //
joeverbout 0:ea44dc9ed014 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
joeverbout 0:ea44dc9ed014 16 // Third party copyrights are property of their respective owners.
joeverbout 0:ea44dc9ed014 17 //
joeverbout 0:ea44dc9ed014 18 // Redistribution and use in source and binary forms, with or without modification,
joeverbout 0:ea44dc9ed014 19 // are permitted provided that the following conditions are met:
joeverbout 0:ea44dc9ed014 20 //
joeverbout 0:ea44dc9ed014 21 // * Redistribution's of source code must retain the above copyright notice,
joeverbout 0:ea44dc9ed014 22 // this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 23 //
joeverbout 0:ea44dc9ed014 24 // * Redistribution's in binary form must reproduce the above copyright notice,
joeverbout 0:ea44dc9ed014 25 // this list of conditions and the following disclaimer in the documentation
joeverbout 0:ea44dc9ed014 26 // and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 27 //
joeverbout 0:ea44dc9ed014 28 // * The name of the copyright holders may not be used to endorse or promote products
joeverbout 0:ea44dc9ed014 29 // derived from this software without specific prior written permission.
joeverbout 0:ea44dc9ed014 30 //
joeverbout 0:ea44dc9ed014 31 // This software is provided by the copyright holders and contributors "as is" and
joeverbout 0:ea44dc9ed014 32 // any express or implied warranties, including, but not limited to, the implied
joeverbout 0:ea44dc9ed014 33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
joeverbout 0:ea44dc9ed014 34 // In no event shall the Intel Corporation or contributors be liable for any direct,
joeverbout 0:ea44dc9ed014 35 // indirect, incidental, special, exemplary, or consequential damages
joeverbout 0:ea44dc9ed014 36 // (including, but not limited to, procurement of substitute goods or services;
joeverbout 0:ea44dc9ed014 37 // loss of use, data, or profits; or business interruption) however caused
joeverbout 0:ea44dc9ed014 38 // and on any theory of liability, whether in contract, strict liability,
joeverbout 0:ea44dc9ed014 39 // or tort (including negligence or otherwise) arising in any way out of
joeverbout 0:ea44dc9ed014 40 // the use of this software, even if advised of the possibility of such damage.
joeverbout 0:ea44dc9ed014 41 //
joeverbout 0:ea44dc9ed014 42 //M*/
joeverbout 0:ea44dc9ed014 43
joeverbout 0:ea44dc9ed014 44 #ifndef __OPENCV_CORE_MAT_HPP__
joeverbout 0:ea44dc9ed014 45 #define __OPENCV_CORE_MAT_HPP__
joeverbout 0:ea44dc9ed014 46
joeverbout 0:ea44dc9ed014 47 #ifndef __cplusplus
joeverbout 0:ea44dc9ed014 48 # error mat.hpp header must be compiled as C++
joeverbout 0:ea44dc9ed014 49 #endif
joeverbout 0:ea44dc9ed014 50
joeverbout 0:ea44dc9ed014 51 #include "opencv2/core/matx.hpp"
joeverbout 0:ea44dc9ed014 52 #include "opencv2/core/types.hpp"
joeverbout 0:ea44dc9ed014 53
joeverbout 0:ea44dc9ed014 54 #include "opencv2/core/bufferpool.hpp"
joeverbout 0:ea44dc9ed014 55
joeverbout 0:ea44dc9ed014 56 namespace cv
joeverbout 0:ea44dc9ed014 57 {
joeverbout 0:ea44dc9ed014 58
joeverbout 0:ea44dc9ed014 59 //! @addtogroup core_basic
joeverbout 0:ea44dc9ed014 60 //! @{
joeverbout 0:ea44dc9ed014 61
joeverbout 0:ea44dc9ed014 62 enum { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25,
joeverbout 0:ea44dc9ed014 63 ACCESS_RW=3<<24, ACCESS_MASK=ACCESS_RW, ACCESS_FAST=1<<26 };
joeverbout 0:ea44dc9ed014 64
joeverbout 0:ea44dc9ed014 65 class CV_EXPORTS _OutputArray;
joeverbout 0:ea44dc9ed014 66
joeverbout 0:ea44dc9ed014 67 //////////////////////// Input/Output Array Arguments /////////////////////////////////
joeverbout 0:ea44dc9ed014 68
joeverbout 0:ea44dc9ed014 69 /** @brief This is the proxy class for passing read-only input arrays into OpenCV functions.
joeverbout 0:ea44dc9ed014 70
joeverbout 0:ea44dc9ed014 71 It is defined as:
joeverbout 0:ea44dc9ed014 72 @code
joeverbout 0:ea44dc9ed014 73 typedef const _InputArray& InputArray;
joeverbout 0:ea44dc9ed014 74 @endcode
joeverbout 0:ea44dc9ed014 75 where _InputArray is a class that can be constructed from `Mat`, `Mat_<T>`, `Matx<T, m, n>`,
joeverbout 0:ea44dc9ed014 76 `std::vector<T>`, `std::vector<std::vector<T> >` or `std::vector<Mat>`. It can also be constructed
joeverbout 0:ea44dc9ed014 77 from a matrix expression.
joeverbout 0:ea44dc9ed014 78
joeverbout 0:ea44dc9ed014 79 Since this is mostly implementation-level class, and its interface may change in future versions, we
joeverbout 0:ea44dc9ed014 80 do not describe it in details. There are a few key things, though, that should be kept in mind:
joeverbout 0:ea44dc9ed014 81
joeverbout 0:ea44dc9ed014 82 - When you see in the reference manual or in OpenCV source code a function that takes
joeverbout 0:ea44dc9ed014 83 InputArray, it means that you can actually pass `Mat`, `Matx`, `vector<T>` etc. (see above the
joeverbout 0:ea44dc9ed014 84 complete list).
joeverbout 0:ea44dc9ed014 85 - Optional input arguments: If some of the input arrays may be empty, pass cv::noArray() (or
joeverbout 0:ea44dc9ed014 86 simply cv::Mat() as you probably did before).
joeverbout 0:ea44dc9ed014 87 - The class is designed solely for passing parameters. That is, normally you *should not*
joeverbout 0:ea44dc9ed014 88 declare class members, local and global variables of this type.
joeverbout 0:ea44dc9ed014 89 - If you want to design your own function or a class method that can operate of arrays of
joeverbout 0:ea44dc9ed014 90 multiple types, you can use InputArray (or OutputArray) for the respective parameters. Inside
joeverbout 0:ea44dc9ed014 91 a function you should use _InputArray::getMat() method to construct a matrix header for the
joeverbout 0:ea44dc9ed014 92 array (without copying data). _InputArray::kind() can be used to distinguish Mat from
joeverbout 0:ea44dc9ed014 93 `vector<>` etc., but normally it is not needed.
joeverbout 0:ea44dc9ed014 94
joeverbout 0:ea44dc9ed014 95 Here is how you can use a function that takes InputArray :
joeverbout 0:ea44dc9ed014 96 @code
joeverbout 0:ea44dc9ed014 97 std::vector<Point2f> vec;
joeverbout 0:ea44dc9ed014 98 // points or a circle
joeverbout 0:ea44dc9ed014 99 for( int i = 0; i < 30; i++ )
joeverbout 0:ea44dc9ed014 100 vec.push_back(Point2f((float)(100 + 30*cos(i*CV_PI*2/5)),
joeverbout 0:ea44dc9ed014 101 (float)(100 - 30*sin(i*CV_PI*2/5))));
joeverbout 0:ea44dc9ed014 102 cv::transform(vec, vec, cv::Matx23f(0.707, -0.707, 10, 0.707, 0.707, 20));
joeverbout 0:ea44dc9ed014 103 @endcode
joeverbout 0:ea44dc9ed014 104 That is, we form an STL vector containing points, and apply in-place affine transformation to the
joeverbout 0:ea44dc9ed014 105 vector using the 2x3 matrix created inline as `Matx<float, 2, 3>` instance.
joeverbout 0:ea44dc9ed014 106
joeverbout 0:ea44dc9ed014 107 Here is how such a function can be implemented (for simplicity, we implement a very specific case of
joeverbout 0:ea44dc9ed014 108 it, according to the assertion statement inside) :
joeverbout 0:ea44dc9ed014 109 @code
joeverbout 0:ea44dc9ed014 110 void myAffineTransform(InputArray _src, OutputArray _dst, InputArray _m)
joeverbout 0:ea44dc9ed014 111 {
joeverbout 0:ea44dc9ed014 112 // get Mat headers for input arrays. This is O(1) operation,
joeverbout 0:ea44dc9ed014 113 // unless _src and/or _m are matrix expressions.
joeverbout 0:ea44dc9ed014 114 Mat src = _src.getMat(), m = _m.getMat();
joeverbout 0:ea44dc9ed014 115 CV_Assert( src.type() == CV_32FC2 && m.type() == CV_32F && m.size() == Size(3, 2) );
joeverbout 0:ea44dc9ed014 116
joeverbout 0:ea44dc9ed014 117 // [re]create the output array so that it has the proper size and type.
joeverbout 0:ea44dc9ed014 118 // In case of Mat it calls Mat::create, in case of STL vector it calls vector::resize.
joeverbout 0:ea44dc9ed014 119 _dst.create(src.size(), src.type());
joeverbout 0:ea44dc9ed014 120 Mat dst = _dst.getMat();
joeverbout 0:ea44dc9ed014 121
joeverbout 0:ea44dc9ed014 122 for( int i = 0; i < src.rows; i++ )
joeverbout 0:ea44dc9ed014 123 for( int j = 0; j < src.cols; j++ )
joeverbout 0:ea44dc9ed014 124 {
joeverbout 0:ea44dc9ed014 125 Point2f pt = src.at<Point2f>(i, j);
joeverbout 0:ea44dc9ed014 126 dst.at<Point2f>(i, j) = Point2f(m.at<float>(0, 0)*pt.x +
joeverbout 0:ea44dc9ed014 127 m.at<float>(0, 1)*pt.y +
joeverbout 0:ea44dc9ed014 128 m.at<float>(0, 2),
joeverbout 0:ea44dc9ed014 129 m.at<float>(1, 0)*pt.x +
joeverbout 0:ea44dc9ed014 130 m.at<float>(1, 1)*pt.y +
joeverbout 0:ea44dc9ed014 131 m.at<float>(1, 2));
joeverbout 0:ea44dc9ed014 132 }
joeverbout 0:ea44dc9ed014 133 }
joeverbout 0:ea44dc9ed014 134 @endcode
joeverbout 0:ea44dc9ed014 135 There is another related type, InputArrayOfArrays, which is currently defined as a synonym for
joeverbout 0:ea44dc9ed014 136 InputArray:
joeverbout 0:ea44dc9ed014 137 @code
joeverbout 0:ea44dc9ed014 138 typedef InputArray InputArrayOfArrays;
joeverbout 0:ea44dc9ed014 139 @endcode
joeverbout 0:ea44dc9ed014 140 It denotes function arguments that are either vectors of vectors or vectors of matrices. A separate
joeverbout 0:ea44dc9ed014 141 synonym is needed to generate Python/Java etc. wrappers properly. At the function implementation
joeverbout 0:ea44dc9ed014 142 level their use is similar, but _InputArray::getMat(idx) should be used to get header for the
joeverbout 0:ea44dc9ed014 143 idx-th component of the outer vector and _InputArray::size().area() should be used to find the
joeverbout 0:ea44dc9ed014 144 number of components (vectors/matrices) of the outer vector.
joeverbout 0:ea44dc9ed014 145 */
joeverbout 0:ea44dc9ed014 146 class CV_EXPORTS _InputArray
joeverbout 0:ea44dc9ed014 147 {
joeverbout 0:ea44dc9ed014 148 public:
joeverbout 0:ea44dc9ed014 149 enum {
joeverbout 0:ea44dc9ed014 150 KIND_SHIFT = 16,
joeverbout 0:ea44dc9ed014 151 FIXED_TYPE = 0x8000 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 152 FIXED_SIZE = 0x4000 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 153 KIND_MASK = 31 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 154
joeverbout 0:ea44dc9ed014 155 NONE = 0 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 156 MAT = 1 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 157 MATX = 2 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 158 STD_VECTOR = 3 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 159 STD_VECTOR_VECTOR = 4 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 160 STD_VECTOR_MAT = 5 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 161 EXPR = 6 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 162 OPENGL_BUFFER = 7 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 163 CUDA_HOST_MEM = 8 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 164 CUDA_GPU_MAT = 9 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 165 UMAT =10 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 166 STD_VECTOR_UMAT =11 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 167 STD_BOOL_VECTOR =12 << KIND_SHIFT,
joeverbout 0:ea44dc9ed014 168 STD_VECTOR_CUDA_GPU_MAT = 13 << KIND_SHIFT
joeverbout 0:ea44dc9ed014 169 };
joeverbout 0:ea44dc9ed014 170
joeverbout 0:ea44dc9ed014 171 _InputArray();
joeverbout 0:ea44dc9ed014 172 _InputArray(int _flags, void* _obj);
joeverbout 0:ea44dc9ed014 173 _InputArray(const Mat& m);
joeverbout 0:ea44dc9ed014 174 _InputArray(const MatExpr& expr);
joeverbout 0:ea44dc9ed014 175 _InputArray(const std::vector<Mat>& vec);
joeverbout 0:ea44dc9ed014 176 template<typename _Tp> _InputArray(const Mat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 177 template<typename _Tp> _InputArray(const std::vector<_Tp>& vec);
joeverbout 0:ea44dc9ed014 178 _InputArray(const std::vector<bool>& vec);
joeverbout 0:ea44dc9ed014 179 template<typename _Tp> _InputArray(const std::vector<std::vector<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 180 template<typename _Tp> _InputArray(const std::vector<Mat_<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 181 template<typename _Tp> _InputArray(const _Tp* vec, int n);
joeverbout 0:ea44dc9ed014 182 template<typename _Tp, int m, int n> _InputArray(const Matx<_Tp, m, n>& matx);
joeverbout 0:ea44dc9ed014 183 _InputArray(const double& val);
joeverbout 0:ea44dc9ed014 184 _InputArray(const cuda::GpuMat& d_mat);
joeverbout 0:ea44dc9ed014 185 _InputArray(const std::vector<cuda::GpuMat>& d_mat_array);
joeverbout 0:ea44dc9ed014 186 _InputArray(const ogl::Buffer& buf);
joeverbout 0:ea44dc9ed014 187 _InputArray(const cuda::HostMem& cuda_mem);
joeverbout 0:ea44dc9ed014 188 template<typename _Tp> _InputArray(const cudev::GpuMat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 189 _InputArray(const UMat& um);
joeverbout 0:ea44dc9ed014 190 _InputArray(const std::vector<UMat>& umv);
joeverbout 0:ea44dc9ed014 191
joeverbout 0:ea44dc9ed014 192 Mat getMat(int idx=-1) const;
joeverbout 0:ea44dc9ed014 193 Mat getMat_(int idx=-1) const;
joeverbout 0:ea44dc9ed014 194 UMat getUMat(int idx=-1) const;
joeverbout 0:ea44dc9ed014 195 void getMatVector(std::vector<Mat>& mv) const;
joeverbout 0:ea44dc9ed014 196 void getUMatVector(std::vector<UMat>& umv) const;
joeverbout 0:ea44dc9ed014 197 void getGpuMatVector(std::vector<cuda::GpuMat>& gpumv) const;
joeverbout 0:ea44dc9ed014 198 cuda::GpuMat getGpuMat() const;
joeverbout 0:ea44dc9ed014 199 ogl::Buffer getOGlBuffer() const;
joeverbout 0:ea44dc9ed014 200
joeverbout 0:ea44dc9ed014 201 int getFlags() const;
joeverbout 0:ea44dc9ed014 202 void* getObj() const;
joeverbout 0:ea44dc9ed014 203 Size getSz() const;
joeverbout 0:ea44dc9ed014 204
joeverbout 0:ea44dc9ed014 205 int kind() const;
joeverbout 0:ea44dc9ed014 206 int dims(int i=-1) const;
joeverbout 0:ea44dc9ed014 207 int cols(int i=-1) const;
joeverbout 0:ea44dc9ed014 208 int rows(int i=-1) const;
joeverbout 0:ea44dc9ed014 209 Size size(int i=-1) const;
joeverbout 0:ea44dc9ed014 210 int sizend(int* sz, int i=-1) const;
joeverbout 0:ea44dc9ed014 211 bool sameSize(const _InputArray& arr) const;
joeverbout 0:ea44dc9ed014 212 size_t total(int i=-1) const;
joeverbout 0:ea44dc9ed014 213 int type(int i=-1) const;
joeverbout 0:ea44dc9ed014 214 int depth(int i=-1) const;
joeverbout 0:ea44dc9ed014 215 int channels(int i=-1) const;
joeverbout 0:ea44dc9ed014 216 bool isContinuous(int i=-1) const;
joeverbout 0:ea44dc9ed014 217 bool isSubmatrix(int i=-1) const;
joeverbout 0:ea44dc9ed014 218 bool empty() const;
joeverbout 0:ea44dc9ed014 219 void copyTo(const _OutputArray& arr) const;
joeverbout 0:ea44dc9ed014 220 void copyTo(const _OutputArray& arr, const _InputArray & mask) const;
joeverbout 0:ea44dc9ed014 221 size_t offset(int i=-1) const;
joeverbout 0:ea44dc9ed014 222 size_t step(int i=-1) const;
joeverbout 0:ea44dc9ed014 223 bool isMat() const;
joeverbout 0:ea44dc9ed014 224 bool isUMat() const;
joeverbout 0:ea44dc9ed014 225 bool isMatVector() const;
joeverbout 0:ea44dc9ed014 226 bool isUMatVector() const;
joeverbout 0:ea44dc9ed014 227 bool isMatx() const;
joeverbout 0:ea44dc9ed014 228 bool isVector() const;
joeverbout 0:ea44dc9ed014 229 bool isGpuMatVector() const;
joeverbout 0:ea44dc9ed014 230 ~_InputArray();
joeverbout 0:ea44dc9ed014 231
joeverbout 0:ea44dc9ed014 232 protected:
joeverbout 0:ea44dc9ed014 233 int flags;
joeverbout 0:ea44dc9ed014 234 void* obj;
joeverbout 0:ea44dc9ed014 235 Size sz;
joeverbout 0:ea44dc9ed014 236
joeverbout 0:ea44dc9ed014 237 void init(int _flags, const void* _obj);
joeverbout 0:ea44dc9ed014 238 void init(int _flags, const void* _obj, Size _sz);
joeverbout 0:ea44dc9ed014 239 };
joeverbout 0:ea44dc9ed014 240
joeverbout 0:ea44dc9ed014 241
joeverbout 0:ea44dc9ed014 242 /** @brief This type is very similar to InputArray except that it is used for input/output and output function
joeverbout 0:ea44dc9ed014 243 parameters.
joeverbout 0:ea44dc9ed014 244
joeverbout 0:ea44dc9ed014 245 Just like with InputArray, OpenCV users should not care about OutputArray, they just pass `Mat`,
joeverbout 0:ea44dc9ed014 246 `vector<T>` etc. to the functions. The same limitation as for `InputArray`: *Do not explicitly
joeverbout 0:ea44dc9ed014 247 create OutputArray instances* applies here too.
joeverbout 0:ea44dc9ed014 248
joeverbout 0:ea44dc9ed014 249 If you want to make your function polymorphic (i.e. accept different arrays as output parameters),
joeverbout 0:ea44dc9ed014 250 it is also not very difficult. Take the sample above as the reference. Note that
joeverbout 0:ea44dc9ed014 251 _OutputArray::create() needs to be called before _OutputArray::getMat(). This way you guarantee
joeverbout 0:ea44dc9ed014 252 that the output array is properly allocated.
joeverbout 0:ea44dc9ed014 253
joeverbout 0:ea44dc9ed014 254 Optional output parameters. If you do not need certain output array to be computed and returned to
joeverbout 0:ea44dc9ed014 255 you, pass cv::noArray(), just like you would in the case of optional input array. At the
joeverbout 0:ea44dc9ed014 256 implementation level, use _OutputArray::needed() to check if certain output array needs to be
joeverbout 0:ea44dc9ed014 257 computed or not.
joeverbout 0:ea44dc9ed014 258
joeverbout 0:ea44dc9ed014 259 There are several synonyms for OutputArray that are used to assist automatic Python/Java/... wrapper
joeverbout 0:ea44dc9ed014 260 generators:
joeverbout 0:ea44dc9ed014 261 @code
joeverbout 0:ea44dc9ed014 262 typedef OutputArray OutputArrayOfArrays;
joeverbout 0:ea44dc9ed014 263 typedef OutputArray InputOutputArray;
joeverbout 0:ea44dc9ed014 264 typedef OutputArray InputOutputArrayOfArrays;
joeverbout 0:ea44dc9ed014 265 @endcode
joeverbout 0:ea44dc9ed014 266 */
joeverbout 0:ea44dc9ed014 267 class CV_EXPORTS _OutputArray : public _InputArray
joeverbout 0:ea44dc9ed014 268 {
joeverbout 0:ea44dc9ed014 269 public:
joeverbout 0:ea44dc9ed014 270 enum
joeverbout 0:ea44dc9ed014 271 {
joeverbout 0:ea44dc9ed014 272 DEPTH_MASK_8U = 1 << CV_8U,
joeverbout 0:ea44dc9ed014 273 DEPTH_MASK_8S = 1 << CV_8S,
joeverbout 0:ea44dc9ed014 274 DEPTH_MASK_16U = 1 << CV_16U,
joeverbout 0:ea44dc9ed014 275 DEPTH_MASK_16S = 1 << CV_16S,
joeverbout 0:ea44dc9ed014 276 DEPTH_MASK_32S = 1 << CV_32S,
joeverbout 0:ea44dc9ed014 277 DEPTH_MASK_32F = 1 << CV_32F,
joeverbout 0:ea44dc9ed014 278 DEPTH_MASK_64F = 1 << CV_64F,
joeverbout 0:ea44dc9ed014 279 DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1,
joeverbout 0:ea44dc9ed014 280 DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S,
joeverbout 0:ea44dc9ed014 281 DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F
joeverbout 0:ea44dc9ed014 282 };
joeverbout 0:ea44dc9ed014 283
joeverbout 0:ea44dc9ed014 284 _OutputArray();
joeverbout 0:ea44dc9ed014 285 _OutputArray(int _flags, void* _obj);
joeverbout 0:ea44dc9ed014 286 _OutputArray(Mat& m);
joeverbout 0:ea44dc9ed014 287 _OutputArray(std::vector<Mat>& vec);
joeverbout 0:ea44dc9ed014 288 _OutputArray(cuda::GpuMat& d_mat);
joeverbout 0:ea44dc9ed014 289 _OutputArray(std::vector<cuda::GpuMat>& d_mat);
joeverbout 0:ea44dc9ed014 290 _OutputArray(ogl::Buffer& buf);
joeverbout 0:ea44dc9ed014 291 _OutputArray(cuda::HostMem& cuda_mem);
joeverbout 0:ea44dc9ed014 292 template<typename _Tp> _OutputArray(cudev::GpuMat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 293 template<typename _Tp> _OutputArray(std::vector<_Tp>& vec);
joeverbout 0:ea44dc9ed014 294 _OutputArray(std::vector<bool>& vec);
joeverbout 0:ea44dc9ed014 295 template<typename _Tp> _OutputArray(std::vector<std::vector<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 296 template<typename _Tp> _OutputArray(std::vector<Mat_<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 297 template<typename _Tp> _OutputArray(Mat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 298 template<typename _Tp> _OutputArray(_Tp* vec, int n);
joeverbout 0:ea44dc9ed014 299 template<typename _Tp, int m, int n> _OutputArray(Matx<_Tp, m, n>& matx);
joeverbout 0:ea44dc9ed014 300 _OutputArray(UMat& m);
joeverbout 0:ea44dc9ed014 301 _OutputArray(std::vector<UMat>& vec);
joeverbout 0:ea44dc9ed014 302
joeverbout 0:ea44dc9ed014 303 _OutputArray(const Mat& m);
joeverbout 0:ea44dc9ed014 304 _OutputArray(const std::vector<Mat>& vec);
joeverbout 0:ea44dc9ed014 305 _OutputArray(const cuda::GpuMat& d_mat);
joeverbout 0:ea44dc9ed014 306 _OutputArray(const std::vector<cuda::GpuMat>& d_mat);
joeverbout 0:ea44dc9ed014 307 _OutputArray(const ogl::Buffer& buf);
joeverbout 0:ea44dc9ed014 308 _OutputArray(const cuda::HostMem& cuda_mem);
joeverbout 0:ea44dc9ed014 309 template<typename _Tp> _OutputArray(const cudev::GpuMat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 310 template<typename _Tp> _OutputArray(const std::vector<_Tp>& vec);
joeverbout 0:ea44dc9ed014 311 template<typename _Tp> _OutputArray(const std::vector<std::vector<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 312 template<typename _Tp> _OutputArray(const std::vector<Mat_<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 313 template<typename _Tp> _OutputArray(const Mat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 314 template<typename _Tp> _OutputArray(const _Tp* vec, int n);
joeverbout 0:ea44dc9ed014 315 template<typename _Tp, int m, int n> _OutputArray(const Matx<_Tp, m, n>& matx);
joeverbout 0:ea44dc9ed014 316 _OutputArray(const UMat& m);
joeverbout 0:ea44dc9ed014 317 _OutputArray(const std::vector<UMat>& vec);
joeverbout 0:ea44dc9ed014 318
joeverbout 0:ea44dc9ed014 319 bool fixedSize() const;
joeverbout 0:ea44dc9ed014 320 bool fixedType() const;
joeverbout 0:ea44dc9ed014 321 bool needed() const;
joeverbout 0:ea44dc9ed014 322 Mat& getMatRef(int i=-1) const;
joeverbout 0:ea44dc9ed014 323 UMat& getUMatRef(int i=-1) const;
joeverbout 0:ea44dc9ed014 324 cuda::GpuMat& getGpuMatRef() const;
joeverbout 0:ea44dc9ed014 325 std::vector<cuda::GpuMat>& getGpuMatVecRef() const;
joeverbout 0:ea44dc9ed014 326 ogl::Buffer& getOGlBufferRef() const;
joeverbout 0:ea44dc9ed014 327 cuda::HostMem& getHostMemRef() const;
joeverbout 0:ea44dc9ed014 328 void create(Size sz, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
joeverbout 0:ea44dc9ed014 329 void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
joeverbout 0:ea44dc9ed014 330 void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
joeverbout 0:ea44dc9ed014 331 void createSameSize(const _InputArray& arr, int mtype) const;
joeverbout 0:ea44dc9ed014 332 void release() const;
joeverbout 0:ea44dc9ed014 333 void clear() const;
joeverbout 0:ea44dc9ed014 334 void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const;
joeverbout 0:ea44dc9ed014 335
joeverbout 0:ea44dc9ed014 336 void assign(const UMat& u) const;
joeverbout 0:ea44dc9ed014 337 void assign(const Mat& m) const;
joeverbout 0:ea44dc9ed014 338 };
joeverbout 0:ea44dc9ed014 339
joeverbout 0:ea44dc9ed014 340
joeverbout 0:ea44dc9ed014 341 class CV_EXPORTS _InputOutputArray : public _OutputArray
joeverbout 0:ea44dc9ed014 342 {
joeverbout 0:ea44dc9ed014 343 public:
joeverbout 0:ea44dc9ed014 344 _InputOutputArray();
joeverbout 0:ea44dc9ed014 345 _InputOutputArray(int _flags, void* _obj);
joeverbout 0:ea44dc9ed014 346 _InputOutputArray(Mat& m);
joeverbout 0:ea44dc9ed014 347 _InputOutputArray(std::vector<Mat>& vec);
joeverbout 0:ea44dc9ed014 348 _InputOutputArray(cuda::GpuMat& d_mat);
joeverbout 0:ea44dc9ed014 349 _InputOutputArray(ogl::Buffer& buf);
joeverbout 0:ea44dc9ed014 350 _InputOutputArray(cuda::HostMem& cuda_mem);
joeverbout 0:ea44dc9ed014 351 template<typename _Tp> _InputOutputArray(cudev::GpuMat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 352 template<typename _Tp> _InputOutputArray(std::vector<_Tp>& vec);
joeverbout 0:ea44dc9ed014 353 _InputOutputArray(std::vector<bool>& vec);
joeverbout 0:ea44dc9ed014 354 template<typename _Tp> _InputOutputArray(std::vector<std::vector<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 355 template<typename _Tp> _InputOutputArray(std::vector<Mat_<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 356 template<typename _Tp> _InputOutputArray(Mat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 357 template<typename _Tp> _InputOutputArray(_Tp* vec, int n);
joeverbout 0:ea44dc9ed014 358 template<typename _Tp, int m, int n> _InputOutputArray(Matx<_Tp, m, n>& matx);
joeverbout 0:ea44dc9ed014 359 _InputOutputArray(UMat& m);
joeverbout 0:ea44dc9ed014 360 _InputOutputArray(std::vector<UMat>& vec);
joeverbout 0:ea44dc9ed014 361
joeverbout 0:ea44dc9ed014 362 _InputOutputArray(const Mat& m);
joeverbout 0:ea44dc9ed014 363 _InputOutputArray(const std::vector<Mat>& vec);
joeverbout 0:ea44dc9ed014 364 _InputOutputArray(const cuda::GpuMat& d_mat);
joeverbout 0:ea44dc9ed014 365 _InputOutputArray(const std::vector<cuda::GpuMat>& d_mat);
joeverbout 0:ea44dc9ed014 366 _InputOutputArray(const ogl::Buffer& buf);
joeverbout 0:ea44dc9ed014 367 _InputOutputArray(const cuda::HostMem& cuda_mem);
joeverbout 0:ea44dc9ed014 368 template<typename _Tp> _InputOutputArray(const cudev::GpuMat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 369 template<typename _Tp> _InputOutputArray(const std::vector<_Tp>& vec);
joeverbout 0:ea44dc9ed014 370 template<typename _Tp> _InputOutputArray(const std::vector<std::vector<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 371 template<typename _Tp> _InputOutputArray(const std::vector<Mat_<_Tp> >& vec);
joeverbout 0:ea44dc9ed014 372 template<typename _Tp> _InputOutputArray(const Mat_<_Tp>& m);
joeverbout 0:ea44dc9ed014 373 template<typename _Tp> _InputOutputArray(const _Tp* vec, int n);
joeverbout 0:ea44dc9ed014 374 template<typename _Tp, int m, int n> _InputOutputArray(const Matx<_Tp, m, n>& matx);
joeverbout 0:ea44dc9ed014 375 _InputOutputArray(const UMat& m);
joeverbout 0:ea44dc9ed014 376 _InputOutputArray(const std::vector<UMat>& vec);
joeverbout 0:ea44dc9ed014 377 };
joeverbout 0:ea44dc9ed014 378
joeverbout 0:ea44dc9ed014 379 typedef const _InputArray& InputArray;
joeverbout 0:ea44dc9ed014 380 typedef InputArray InputArrayOfArrays;
joeverbout 0:ea44dc9ed014 381 typedef const _OutputArray& OutputArray;
joeverbout 0:ea44dc9ed014 382 typedef OutputArray OutputArrayOfArrays;
joeverbout 0:ea44dc9ed014 383 typedef const _InputOutputArray& InputOutputArray;
joeverbout 0:ea44dc9ed014 384 typedef InputOutputArray InputOutputArrayOfArrays;
joeverbout 0:ea44dc9ed014 385
joeverbout 0:ea44dc9ed014 386 CV_EXPORTS InputOutputArray noArray();
joeverbout 0:ea44dc9ed014 387
joeverbout 0:ea44dc9ed014 388 /////////////////////////////////// MatAllocator //////////////////////////////////////
joeverbout 0:ea44dc9ed014 389
joeverbout 0:ea44dc9ed014 390 //! Usage flags for allocator
joeverbout 0:ea44dc9ed014 391 enum UMatUsageFlags
joeverbout 0:ea44dc9ed014 392 {
joeverbout 0:ea44dc9ed014 393 USAGE_DEFAULT = 0,
joeverbout 0:ea44dc9ed014 394
joeverbout 0:ea44dc9ed014 395 // buffer allocation policy is platform and usage specific
joeverbout 0:ea44dc9ed014 396 USAGE_ALLOCATE_HOST_MEMORY = 1 << 0,
joeverbout 0:ea44dc9ed014 397 USAGE_ALLOCATE_DEVICE_MEMORY = 1 << 1,
joeverbout 0:ea44dc9ed014 398 USAGE_ALLOCATE_SHARED_MEMORY = 1 << 2, // It is not equal to: USAGE_ALLOCATE_HOST_MEMORY | USAGE_ALLOCATE_DEVICE_MEMORY
joeverbout 0:ea44dc9ed014 399
joeverbout 0:ea44dc9ed014 400 __UMAT_USAGE_FLAGS_32BIT = 0x7fffffff // Binary compatibility hint
joeverbout 0:ea44dc9ed014 401 };
joeverbout 0:ea44dc9ed014 402
joeverbout 0:ea44dc9ed014 403 struct CV_EXPORTS UMatData;
joeverbout 0:ea44dc9ed014 404
joeverbout 0:ea44dc9ed014 405 /** @brief Custom array allocator
joeverbout 0:ea44dc9ed014 406 */
joeverbout 0:ea44dc9ed014 407 class CV_EXPORTS MatAllocator
joeverbout 0:ea44dc9ed014 408 {
joeverbout 0:ea44dc9ed014 409 public:
joeverbout 0:ea44dc9ed014 410 MatAllocator() {}
joeverbout 0:ea44dc9ed014 411 virtual ~MatAllocator() {}
joeverbout 0:ea44dc9ed014 412
joeverbout 0:ea44dc9ed014 413 // let's comment it off for now to detect and fix all the uses of allocator
joeverbout 0:ea44dc9ed014 414 //virtual void allocate(int dims, const int* sizes, int type, int*& refcount,
joeverbout 0:ea44dc9ed014 415 // uchar*& datastart, uchar*& data, size_t* step) = 0;
joeverbout 0:ea44dc9ed014 416 //virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0;
joeverbout 0:ea44dc9ed014 417 virtual UMatData* allocate(int dims, const int* sizes, int type,
joeverbout 0:ea44dc9ed014 418 void* data, size_t* step, int flags, UMatUsageFlags usageFlags) const = 0;
joeverbout 0:ea44dc9ed014 419 virtual bool allocate(UMatData* data, int accessflags, UMatUsageFlags usageFlags) const = 0;
joeverbout 0:ea44dc9ed014 420 virtual void deallocate(UMatData* data) const = 0;
joeverbout 0:ea44dc9ed014 421 virtual void map(UMatData* data, int accessflags) const;
joeverbout 0:ea44dc9ed014 422 virtual void unmap(UMatData* data) const;
joeverbout 0:ea44dc9ed014 423 virtual void download(UMatData* data, void* dst, int dims, const size_t sz[],
joeverbout 0:ea44dc9ed014 424 const size_t srcofs[], const size_t srcstep[],
joeverbout 0:ea44dc9ed014 425 const size_t dststep[]) const;
joeverbout 0:ea44dc9ed014 426 virtual void upload(UMatData* data, const void* src, int dims, const size_t sz[],
joeverbout 0:ea44dc9ed014 427 const size_t dstofs[], const size_t dststep[],
joeverbout 0:ea44dc9ed014 428 const size_t srcstep[]) const;
joeverbout 0:ea44dc9ed014 429 virtual void copy(UMatData* srcdata, UMatData* dstdata, int dims, const size_t sz[],
joeverbout 0:ea44dc9ed014 430 const size_t srcofs[], const size_t srcstep[],
joeverbout 0:ea44dc9ed014 431 const size_t dstofs[], const size_t dststep[], bool sync) const;
joeverbout 0:ea44dc9ed014 432
joeverbout 0:ea44dc9ed014 433 // default implementation returns DummyBufferPoolController
joeverbout 0:ea44dc9ed014 434 virtual BufferPoolController* getBufferPoolController(const char* id = NULL) const;
joeverbout 0:ea44dc9ed014 435 };
joeverbout 0:ea44dc9ed014 436
joeverbout 0:ea44dc9ed014 437
joeverbout 0:ea44dc9ed014 438 //////////////////////////////// MatCommaInitializer //////////////////////////////////
joeverbout 0:ea44dc9ed014 439
joeverbout 0:ea44dc9ed014 440 /** @brief Comma-separated Matrix Initializer
joeverbout 0:ea44dc9ed014 441
joeverbout 0:ea44dc9ed014 442 The class instances are usually not created explicitly.
joeverbout 0:ea44dc9ed014 443 Instead, they are created on "matrix << firstValue" operator.
joeverbout 0:ea44dc9ed014 444
joeverbout 0:ea44dc9ed014 445 The sample below initializes 2x2 rotation matrix:
joeverbout 0:ea44dc9ed014 446
joeverbout 0:ea44dc9ed014 447 \code
joeverbout 0:ea44dc9ed014 448 double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180);
joeverbout 0:ea44dc9ed014 449 Mat R = (Mat_<double>(2,2) << a, -b, b, a);
joeverbout 0:ea44dc9ed014 450 \endcode
joeverbout 0:ea44dc9ed014 451 */
joeverbout 0:ea44dc9ed014 452 template<typename _Tp> class MatCommaInitializer_
joeverbout 0:ea44dc9ed014 453 {
joeverbout 0:ea44dc9ed014 454 public:
joeverbout 0:ea44dc9ed014 455 //! the constructor, created by "matrix << firstValue" operator, where matrix is cv::Mat
joeverbout 0:ea44dc9ed014 456 MatCommaInitializer_(Mat_<_Tp>* _m);
joeverbout 0:ea44dc9ed014 457 //! the operator that takes the next value and put it to the matrix
joeverbout 0:ea44dc9ed014 458 template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v);
joeverbout 0:ea44dc9ed014 459 //! another form of conversion operator
joeverbout 0:ea44dc9ed014 460 operator Mat_<_Tp>() const;
joeverbout 0:ea44dc9ed014 461 protected:
joeverbout 0:ea44dc9ed014 462 MatIterator_<_Tp> it;
joeverbout 0:ea44dc9ed014 463 };
joeverbout 0:ea44dc9ed014 464
joeverbout 0:ea44dc9ed014 465
joeverbout 0:ea44dc9ed014 466 /////////////////////////////////////// Mat ///////////////////////////////////////////
joeverbout 0:ea44dc9ed014 467
joeverbout 0:ea44dc9ed014 468 // note that umatdata might be allocated together
joeverbout 0:ea44dc9ed014 469 // with the matrix data, not as a separate object.
joeverbout 0:ea44dc9ed014 470 // therefore, it does not have constructor or destructor;
joeverbout 0:ea44dc9ed014 471 // it should be explicitly initialized using init().
joeverbout 0:ea44dc9ed014 472 struct CV_EXPORTS UMatData
joeverbout 0:ea44dc9ed014 473 {
joeverbout 0:ea44dc9ed014 474 enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2,
joeverbout 0:ea44dc9ed014 475 DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24,
joeverbout 0:ea44dc9ed014 476 USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64};
joeverbout 0:ea44dc9ed014 477 UMatData(const MatAllocator* allocator);
joeverbout 0:ea44dc9ed014 478 ~UMatData();
joeverbout 0:ea44dc9ed014 479
joeverbout 0:ea44dc9ed014 480 // provide atomic access to the structure
joeverbout 0:ea44dc9ed014 481 void lock();
joeverbout 0:ea44dc9ed014 482 void unlock();
joeverbout 0:ea44dc9ed014 483
joeverbout 0:ea44dc9ed014 484 bool hostCopyObsolete() const;
joeverbout 0:ea44dc9ed014 485 bool deviceCopyObsolete() const;
joeverbout 0:ea44dc9ed014 486 bool deviceMemMapped() const;
joeverbout 0:ea44dc9ed014 487 bool copyOnMap() const;
joeverbout 0:ea44dc9ed014 488 bool tempUMat() const;
joeverbout 0:ea44dc9ed014 489 bool tempCopiedUMat() const;
joeverbout 0:ea44dc9ed014 490 void markHostCopyObsolete(bool flag);
joeverbout 0:ea44dc9ed014 491 void markDeviceCopyObsolete(bool flag);
joeverbout 0:ea44dc9ed014 492 void markDeviceMemMapped(bool flag);
joeverbout 0:ea44dc9ed014 493
joeverbout 0:ea44dc9ed014 494 const MatAllocator* prevAllocator;
joeverbout 0:ea44dc9ed014 495 const MatAllocator* currAllocator;
joeverbout 0:ea44dc9ed014 496 int urefcount;
joeverbout 0:ea44dc9ed014 497 int refcount;
joeverbout 0:ea44dc9ed014 498 uchar* data;
joeverbout 0:ea44dc9ed014 499 uchar* origdata;
joeverbout 0:ea44dc9ed014 500 size_t size;
joeverbout 0:ea44dc9ed014 501
joeverbout 0:ea44dc9ed014 502 int flags;
joeverbout 0:ea44dc9ed014 503 void* handle;
joeverbout 0:ea44dc9ed014 504 void* userdata;
joeverbout 0:ea44dc9ed014 505 int allocatorFlags_;
joeverbout 0:ea44dc9ed014 506 int mapcount;
joeverbout 0:ea44dc9ed014 507 UMatData* originalUMatData;
joeverbout 0:ea44dc9ed014 508 };
joeverbout 0:ea44dc9ed014 509
joeverbout 0:ea44dc9ed014 510
joeverbout 0:ea44dc9ed014 511 struct CV_EXPORTS UMatDataAutoLock
joeverbout 0:ea44dc9ed014 512 {
joeverbout 0:ea44dc9ed014 513 explicit UMatDataAutoLock(UMatData* u);
joeverbout 0:ea44dc9ed014 514 ~UMatDataAutoLock();
joeverbout 0:ea44dc9ed014 515 UMatData* u;
joeverbout 0:ea44dc9ed014 516 };
joeverbout 0:ea44dc9ed014 517
joeverbout 0:ea44dc9ed014 518
joeverbout 0:ea44dc9ed014 519 struct CV_EXPORTS MatSize
joeverbout 0:ea44dc9ed014 520 {
joeverbout 0:ea44dc9ed014 521 explicit MatSize(int* _p);
joeverbout 0:ea44dc9ed014 522 Size operator()() const;
joeverbout 0:ea44dc9ed014 523 const int& operator[](int i) const;
joeverbout 0:ea44dc9ed014 524 int& operator[](int i);
joeverbout 0:ea44dc9ed014 525 operator const int*() const;
joeverbout 0:ea44dc9ed014 526 bool operator == (const MatSize& sz) const;
joeverbout 0:ea44dc9ed014 527 bool operator != (const MatSize& sz) const;
joeverbout 0:ea44dc9ed014 528
joeverbout 0:ea44dc9ed014 529 int* p;
joeverbout 0:ea44dc9ed014 530 };
joeverbout 0:ea44dc9ed014 531
joeverbout 0:ea44dc9ed014 532 struct CV_EXPORTS MatStep
joeverbout 0:ea44dc9ed014 533 {
joeverbout 0:ea44dc9ed014 534 MatStep();
joeverbout 0:ea44dc9ed014 535 explicit MatStep(size_t s);
joeverbout 0:ea44dc9ed014 536 const size_t& operator[](int i) const;
joeverbout 0:ea44dc9ed014 537 size_t& operator[](int i);
joeverbout 0:ea44dc9ed014 538 operator size_t() const;
joeverbout 0:ea44dc9ed014 539 MatStep& operator = (size_t s);
joeverbout 0:ea44dc9ed014 540
joeverbout 0:ea44dc9ed014 541 size_t* p;
joeverbout 0:ea44dc9ed014 542 size_t buf[2];
joeverbout 0:ea44dc9ed014 543 protected:
joeverbout 0:ea44dc9ed014 544 MatStep& operator = (const MatStep&);
joeverbout 0:ea44dc9ed014 545 };
joeverbout 0:ea44dc9ed014 546
joeverbout 0:ea44dc9ed014 547 /** @example cout_mat.cpp
joeverbout 0:ea44dc9ed014 548 An example demonstrating the serial out capabilities of cv::Mat
joeverbout 0:ea44dc9ed014 549 */
joeverbout 0:ea44dc9ed014 550
joeverbout 0:ea44dc9ed014 551 /** @brief n-dimensional dense array class
joeverbout 0:ea44dc9ed014 552
joeverbout 0:ea44dc9ed014 553 The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array. It
joeverbout 0:ea44dc9ed014 554 can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel
joeverbout 0:ea44dc9ed014 555 volumes, vector fields, point clouds, tensors, histograms (though, very high-dimensional histograms
joeverbout 0:ea44dc9ed014 556 may be better stored in a SparseMat ). The data layout of the array `M` is defined by the array
joeverbout 0:ea44dc9ed014 557 `M.step[]`, so that the address of element \f$(i_0,...,i_{M.dims-1})\f$, where \f$0\leq i_k<M.size[k]\f$, is
joeverbout 0:ea44dc9ed014 558 computed as:
joeverbout 0:ea44dc9ed014 559 \f[addr(M_{i_0,...,i_{M.dims-1}}) = M.data + M.step[0]*i_0 + M.step[1]*i_1 + ... + M.step[M.dims-1]*i_{M.dims-1}\f]
joeverbout 0:ea44dc9ed014 560 In case of a 2-dimensional array, the above formula is reduced to:
joeverbout 0:ea44dc9ed014 561 \f[addr(M_{i,j}) = M.data + M.step[0]*i + M.step[1]*j\f]
joeverbout 0:ea44dc9ed014 562 Note that `M.step[i] >= M.step[i+1]` (in fact, `M.step[i] >= M.step[i+1]*M.size[i+1]` ). This means
joeverbout 0:ea44dc9ed014 563 that 2-dimensional matrices are stored row-by-row, 3-dimensional matrices are stored plane-by-plane,
joeverbout 0:ea44dc9ed014 564 and so on. M.step[M.dims-1] is minimal and always equal to the element size M.elemSize() .
joeverbout 0:ea44dc9ed014 565
joeverbout 0:ea44dc9ed014 566 So, the data layout in Mat is fully compatible with CvMat, IplImage, and CvMatND types from OpenCV
joeverbout 0:ea44dc9ed014 567 1.x. It is also compatible with the majority of dense array types from the standard toolkits and
joeverbout 0:ea44dc9ed014 568 SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, that is, with any
joeverbout 0:ea44dc9ed014 569 array that uses *steps* (or *strides*) to compute the position of a pixel. Due to this
joeverbout 0:ea44dc9ed014 570 compatibility, it is possible to make a Mat header for user-allocated data and process it in-place
joeverbout 0:ea44dc9ed014 571 using OpenCV functions.
joeverbout 0:ea44dc9ed014 572
joeverbout 0:ea44dc9ed014 573 There are many different ways to create a Mat object. The most popular options are listed below:
joeverbout 0:ea44dc9ed014 574
joeverbout 0:ea44dc9ed014 575 - Use the create(nrows, ncols, type) method or the similar Mat(nrows, ncols, type[, fillValue])
joeverbout 0:ea44dc9ed014 576 constructor. A new array of the specified size and type is allocated. type has the same meaning as
joeverbout 0:ea44dc9ed014 577 in the cvCreateMat method. For example, CV_8UC1 means a 8-bit single-channel array, CV_32FC2
joeverbout 0:ea44dc9ed014 578 means a 2-channel (complex) floating-point array, and so on.
joeverbout 0:ea44dc9ed014 579 @code
joeverbout 0:ea44dc9ed014 580 // make a 7x7 complex matrix filled with 1+3j.
joeverbout 0:ea44dc9ed014 581 Mat M(7,7,CV_32FC2,Scalar(1,3));
joeverbout 0:ea44dc9ed014 582 // and now turn M to a 100x60 15-channel 8-bit matrix.
joeverbout 0:ea44dc9ed014 583 // The old content will be deallocated
joeverbout 0:ea44dc9ed014 584 M.create(100,60,CV_8UC(15));
joeverbout 0:ea44dc9ed014 585 @endcode
joeverbout 0:ea44dc9ed014 586 As noted in the introduction to this chapter, create() allocates only a new array when the shape
joeverbout 0:ea44dc9ed014 587 or type of the current array are different from the specified ones.
joeverbout 0:ea44dc9ed014 588
joeverbout 0:ea44dc9ed014 589 - Create a multi-dimensional array:
joeverbout 0:ea44dc9ed014 590 @code
joeverbout 0:ea44dc9ed014 591 // create a 100x100x100 8-bit array
joeverbout 0:ea44dc9ed014 592 int sz[] = {100, 100, 100};
joeverbout 0:ea44dc9ed014 593 Mat bigCube(3, sz, CV_8U, Scalar::all(0));
joeverbout 0:ea44dc9ed014 594 @endcode
joeverbout 0:ea44dc9ed014 595 It passes the number of dimensions =1 to the Mat constructor but the created array will be
joeverbout 0:ea44dc9ed014 596 2-dimensional with the number of columns set to 1. So, Mat::dims is always \>= 2 (can also be 0
joeverbout 0:ea44dc9ed014 597 when the array is empty).
joeverbout 0:ea44dc9ed014 598
joeverbout 0:ea44dc9ed014 599 - Use a copy constructor or assignment operator where there can be an array or expression on the
joeverbout 0:ea44dc9ed014 600 right side (see below). As noted in the introduction, the array assignment is an O(1) operation
joeverbout 0:ea44dc9ed014 601 because it only copies the header and increases the reference counter. The Mat::clone() method can
joeverbout 0:ea44dc9ed014 602 be used to get a full (deep) copy of the array when you need it.
joeverbout 0:ea44dc9ed014 603
joeverbout 0:ea44dc9ed014 604 - Construct a header for a part of another array. It can be a single row, single column, several
joeverbout 0:ea44dc9ed014 605 rows, several columns, rectangular region in the array (called a *minor* in algebra) or a
joeverbout 0:ea44dc9ed014 606 diagonal. Such operations are also O(1) because the new header references the same data. You can
joeverbout 0:ea44dc9ed014 607 actually modify a part of the array using this feature, for example:
joeverbout 0:ea44dc9ed014 608 @code
joeverbout 0:ea44dc9ed014 609 // add the 5-th row, multiplied by 3 to the 3rd row
joeverbout 0:ea44dc9ed014 610 M.row(3) = M.row(3) + M.row(5)*3;
joeverbout 0:ea44dc9ed014 611 // now copy the 7-th column to the 1-st column
joeverbout 0:ea44dc9ed014 612 // M.col(1) = M.col(7); // this will not work
joeverbout 0:ea44dc9ed014 613 Mat M1 = M.col(1);
joeverbout 0:ea44dc9ed014 614 M.col(7).copyTo(M1);
joeverbout 0:ea44dc9ed014 615 // create a new 320x240 image
joeverbout 0:ea44dc9ed014 616 Mat img(Size(320,240),CV_8UC3);
joeverbout 0:ea44dc9ed014 617 // select a ROI
joeverbout 0:ea44dc9ed014 618 Mat roi(img, Rect(10,10,100,100));
joeverbout 0:ea44dc9ed014 619 // fill the ROI with (0,255,0) (which is green in RGB space);
joeverbout 0:ea44dc9ed014 620 // the original 320x240 image will be modified
joeverbout 0:ea44dc9ed014 621 roi = Scalar(0,255,0);
joeverbout 0:ea44dc9ed014 622 @endcode
joeverbout 0:ea44dc9ed014 623 Due to the additional datastart and dataend members, it is possible to compute a relative
joeverbout 0:ea44dc9ed014 624 sub-array position in the main *container* array using locateROI():
joeverbout 0:ea44dc9ed014 625 @code
joeverbout 0:ea44dc9ed014 626 Mat A = Mat::eye(10, 10, CV_32S);
joeverbout 0:ea44dc9ed014 627 // extracts A columns, 1 (inclusive) to 3 (exclusive).
joeverbout 0:ea44dc9ed014 628 Mat B = A(Range::all(), Range(1, 3));
joeverbout 0:ea44dc9ed014 629 // extracts B rows, 5 (inclusive) to 9 (exclusive).
joeverbout 0:ea44dc9ed014 630 // that is, C \~ A(Range(5, 9), Range(1, 3))
joeverbout 0:ea44dc9ed014 631 Mat C = B(Range(5, 9), Range::all());
joeverbout 0:ea44dc9ed014 632 Size size; Point ofs;
joeverbout 0:ea44dc9ed014 633 C.locateROI(size, ofs);
joeverbout 0:ea44dc9ed014 634 // size will be (width=10,height=10) and the ofs will be (x=1, y=5)
joeverbout 0:ea44dc9ed014 635 @endcode
joeverbout 0:ea44dc9ed014 636 As in case of whole matrices, if you need a deep copy, use the `clone()` method of the extracted
joeverbout 0:ea44dc9ed014 637 sub-matrices.
joeverbout 0:ea44dc9ed014 638
joeverbout 0:ea44dc9ed014 639 - Make a header for user-allocated data. It can be useful to do the following:
joeverbout 0:ea44dc9ed014 640 -# Process "foreign" data using OpenCV (for example, when you implement a DirectShow\* filter or
joeverbout 0:ea44dc9ed014 641 a processing module for gstreamer, and so on). For example:
joeverbout 0:ea44dc9ed014 642 @code
joeverbout 0:ea44dc9ed014 643 void process_video_frame(const unsigned char* pixels,
joeverbout 0:ea44dc9ed014 644 int width, int height, int step)
joeverbout 0:ea44dc9ed014 645 {
joeverbout 0:ea44dc9ed014 646 Mat img(height, width, CV_8UC3, pixels, step);
joeverbout 0:ea44dc9ed014 647 GaussianBlur(img, img, Size(7,7), 1.5, 1.5);
joeverbout 0:ea44dc9ed014 648 }
joeverbout 0:ea44dc9ed014 649 @endcode
joeverbout 0:ea44dc9ed014 650 -# Quickly initialize small matrices and/or get a super-fast element access.
joeverbout 0:ea44dc9ed014 651 @code
joeverbout 0:ea44dc9ed014 652 double m[3][3] = {{a, b, c}, {d, e, f}, {g, h, i}};
joeverbout 0:ea44dc9ed014 653 Mat M = Mat(3, 3, CV_64F, m).inv();
joeverbout 0:ea44dc9ed014 654 @endcode
joeverbout 0:ea44dc9ed014 655 .
joeverbout 0:ea44dc9ed014 656 Partial yet very common cases of this *user-allocated data* case are conversions from CvMat and
joeverbout 0:ea44dc9ed014 657 IplImage to Mat. For this purpose, there is function cv::cvarrToMat taking pointers to CvMat or
joeverbout 0:ea44dc9ed014 658 IplImage and the optional flag indicating whether to copy the data or not.
joeverbout 0:ea44dc9ed014 659 @snippet samples/cpp/image.cpp iplimage
joeverbout 0:ea44dc9ed014 660
joeverbout 0:ea44dc9ed014 661 - Use MATLAB-style array initializers, zeros(), ones(), eye(), for example:
joeverbout 0:ea44dc9ed014 662 @code
joeverbout 0:ea44dc9ed014 663 // create a double-precision identity martix and add it to M.
joeverbout 0:ea44dc9ed014 664 M += Mat::eye(M.rows, M.cols, CV_64F);
joeverbout 0:ea44dc9ed014 665 @endcode
joeverbout 0:ea44dc9ed014 666
joeverbout 0:ea44dc9ed014 667 - Use a comma-separated initializer:
joeverbout 0:ea44dc9ed014 668 @code
joeverbout 0:ea44dc9ed014 669 // create a 3x3 double-precision identity matrix
joeverbout 0:ea44dc9ed014 670 Mat M = (Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
joeverbout 0:ea44dc9ed014 671 @endcode
joeverbout 0:ea44dc9ed014 672 With this approach, you first call a constructor of the Mat class with the proper parameters, and
joeverbout 0:ea44dc9ed014 673 then you just put `<< operator` followed by comma-separated values that can be constants,
joeverbout 0:ea44dc9ed014 674 variables, expressions, and so on. Also, note the extra parentheses required to avoid compilation
joeverbout 0:ea44dc9ed014 675 errors.
joeverbout 0:ea44dc9ed014 676
joeverbout 0:ea44dc9ed014 677 Once the array is created, it is automatically managed via a reference-counting mechanism. If the
joeverbout 0:ea44dc9ed014 678 array header is built on top of user-allocated data, you should handle the data by yourself. The
joeverbout 0:ea44dc9ed014 679 array data is deallocated when no one points to it. If you want to release the data pointed by a
joeverbout 0:ea44dc9ed014 680 array header before the array destructor is called, use Mat::release().
joeverbout 0:ea44dc9ed014 681
joeverbout 0:ea44dc9ed014 682 The next important thing to learn about the array class is element access. This manual already
joeverbout 0:ea44dc9ed014 683 described how to compute an address of each array element. Normally, you are not required to use the
joeverbout 0:ea44dc9ed014 684 formula directly in the code. If you know the array element type (which can be retrieved using the
joeverbout 0:ea44dc9ed014 685 method Mat::type() ), you can access the element \f$M_{ij}\f$ of a 2-dimensional array as:
joeverbout 0:ea44dc9ed014 686 @code
joeverbout 0:ea44dc9ed014 687 M.at<double>(i,j) += 1.f;
joeverbout 0:ea44dc9ed014 688 @endcode
joeverbout 0:ea44dc9ed014 689 assuming that `M` is a double-precision floating-point array. There are several variants of the method
joeverbout 0:ea44dc9ed014 690 at for a different number of dimensions.
joeverbout 0:ea44dc9ed014 691
joeverbout 0:ea44dc9ed014 692 If you need to process a whole row of a 2D array, the most efficient way is to get the pointer to
joeverbout 0:ea44dc9ed014 693 the row first, and then just use the plain C operator [] :
joeverbout 0:ea44dc9ed014 694 @code
joeverbout 0:ea44dc9ed014 695 // compute sum of positive matrix elements
joeverbout 0:ea44dc9ed014 696 // (assuming that M isa double-precision matrix)
joeverbout 0:ea44dc9ed014 697 double sum=0;
joeverbout 0:ea44dc9ed014 698 for(int i = 0; i < M.rows; i++)
joeverbout 0:ea44dc9ed014 699 {
joeverbout 0:ea44dc9ed014 700 const double* Mi = M.ptr<double>(i);
joeverbout 0:ea44dc9ed014 701 for(int j = 0; j < M.cols; j++)
joeverbout 0:ea44dc9ed014 702 sum += std::max(Mi[j], 0.);
joeverbout 0:ea44dc9ed014 703 }
joeverbout 0:ea44dc9ed014 704 @endcode
joeverbout 0:ea44dc9ed014 705 Some operations, like the one above, do not actually depend on the array shape. They just process
joeverbout 0:ea44dc9ed014 706 elements of an array one by one (or elements from multiple arrays that have the same coordinates,
joeverbout 0:ea44dc9ed014 707 for example, array addition). Such operations are called *element-wise*. It makes sense to check
joeverbout 0:ea44dc9ed014 708 whether all the input/output arrays are continuous, namely, have no gaps at the end of each row. If
joeverbout 0:ea44dc9ed014 709 yes, process them as a long single row:
joeverbout 0:ea44dc9ed014 710 @code
joeverbout 0:ea44dc9ed014 711 // compute the sum of positive matrix elements, optimized variant
joeverbout 0:ea44dc9ed014 712 double sum=0;
joeverbout 0:ea44dc9ed014 713 int cols = M.cols, rows = M.rows;
joeverbout 0:ea44dc9ed014 714 if(M.isContinuous())
joeverbout 0:ea44dc9ed014 715 {
joeverbout 0:ea44dc9ed014 716 cols *= rows;
joeverbout 0:ea44dc9ed014 717 rows = 1;
joeverbout 0:ea44dc9ed014 718 }
joeverbout 0:ea44dc9ed014 719 for(int i = 0; i < rows; i++)
joeverbout 0:ea44dc9ed014 720 {
joeverbout 0:ea44dc9ed014 721 const double* Mi = M.ptr<double>(i);
joeverbout 0:ea44dc9ed014 722 for(int j = 0; j < cols; j++)
joeverbout 0:ea44dc9ed014 723 sum += std::max(Mi[j], 0.);
joeverbout 0:ea44dc9ed014 724 }
joeverbout 0:ea44dc9ed014 725 @endcode
joeverbout 0:ea44dc9ed014 726 In case of the continuous matrix, the outer loop body is executed just once. So, the overhead is
joeverbout 0:ea44dc9ed014 727 smaller, which is especially noticeable in case of small matrices.
joeverbout 0:ea44dc9ed014 728
joeverbout 0:ea44dc9ed014 729 Finally, there are STL-style iterators that are smart enough to skip gaps between successive rows:
joeverbout 0:ea44dc9ed014 730 @code
joeverbout 0:ea44dc9ed014 731 // compute sum of positive matrix elements, iterator-based variant
joeverbout 0:ea44dc9ed014 732 double sum=0;
joeverbout 0:ea44dc9ed014 733 MatConstIterator_<double> it = M.begin<double>(), it_end = M.end<double>();
joeverbout 0:ea44dc9ed014 734 for(; it != it_end; ++it)
joeverbout 0:ea44dc9ed014 735 sum += std::max(*it, 0.);
joeverbout 0:ea44dc9ed014 736 @endcode
joeverbout 0:ea44dc9ed014 737 The matrix iterators are random-access iterators, so they can be passed to any STL algorithm,
joeverbout 0:ea44dc9ed014 738 including std::sort().
joeverbout 0:ea44dc9ed014 739 */
joeverbout 0:ea44dc9ed014 740 class CV_EXPORTS Mat
joeverbout 0:ea44dc9ed014 741 {
joeverbout 0:ea44dc9ed014 742 public:
joeverbout 0:ea44dc9ed014 743 /**
joeverbout 0:ea44dc9ed014 744 These are various constructors that form a matrix. As noted in the AutomaticAllocation, often
joeverbout 0:ea44dc9ed014 745 the default constructor is enough, and the proper matrix will be allocated by an OpenCV function.
joeverbout 0:ea44dc9ed014 746 The constructed matrix can further be assigned to another matrix or matrix expression or can be
joeverbout 0:ea44dc9ed014 747 allocated with Mat::create . In the former case, the old content is de-referenced.
joeverbout 0:ea44dc9ed014 748 */
joeverbout 0:ea44dc9ed014 749 Mat();
joeverbout 0:ea44dc9ed014 750
joeverbout 0:ea44dc9ed014 751 /** @overload
joeverbout 0:ea44dc9ed014 752 @param rows Number of rows in a 2D array.
joeverbout 0:ea44dc9ed014 753 @param cols Number of columns in a 2D array.
joeverbout 0:ea44dc9ed014 754 @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
joeverbout 0:ea44dc9ed014 755 CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
joeverbout 0:ea44dc9ed014 756 */
joeverbout 0:ea44dc9ed014 757 Mat(int rows, int cols, int type);
joeverbout 0:ea44dc9ed014 758
joeverbout 0:ea44dc9ed014 759 /** @overload
joeverbout 0:ea44dc9ed014 760 @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the
joeverbout 0:ea44dc9ed014 761 number of columns go in the reverse order.
joeverbout 0:ea44dc9ed014 762 @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
joeverbout 0:ea44dc9ed014 763 CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
joeverbout 0:ea44dc9ed014 764 */
joeverbout 0:ea44dc9ed014 765 Mat(Size size, int type);
joeverbout 0:ea44dc9ed014 766
joeverbout 0:ea44dc9ed014 767 /** @overload
joeverbout 0:ea44dc9ed014 768 @param rows Number of rows in a 2D array.
joeverbout 0:ea44dc9ed014 769 @param cols Number of columns in a 2D array.
joeverbout 0:ea44dc9ed014 770 @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
joeverbout 0:ea44dc9ed014 771 CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
joeverbout 0:ea44dc9ed014 772 @param s An optional value to initialize each matrix element with. To set all the matrix elements to
joeverbout 0:ea44dc9ed014 773 the particular value after the construction, use the assignment operator
joeverbout 0:ea44dc9ed014 774 Mat::operator=(const Scalar& value) .
joeverbout 0:ea44dc9ed014 775 */
joeverbout 0:ea44dc9ed014 776 Mat(int rows, int cols, int type, const Scalar& s);
joeverbout 0:ea44dc9ed014 777
joeverbout 0:ea44dc9ed014 778 /** @overload
joeverbout 0:ea44dc9ed014 779 @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the
joeverbout 0:ea44dc9ed014 780 number of columns go in the reverse order.
joeverbout 0:ea44dc9ed014 781 @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
joeverbout 0:ea44dc9ed014 782 CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
joeverbout 0:ea44dc9ed014 783 @param s An optional value to initialize each matrix element with. To set all the matrix elements to
joeverbout 0:ea44dc9ed014 784 the particular value after the construction, use the assignment operator
joeverbout 0:ea44dc9ed014 785 Mat::operator=(const Scalar& value) .
joeverbout 0:ea44dc9ed014 786 */
joeverbout 0:ea44dc9ed014 787 Mat(Size size, int type, const Scalar& s);
joeverbout 0:ea44dc9ed014 788
joeverbout 0:ea44dc9ed014 789 /** @overload
joeverbout 0:ea44dc9ed014 790 @param ndims Array dimensionality.
joeverbout 0:ea44dc9ed014 791 @param sizes Array of integers specifying an n-dimensional array shape.
joeverbout 0:ea44dc9ed014 792 @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
joeverbout 0:ea44dc9ed014 793 CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
joeverbout 0:ea44dc9ed014 794 */
joeverbout 0:ea44dc9ed014 795 Mat(int ndims, const int* sizes, int type);
joeverbout 0:ea44dc9ed014 796
joeverbout 0:ea44dc9ed014 797 /** @overload
joeverbout 0:ea44dc9ed014 798 @param ndims Array dimensionality.
joeverbout 0:ea44dc9ed014 799 @param sizes Array of integers specifying an n-dimensional array shape.
joeverbout 0:ea44dc9ed014 800 @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
joeverbout 0:ea44dc9ed014 801 CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
joeverbout 0:ea44dc9ed014 802 @param s An optional value to initialize each matrix element with. To set all the matrix elements to
joeverbout 0:ea44dc9ed014 803 the particular value after the construction, use the assignment operator
joeverbout 0:ea44dc9ed014 804 Mat::operator=(const Scalar& value) .
joeverbout 0:ea44dc9ed014 805 */
joeverbout 0:ea44dc9ed014 806 Mat(int ndims, const int* sizes, int type, const Scalar& s);
joeverbout 0:ea44dc9ed014 807
joeverbout 0:ea44dc9ed014 808 /** @overload
joeverbout 0:ea44dc9ed014 809 @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied
joeverbout 0:ea44dc9ed014 810 by these constructors. Instead, the header pointing to m data or its sub-array is constructed and
joeverbout 0:ea44dc9ed014 811 associated with it. The reference counter, if any, is incremented. So, when you modify the matrix
joeverbout 0:ea44dc9ed014 812 formed using such a constructor, you also modify the corresponding elements of m . If you want to
joeverbout 0:ea44dc9ed014 813 have an independent copy of the sub-array, use Mat::clone() .
joeverbout 0:ea44dc9ed014 814 */
joeverbout 0:ea44dc9ed014 815 Mat(const Mat& m);
joeverbout 0:ea44dc9ed014 816
joeverbout 0:ea44dc9ed014 817 /** @overload
joeverbout 0:ea44dc9ed014 818 @param rows Number of rows in a 2D array.
joeverbout 0:ea44dc9ed014 819 @param cols Number of columns in a 2D array.
joeverbout 0:ea44dc9ed014 820 @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
joeverbout 0:ea44dc9ed014 821 CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
joeverbout 0:ea44dc9ed014 822 @param data Pointer to the user data. Matrix constructors that take data and step parameters do not
joeverbout 0:ea44dc9ed014 823 allocate matrix data. Instead, they just initialize the matrix header that points to the specified
joeverbout 0:ea44dc9ed014 824 data, which means that no data is copied. This operation is very efficient and can be used to
joeverbout 0:ea44dc9ed014 825 process external data using OpenCV functions. The external data is not automatically deallocated, so
joeverbout 0:ea44dc9ed014 826 you should take care of it.
joeverbout 0:ea44dc9ed014 827 @param step Number of bytes each matrix row occupies. The value should include the padding bytes at
joeverbout 0:ea44dc9ed014 828 the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed
joeverbout 0:ea44dc9ed014 829 and the actual step is calculated as cols*elemSize(). See Mat::elemSize.
joeverbout 0:ea44dc9ed014 830 */
joeverbout 0:ea44dc9ed014 831 Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP);
joeverbout 0:ea44dc9ed014 832
joeverbout 0:ea44dc9ed014 833 /** @overload
joeverbout 0:ea44dc9ed014 834 @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the
joeverbout 0:ea44dc9ed014 835 number of columns go in the reverse order.
joeverbout 0:ea44dc9ed014 836 @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
joeverbout 0:ea44dc9ed014 837 CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
joeverbout 0:ea44dc9ed014 838 @param data Pointer to the user data. Matrix constructors that take data and step parameters do not
joeverbout 0:ea44dc9ed014 839 allocate matrix data. Instead, they just initialize the matrix header that points to the specified
joeverbout 0:ea44dc9ed014 840 data, which means that no data is copied. This operation is very efficient and can be used to
joeverbout 0:ea44dc9ed014 841 process external data using OpenCV functions. The external data is not automatically deallocated, so
joeverbout 0:ea44dc9ed014 842 you should take care of it.
joeverbout 0:ea44dc9ed014 843 @param step Number of bytes each matrix row occupies. The value should include the padding bytes at
joeverbout 0:ea44dc9ed014 844 the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed
joeverbout 0:ea44dc9ed014 845 and the actual step is calculated as cols*elemSize(). See Mat::elemSize.
joeverbout 0:ea44dc9ed014 846 */
joeverbout 0:ea44dc9ed014 847 Mat(Size size, int type, void* data, size_t step=AUTO_STEP);
joeverbout 0:ea44dc9ed014 848
joeverbout 0:ea44dc9ed014 849 /** @overload
joeverbout 0:ea44dc9ed014 850 @param ndims Array dimensionality.
joeverbout 0:ea44dc9ed014 851 @param sizes Array of integers specifying an n-dimensional array shape.
joeverbout 0:ea44dc9ed014 852 @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
joeverbout 0:ea44dc9ed014 853 CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
joeverbout 0:ea44dc9ed014 854 @param data Pointer to the user data. Matrix constructors that take data and step parameters do not
joeverbout 0:ea44dc9ed014 855 allocate matrix data. Instead, they just initialize the matrix header that points to the specified
joeverbout 0:ea44dc9ed014 856 data, which means that no data is copied. This operation is very efficient and can be used to
joeverbout 0:ea44dc9ed014 857 process external data using OpenCV functions. The external data is not automatically deallocated, so
joeverbout 0:ea44dc9ed014 858 you should take care of it.
joeverbout 0:ea44dc9ed014 859 @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always
joeverbout 0:ea44dc9ed014 860 set to the element size). If not specified, the matrix is assumed to be continuous.
joeverbout 0:ea44dc9ed014 861 */
joeverbout 0:ea44dc9ed014 862 Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0);
joeverbout 0:ea44dc9ed014 863
joeverbout 0:ea44dc9ed014 864 /** @overload
joeverbout 0:ea44dc9ed014 865 @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied
joeverbout 0:ea44dc9ed014 866 by these constructors. Instead, the header pointing to m data or its sub-array is constructed and
joeverbout 0:ea44dc9ed014 867 associated with it. The reference counter, if any, is incremented. So, when you modify the matrix
joeverbout 0:ea44dc9ed014 868 formed using such a constructor, you also modify the corresponding elements of m . If you want to
joeverbout 0:ea44dc9ed014 869 have an independent copy of the sub-array, use Mat::clone() .
joeverbout 0:ea44dc9ed014 870 @param rowRange Range of the m rows to take. As usual, the range start is inclusive and the range
joeverbout 0:ea44dc9ed014 871 end is exclusive. Use Range::all() to take all the rows.
joeverbout 0:ea44dc9ed014 872 @param colRange Range of the m columns to take. Use Range::all() to take all the columns.
joeverbout 0:ea44dc9ed014 873 */
joeverbout 0:ea44dc9ed014 874 Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all());
joeverbout 0:ea44dc9ed014 875
joeverbout 0:ea44dc9ed014 876 /** @overload
joeverbout 0:ea44dc9ed014 877 @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied
joeverbout 0:ea44dc9ed014 878 by these constructors. Instead, the header pointing to m data or its sub-array is constructed and
joeverbout 0:ea44dc9ed014 879 associated with it. The reference counter, if any, is incremented. So, when you modify the matrix
joeverbout 0:ea44dc9ed014 880 formed using such a constructor, you also modify the corresponding elements of m . If you want to
joeverbout 0:ea44dc9ed014 881 have an independent copy of the sub-array, use Mat::clone() .
joeverbout 0:ea44dc9ed014 882 @param roi Region of interest.
joeverbout 0:ea44dc9ed014 883 */
joeverbout 0:ea44dc9ed014 884 Mat(const Mat& m, const Rect& roi);
joeverbout 0:ea44dc9ed014 885
joeverbout 0:ea44dc9ed014 886 /** @overload
joeverbout 0:ea44dc9ed014 887 @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied
joeverbout 0:ea44dc9ed014 888 by these constructors. Instead, the header pointing to m data or its sub-array is constructed and
joeverbout 0:ea44dc9ed014 889 associated with it. The reference counter, if any, is incremented. So, when you modify the matrix
joeverbout 0:ea44dc9ed014 890 formed using such a constructor, you also modify the corresponding elements of m . If you want to
joeverbout 0:ea44dc9ed014 891 have an independent copy of the sub-array, use Mat::clone() .
joeverbout 0:ea44dc9ed014 892 @param ranges Array of selected ranges of m along each dimensionality.
joeverbout 0:ea44dc9ed014 893 */
joeverbout 0:ea44dc9ed014 894 Mat(const Mat& m, const Range* ranges);
joeverbout 0:ea44dc9ed014 895
joeverbout 0:ea44dc9ed014 896 /** @overload
joeverbout 0:ea44dc9ed014 897 @param vec STL vector whose elements form the matrix. The matrix has a single column and the number
joeverbout 0:ea44dc9ed014 898 of rows equal to the number of vector elements. Type of the matrix matches the type of vector
joeverbout 0:ea44dc9ed014 899 elements. The constructor can handle arbitrary types, for which there is a properly declared
joeverbout 0:ea44dc9ed014 900 DataType . This means that the vector elements must be primitive numbers or uni-type numerical
joeverbout 0:ea44dc9ed014 901 tuples of numbers. Mixed-type structures are not supported. The corresponding constructor is
joeverbout 0:ea44dc9ed014 902 explicit. Since STL vectors are not automatically converted to Mat instances, you should write
joeverbout 0:ea44dc9ed014 903 Mat(vec) explicitly. Unless you copy the data into the matrix ( copyData=true ), no new elements
joeverbout 0:ea44dc9ed014 904 will be added to the vector because it can potentially yield vector data reallocation, and, thus,
joeverbout 0:ea44dc9ed014 905 the matrix data pointer will be invalid.
joeverbout 0:ea44dc9ed014 906 @param copyData Flag to specify whether the underlying data of the STL vector should be copied
joeverbout 0:ea44dc9ed014 907 to (true) or shared with (false) the newly constructed matrix. When the data is copied, the
joeverbout 0:ea44dc9ed014 908 allocated buffer is managed using Mat reference counting mechanism. While the data is shared,
joeverbout 0:ea44dc9ed014 909 the reference counter is NULL, and you should not deallocate the data until the matrix is not
joeverbout 0:ea44dc9ed014 910 destructed.
joeverbout 0:ea44dc9ed014 911 */
joeverbout 0:ea44dc9ed014 912 template<typename _Tp> explicit Mat(const std::vector<_Tp>& vec, bool copyData=false);
joeverbout 0:ea44dc9ed014 913
joeverbout 0:ea44dc9ed014 914 /** @overload
joeverbout 0:ea44dc9ed014 915 */
joeverbout 0:ea44dc9ed014 916 template<typename _Tp, int n> explicit Mat(const Vec<_Tp, n>& vec, bool copyData=true);
joeverbout 0:ea44dc9ed014 917
joeverbout 0:ea44dc9ed014 918 /** @overload
joeverbout 0:ea44dc9ed014 919 */
joeverbout 0:ea44dc9ed014 920 template<typename _Tp, int m, int n> explicit Mat(const Matx<_Tp, m, n>& mtx, bool copyData=true);
joeverbout 0:ea44dc9ed014 921
joeverbout 0:ea44dc9ed014 922 /** @overload
joeverbout 0:ea44dc9ed014 923 */
joeverbout 0:ea44dc9ed014 924 template<typename _Tp> explicit Mat(const Point_<_Tp>& pt, bool copyData=true);
joeverbout 0:ea44dc9ed014 925
joeverbout 0:ea44dc9ed014 926 /** @overload
joeverbout 0:ea44dc9ed014 927 */
joeverbout 0:ea44dc9ed014 928 template<typename _Tp> explicit Mat(const Point3_<_Tp>& pt, bool copyData=true);
joeverbout 0:ea44dc9ed014 929
joeverbout 0:ea44dc9ed014 930 /** @overload
joeverbout 0:ea44dc9ed014 931 */
joeverbout 0:ea44dc9ed014 932 template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer);
joeverbout 0:ea44dc9ed014 933
joeverbout 0:ea44dc9ed014 934 //! download data from GpuMat
joeverbout 0:ea44dc9ed014 935 explicit Mat(const cuda::GpuMat& m);
joeverbout 0:ea44dc9ed014 936
joeverbout 0:ea44dc9ed014 937 //! destructor - calls release()
joeverbout 0:ea44dc9ed014 938 ~Mat();
joeverbout 0:ea44dc9ed014 939
joeverbout 0:ea44dc9ed014 940 /** @brief assignment operators
joeverbout 0:ea44dc9ed014 941
joeverbout 0:ea44dc9ed014 942 These are available assignment operators. Since they all are very different, make sure to read the
joeverbout 0:ea44dc9ed014 943 operator parameters description.
joeverbout 0:ea44dc9ed014 944 @param m Assigned, right-hand-side matrix. Matrix assignment is an O(1) operation. This means that
joeverbout 0:ea44dc9ed014 945 no data is copied but the data is shared and the reference counter, if any, is incremented. Before
joeverbout 0:ea44dc9ed014 946 assigning new data, the old data is de-referenced via Mat::release .
joeverbout 0:ea44dc9ed014 947 */
joeverbout 0:ea44dc9ed014 948 Mat& operator = (const Mat& m);
joeverbout 0:ea44dc9ed014 949
joeverbout 0:ea44dc9ed014 950 /** @overload
joeverbout 0:ea44dc9ed014 951 @param expr Assigned matrix expression object. As opposite to the first form of the assignment
joeverbout 0:ea44dc9ed014 952 operation, the second form can reuse already allocated matrix if it has the right size and type to
joeverbout 0:ea44dc9ed014 953 fit the matrix expression result. It is automatically handled by the real function that the matrix
joeverbout 0:ea44dc9ed014 954 expressions is expanded to. For example, C=A+B is expanded to add(A, B, C), and add takes care of
joeverbout 0:ea44dc9ed014 955 automatic C reallocation.
joeverbout 0:ea44dc9ed014 956 */
joeverbout 0:ea44dc9ed014 957 Mat& operator = (const MatExpr& expr);
joeverbout 0:ea44dc9ed014 958
joeverbout 0:ea44dc9ed014 959 //! retrieve UMat from Mat
joeverbout 0:ea44dc9ed014 960 UMat getUMat(int accessFlags, UMatUsageFlags usageFlags = USAGE_DEFAULT) const;
joeverbout 0:ea44dc9ed014 961
joeverbout 0:ea44dc9ed014 962 /** @brief Creates a matrix header for the specified matrix row.
joeverbout 0:ea44dc9ed014 963
joeverbout 0:ea44dc9ed014 964 The method makes a new header for the specified matrix row and returns it. This is an O(1)
joeverbout 0:ea44dc9ed014 965 operation, regardless of the matrix size. The underlying data of the new matrix is shared with the
joeverbout 0:ea44dc9ed014 966 original matrix. Here is the example of one of the classical basic matrix processing operations,
joeverbout 0:ea44dc9ed014 967 axpy, used by LU and many other algorithms:
joeverbout 0:ea44dc9ed014 968 @code
joeverbout 0:ea44dc9ed014 969 inline void matrix_axpy(Mat& A, int i, int j, double alpha)
joeverbout 0:ea44dc9ed014 970 {
joeverbout 0:ea44dc9ed014 971 A.row(i) += A.row(j)*alpha;
joeverbout 0:ea44dc9ed014 972 }
joeverbout 0:ea44dc9ed014 973 @endcode
joeverbout 0:ea44dc9ed014 974 @note In the current implementation, the following code does not work as expected:
joeverbout 0:ea44dc9ed014 975 @code
joeverbout 0:ea44dc9ed014 976 Mat A;
joeverbout 0:ea44dc9ed014 977 ...
joeverbout 0:ea44dc9ed014 978 A.row(i) = A.row(j); // will not work
joeverbout 0:ea44dc9ed014 979 @endcode
joeverbout 0:ea44dc9ed014 980 This happens because A.row(i) forms a temporary header that is further assigned to another header.
joeverbout 0:ea44dc9ed014 981 Remember that each of these operations is O(1), that is, no data is copied. Thus, the above
joeverbout 0:ea44dc9ed014 982 assignment is not true if you may have expected the j-th row to be copied to the i-th row. To
joeverbout 0:ea44dc9ed014 983 achieve that, you should either turn this simple assignment into an expression or use the
joeverbout 0:ea44dc9ed014 984 Mat::copyTo method:
joeverbout 0:ea44dc9ed014 985 @code
joeverbout 0:ea44dc9ed014 986 Mat A;
joeverbout 0:ea44dc9ed014 987 ...
joeverbout 0:ea44dc9ed014 988 // works, but looks a bit obscure.
joeverbout 0:ea44dc9ed014 989 A.row(i) = A.row(j) + 0;
joeverbout 0:ea44dc9ed014 990 // this is a bit longer, but the recommended method.
joeverbout 0:ea44dc9ed014 991 A.row(j).copyTo(A.row(i));
joeverbout 0:ea44dc9ed014 992 @endcode
joeverbout 0:ea44dc9ed014 993 @param y A 0-based row index.
joeverbout 0:ea44dc9ed014 994 */
joeverbout 0:ea44dc9ed014 995 Mat row(int y) const;
joeverbout 0:ea44dc9ed014 996
joeverbout 0:ea44dc9ed014 997 /** @brief Creates a matrix header for the specified matrix column.
joeverbout 0:ea44dc9ed014 998
joeverbout 0:ea44dc9ed014 999 The method makes a new header for the specified matrix column and returns it. This is an O(1)
joeverbout 0:ea44dc9ed014 1000 operation, regardless of the matrix size. The underlying data of the new matrix is shared with the
joeverbout 0:ea44dc9ed014 1001 original matrix. See also the Mat::row description.
joeverbout 0:ea44dc9ed014 1002 @param x A 0-based column index.
joeverbout 0:ea44dc9ed014 1003 */
joeverbout 0:ea44dc9ed014 1004 Mat col(int x) const;
joeverbout 0:ea44dc9ed014 1005
joeverbout 0:ea44dc9ed014 1006 /** @brief Creates a matrix header for the specified row span.
joeverbout 0:ea44dc9ed014 1007
joeverbout 0:ea44dc9ed014 1008 The method makes a new header for the specified row span of the matrix. Similarly to Mat::row and
joeverbout 0:ea44dc9ed014 1009 Mat::col , this is an O(1) operation.
joeverbout 0:ea44dc9ed014 1010 @param startrow An inclusive 0-based start index of the row span.
joeverbout 0:ea44dc9ed014 1011 @param endrow An exclusive 0-based ending index of the row span.
joeverbout 0:ea44dc9ed014 1012 */
joeverbout 0:ea44dc9ed014 1013 Mat rowRange(int startrow, int endrow) const;
joeverbout 0:ea44dc9ed014 1014
joeverbout 0:ea44dc9ed014 1015 /** @overload
joeverbout 0:ea44dc9ed014 1016 @param r Range structure containing both the start and the end indices.
joeverbout 0:ea44dc9ed014 1017 */
joeverbout 0:ea44dc9ed014 1018 Mat rowRange(const Range& r) const;
joeverbout 0:ea44dc9ed014 1019
joeverbout 0:ea44dc9ed014 1020 /** @brief Creates a matrix header for the specified column span.
joeverbout 0:ea44dc9ed014 1021
joeverbout 0:ea44dc9ed014 1022 The method makes a new header for the specified column span of the matrix. Similarly to Mat::row and
joeverbout 0:ea44dc9ed014 1023 Mat::col , this is an O(1) operation.
joeverbout 0:ea44dc9ed014 1024 @param startcol An inclusive 0-based start index of the column span.
joeverbout 0:ea44dc9ed014 1025 @param endcol An exclusive 0-based ending index of the column span.
joeverbout 0:ea44dc9ed014 1026 */
joeverbout 0:ea44dc9ed014 1027 Mat colRange(int startcol, int endcol) const;
joeverbout 0:ea44dc9ed014 1028
joeverbout 0:ea44dc9ed014 1029 /** @overload
joeverbout 0:ea44dc9ed014 1030 @param r Range structure containing both the start and the end indices.
joeverbout 0:ea44dc9ed014 1031 */
joeverbout 0:ea44dc9ed014 1032 Mat colRange(const Range& r) const;
joeverbout 0:ea44dc9ed014 1033
joeverbout 0:ea44dc9ed014 1034 /** @brief Extracts a diagonal from a matrix
joeverbout 0:ea44dc9ed014 1035
joeverbout 0:ea44dc9ed014 1036 The method makes a new header for the specified matrix diagonal. The new matrix is represented as a
joeverbout 0:ea44dc9ed014 1037 single-column matrix. Similarly to Mat::row and Mat::col, this is an O(1) operation.
joeverbout 0:ea44dc9ed014 1038 @param d index of the diagonal, with the following values:
joeverbout 0:ea44dc9ed014 1039 - `d=0` is the main diagonal.
joeverbout 0:ea44dc9ed014 1040 - `d>0` is a diagonal from the lower half. For example, d=1 means the diagonal is set
joeverbout 0:ea44dc9ed014 1041 immediately below the main one.
joeverbout 0:ea44dc9ed014 1042 - `d<0` is a diagonal from the upper half. For example, d=-1 means the diagonal is set
joeverbout 0:ea44dc9ed014 1043 immediately above the main one.
joeverbout 0:ea44dc9ed014 1044 */
joeverbout 0:ea44dc9ed014 1045 Mat diag(int d=0) const;
joeverbout 0:ea44dc9ed014 1046
joeverbout 0:ea44dc9ed014 1047 /** @brief creates a diagonal matrix
joeverbout 0:ea44dc9ed014 1048
joeverbout 0:ea44dc9ed014 1049 The method makes a new header for the specified matrix diagonal. The new matrix is represented as a
joeverbout 0:ea44dc9ed014 1050 single-column matrix. Similarly to Mat::row and Mat::col, this is an O(1) operation.
joeverbout 0:ea44dc9ed014 1051 @param d Single-column matrix that forms a diagonal matrix
joeverbout 0:ea44dc9ed014 1052 */
joeverbout 0:ea44dc9ed014 1053 static Mat diag(const Mat& d);
joeverbout 0:ea44dc9ed014 1054
joeverbout 0:ea44dc9ed014 1055 /** @brief Creates a full copy of the array and the underlying data.
joeverbout 0:ea44dc9ed014 1056
joeverbout 0:ea44dc9ed014 1057 The method creates a full copy of the array. The original step[] is not taken into account. So, the
joeverbout 0:ea44dc9ed014 1058 array copy is a continuous array occupying total()*elemSize() bytes.
joeverbout 0:ea44dc9ed014 1059 */
joeverbout 0:ea44dc9ed014 1060 Mat clone() const;
joeverbout 0:ea44dc9ed014 1061
joeverbout 0:ea44dc9ed014 1062 /** @brief Copies the matrix to another one.
joeverbout 0:ea44dc9ed014 1063
joeverbout 0:ea44dc9ed014 1064 The method copies the matrix data to another matrix. Before copying the data, the method invokes :
joeverbout 0:ea44dc9ed014 1065 @code
joeverbout 0:ea44dc9ed014 1066 m.create(this->size(), this->type());
joeverbout 0:ea44dc9ed014 1067 @endcode
joeverbout 0:ea44dc9ed014 1068 so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the
joeverbout 0:ea44dc9ed014 1069 function does not handle the case of a partial overlap between the source and the destination
joeverbout 0:ea44dc9ed014 1070 matrices.
joeverbout 0:ea44dc9ed014 1071
joeverbout 0:ea44dc9ed014 1072 When the operation mask is specified, if the Mat::create call shown above reallocates the matrix,
joeverbout 0:ea44dc9ed014 1073 the newly allocated matrix is initialized with all zeros before copying the data.
joeverbout 0:ea44dc9ed014 1074 @param m Destination matrix. If it does not have a proper size or type before the operation, it is
joeverbout 0:ea44dc9ed014 1075 reallocated.
joeverbout 0:ea44dc9ed014 1076 */
joeverbout 0:ea44dc9ed014 1077 void copyTo( OutputArray m ) const;
joeverbout 0:ea44dc9ed014 1078
joeverbout 0:ea44dc9ed014 1079 /** @overload
joeverbout 0:ea44dc9ed014 1080 @param m Destination matrix. If it does not have a proper size or type before the operation, it is
joeverbout 0:ea44dc9ed014 1081 reallocated.
joeverbout 0:ea44dc9ed014 1082 @param mask Operation mask. Its non-zero elements indicate which matrix elements need to be copied.
joeverbout 0:ea44dc9ed014 1083 The mask has to be of type CV_8U and can have 1 or multiple channels.
joeverbout 0:ea44dc9ed014 1084 */
joeverbout 0:ea44dc9ed014 1085 void copyTo( OutputArray m, InputArray mask ) const;
joeverbout 0:ea44dc9ed014 1086
joeverbout 0:ea44dc9ed014 1087 /** @brief Converts an array to another data type with optional scaling.
joeverbout 0:ea44dc9ed014 1088
joeverbout 0:ea44dc9ed014 1089 The method converts source pixel values to the target data type. saturate_cast\<\> is applied at
joeverbout 0:ea44dc9ed014 1090 the end to avoid possible overflows:
joeverbout 0:ea44dc9ed014 1091
joeverbout 0:ea44dc9ed014 1092 \f[m(x,y) = saturate \_ cast<rType>( \alpha (*this)(x,y) + \beta )\f]
joeverbout 0:ea44dc9ed014 1093 @param m output matrix; if it does not have a proper size or type before the operation, it is
joeverbout 0:ea44dc9ed014 1094 reallocated.
joeverbout 0:ea44dc9ed014 1095 @param rtype desired output matrix type or, rather, the depth since the number of channels are the
joeverbout 0:ea44dc9ed014 1096 same as the input has; if rtype is negative, the output matrix will have the same type as the input.
joeverbout 0:ea44dc9ed014 1097 @param alpha optional scale factor.
joeverbout 0:ea44dc9ed014 1098 @param beta optional delta added to the scaled values.
joeverbout 0:ea44dc9ed014 1099 */
joeverbout 0:ea44dc9ed014 1100 void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const;
joeverbout 0:ea44dc9ed014 1101
joeverbout 0:ea44dc9ed014 1102 /** @brief Provides a functional form of convertTo.
joeverbout 0:ea44dc9ed014 1103
joeverbout 0:ea44dc9ed014 1104 This is an internally used method called by the @ref MatrixExpressions engine.
joeverbout 0:ea44dc9ed014 1105 @param m Destination array.
joeverbout 0:ea44dc9ed014 1106 @param type Desired destination array depth (or -1 if it should be the same as the source type).
joeverbout 0:ea44dc9ed014 1107 */
joeverbout 0:ea44dc9ed014 1108 void assignTo( Mat& m, int type=-1 ) const;
joeverbout 0:ea44dc9ed014 1109
joeverbout 0:ea44dc9ed014 1110 /** @brief Sets all or some of the array elements to the specified value.
joeverbout 0:ea44dc9ed014 1111 @param s Assigned scalar converted to the actual array type.
joeverbout 0:ea44dc9ed014 1112 */
joeverbout 0:ea44dc9ed014 1113 Mat& operator = (const Scalar& s);
joeverbout 0:ea44dc9ed014 1114
joeverbout 0:ea44dc9ed014 1115 /** @brief Sets all or some of the array elements to the specified value.
joeverbout 0:ea44dc9ed014 1116
joeverbout 0:ea44dc9ed014 1117 This is an advanced variant of the Mat::operator=(const Scalar& s) operator.
joeverbout 0:ea44dc9ed014 1118 @param value Assigned scalar converted to the actual array type.
joeverbout 0:ea44dc9ed014 1119 @param mask Operation mask of the same size as \*this.
joeverbout 0:ea44dc9ed014 1120 */
joeverbout 0:ea44dc9ed014 1121 Mat& setTo(InputArray value, InputArray mask=noArray());
joeverbout 0:ea44dc9ed014 1122
joeverbout 0:ea44dc9ed014 1123 /** @brief Changes the shape and/or the number of channels of a 2D matrix without copying the data.
joeverbout 0:ea44dc9ed014 1124
joeverbout 0:ea44dc9ed014 1125 The method makes a new matrix header for \*this elements. The new matrix may have a different size
joeverbout 0:ea44dc9ed014 1126 and/or different number of channels. Any combination is possible if:
joeverbout 0:ea44dc9ed014 1127 - No extra elements are included into the new matrix and no elements are excluded. Consequently,
joeverbout 0:ea44dc9ed014 1128 the product rows\*cols\*channels() must stay the same after the transformation.
joeverbout 0:ea44dc9ed014 1129 - No data is copied. That is, this is an O(1) operation. Consequently, if you change the number of
joeverbout 0:ea44dc9ed014 1130 rows, or the operation changes the indices of elements row in some other way, the matrix must be
joeverbout 0:ea44dc9ed014 1131 continuous. See Mat::isContinuous .
joeverbout 0:ea44dc9ed014 1132
joeverbout 0:ea44dc9ed014 1133 For example, if there is a set of 3D points stored as an STL vector, and you want to represent the
joeverbout 0:ea44dc9ed014 1134 points as a 3xN matrix, do the following:
joeverbout 0:ea44dc9ed014 1135 @code
joeverbout 0:ea44dc9ed014 1136 std::vector<Point3f> vec;
joeverbout 0:ea44dc9ed014 1137 ...
joeverbout 0:ea44dc9ed014 1138 Mat pointMat = Mat(vec). // convert vector to Mat, O(1) operation
joeverbout 0:ea44dc9ed014 1139 reshape(1). // make Nx3 1-channel matrix out of Nx1 3-channel.
joeverbout 0:ea44dc9ed014 1140 // Also, an O(1) operation
joeverbout 0:ea44dc9ed014 1141 t(); // finally, transpose the Nx3 matrix.
joeverbout 0:ea44dc9ed014 1142 // This involves copying all the elements
joeverbout 0:ea44dc9ed014 1143 @endcode
joeverbout 0:ea44dc9ed014 1144 @param cn New number of channels. If the parameter is 0, the number of channels remains the same.
joeverbout 0:ea44dc9ed014 1145 @param rows New number of rows. If the parameter is 0, the number of rows remains the same.
joeverbout 0:ea44dc9ed014 1146 */
joeverbout 0:ea44dc9ed014 1147 Mat reshape(int cn, int rows=0) const;
joeverbout 0:ea44dc9ed014 1148
joeverbout 0:ea44dc9ed014 1149 /** @overload */
joeverbout 0:ea44dc9ed014 1150 Mat reshape(int cn, int newndims, const int* newsz) const;
joeverbout 0:ea44dc9ed014 1151
joeverbout 0:ea44dc9ed014 1152 /** @brief Transposes a matrix.
joeverbout 0:ea44dc9ed014 1153
joeverbout 0:ea44dc9ed014 1154 The method performs matrix transposition by means of matrix expressions. It does not perform the
joeverbout 0:ea44dc9ed014 1155 actual transposition but returns a temporary matrix transposition object that can be further used as
joeverbout 0:ea44dc9ed014 1156 a part of more complex matrix expressions or can be assigned to a matrix:
joeverbout 0:ea44dc9ed014 1157 @code
joeverbout 0:ea44dc9ed014 1158 Mat A1 = A + Mat::eye(A.size(), A.type())*lambda;
joeverbout 0:ea44dc9ed014 1159 Mat C = A1.t()*A1; // compute (A + lambda*I)^t * (A + lamda*I)
joeverbout 0:ea44dc9ed014 1160 @endcode
joeverbout 0:ea44dc9ed014 1161 */
joeverbout 0:ea44dc9ed014 1162 MatExpr t() const;
joeverbout 0:ea44dc9ed014 1163
joeverbout 0:ea44dc9ed014 1164 /** @brief Inverses a matrix.
joeverbout 0:ea44dc9ed014 1165
joeverbout 0:ea44dc9ed014 1166 The method performs a matrix inversion by means of matrix expressions. This means that a temporary
joeverbout 0:ea44dc9ed014 1167 matrix inversion object is returned by the method and can be used further as a part of more complex
joeverbout 0:ea44dc9ed014 1168 matrix expressions or can be assigned to a matrix.
joeverbout 0:ea44dc9ed014 1169 @param method Matrix inversion method. One of cv::DecompTypes
joeverbout 0:ea44dc9ed014 1170 */
joeverbout 0:ea44dc9ed014 1171 MatExpr inv(int method=DECOMP_LU) const;
joeverbout 0:ea44dc9ed014 1172
joeverbout 0:ea44dc9ed014 1173 /** @brief Performs an element-wise multiplication or division of the two matrices.
joeverbout 0:ea44dc9ed014 1174
joeverbout 0:ea44dc9ed014 1175 The method returns a temporary object encoding per-element array multiplication, with optional
joeverbout 0:ea44dc9ed014 1176 scale. Note that this is not a matrix multiplication that corresponds to a simpler "\*" operator.
joeverbout 0:ea44dc9ed014 1177
joeverbout 0:ea44dc9ed014 1178 Example:
joeverbout 0:ea44dc9ed014 1179 @code
joeverbout 0:ea44dc9ed014 1180 Mat C = A.mul(5/B); // equivalent to divide(A, B, C, 5)
joeverbout 0:ea44dc9ed014 1181 @endcode
joeverbout 0:ea44dc9ed014 1182 @param m Another array of the same type and the same size as \*this, or a matrix expression.
joeverbout 0:ea44dc9ed014 1183 @param scale Optional scale factor.
joeverbout 0:ea44dc9ed014 1184 */
joeverbout 0:ea44dc9ed014 1185 MatExpr mul(InputArray m, double scale=1) const;
joeverbout 0:ea44dc9ed014 1186
joeverbout 0:ea44dc9ed014 1187 /** @brief Computes a cross-product of two 3-element vectors.
joeverbout 0:ea44dc9ed014 1188
joeverbout 0:ea44dc9ed014 1189 The method computes a cross-product of two 3-element vectors. The vectors must be 3-element
joeverbout 0:ea44dc9ed014 1190 floating-point vectors of the same shape and size. The result is another 3-element vector of the
joeverbout 0:ea44dc9ed014 1191 same shape and type as operands.
joeverbout 0:ea44dc9ed014 1192 @param m Another cross-product operand.
joeverbout 0:ea44dc9ed014 1193 */
joeverbout 0:ea44dc9ed014 1194 Mat cross(InputArray m) const;
joeverbout 0:ea44dc9ed014 1195
joeverbout 0:ea44dc9ed014 1196 /** @brief Computes a dot-product of two vectors.
joeverbout 0:ea44dc9ed014 1197
joeverbout 0:ea44dc9ed014 1198 The method computes a dot-product of two matrices. If the matrices are not single-column or
joeverbout 0:ea44dc9ed014 1199 single-row vectors, the top-to-bottom left-to-right scan ordering is used to treat them as 1D
joeverbout 0:ea44dc9ed014 1200 vectors. The vectors must have the same size and type. If the matrices have more than one channel,
joeverbout 0:ea44dc9ed014 1201 the dot products from all the channels are summed together.
joeverbout 0:ea44dc9ed014 1202 @param m another dot-product operand.
joeverbout 0:ea44dc9ed014 1203 */
joeverbout 0:ea44dc9ed014 1204 double dot(InputArray m) const;
joeverbout 0:ea44dc9ed014 1205
joeverbout 0:ea44dc9ed014 1206 /** @brief Returns a zero array of the specified size and type.
joeverbout 0:ea44dc9ed014 1207
joeverbout 0:ea44dc9ed014 1208 The method returns a Matlab-style zero array initializer. It can be used to quickly form a constant
joeverbout 0:ea44dc9ed014 1209 array as a function parameter, part of a matrix expression, or as a matrix initializer. :
joeverbout 0:ea44dc9ed014 1210 @code
joeverbout 0:ea44dc9ed014 1211 Mat A;
joeverbout 0:ea44dc9ed014 1212 A = Mat::zeros(3, 3, CV_32F);
joeverbout 0:ea44dc9ed014 1213 @endcode
joeverbout 0:ea44dc9ed014 1214 In the example above, a new matrix is allocated only if A is not a 3x3 floating-point matrix.
joeverbout 0:ea44dc9ed014 1215 Otherwise, the existing matrix A is filled with zeros.
joeverbout 0:ea44dc9ed014 1216 @param rows Number of rows.
joeverbout 0:ea44dc9ed014 1217 @param cols Number of columns.
joeverbout 0:ea44dc9ed014 1218 @param type Created matrix type.
joeverbout 0:ea44dc9ed014 1219 */
joeverbout 0:ea44dc9ed014 1220 static MatExpr zeros(int rows, int cols, int type);
joeverbout 0:ea44dc9ed014 1221
joeverbout 0:ea44dc9ed014 1222 /** @overload
joeverbout 0:ea44dc9ed014 1223 @param size Alternative to the matrix size specification Size(cols, rows) .
joeverbout 0:ea44dc9ed014 1224 @param type Created matrix type.
joeverbout 0:ea44dc9ed014 1225 */
joeverbout 0:ea44dc9ed014 1226 static MatExpr zeros(Size size, int type);
joeverbout 0:ea44dc9ed014 1227
joeverbout 0:ea44dc9ed014 1228 /** @overload
joeverbout 0:ea44dc9ed014 1229 @param ndims Array dimensionality.
joeverbout 0:ea44dc9ed014 1230 @param sz Array of integers specifying the array shape.
joeverbout 0:ea44dc9ed014 1231 @param type Created matrix type.
joeverbout 0:ea44dc9ed014 1232 */
joeverbout 0:ea44dc9ed014 1233 static MatExpr zeros(int ndims, const int* sz, int type);
joeverbout 0:ea44dc9ed014 1234
joeverbout 0:ea44dc9ed014 1235 /** @brief Returns an array of all 1's of the specified size and type.
joeverbout 0:ea44dc9ed014 1236
joeverbout 0:ea44dc9ed014 1237 The method returns a Matlab-style 1's array initializer, similarly to Mat::zeros. Note that using
joeverbout 0:ea44dc9ed014 1238 this method you can initialize an array with an arbitrary value, using the following Matlab idiom:
joeverbout 0:ea44dc9ed014 1239 @code
joeverbout 0:ea44dc9ed014 1240 Mat A = Mat::ones(100, 100, CV_8U)*3; // make 100x100 matrix filled with 3.
joeverbout 0:ea44dc9ed014 1241 @endcode
joeverbout 0:ea44dc9ed014 1242 The above operation does not form a 100x100 matrix of 1's and then multiply it by 3. Instead, it
joeverbout 0:ea44dc9ed014 1243 just remembers the scale factor (3 in this case) and use it when actually invoking the matrix
joeverbout 0:ea44dc9ed014 1244 initializer.
joeverbout 0:ea44dc9ed014 1245 @param rows Number of rows.
joeverbout 0:ea44dc9ed014 1246 @param cols Number of columns.
joeverbout 0:ea44dc9ed014 1247 @param type Created matrix type.
joeverbout 0:ea44dc9ed014 1248 */
joeverbout 0:ea44dc9ed014 1249 static MatExpr ones(int rows, int cols, int type);
joeverbout 0:ea44dc9ed014 1250
joeverbout 0:ea44dc9ed014 1251 /** @overload
joeverbout 0:ea44dc9ed014 1252 @param size Alternative to the matrix size specification Size(cols, rows) .
joeverbout 0:ea44dc9ed014 1253 @param type Created matrix type.
joeverbout 0:ea44dc9ed014 1254 */
joeverbout 0:ea44dc9ed014 1255 static MatExpr ones(Size size, int type);
joeverbout 0:ea44dc9ed014 1256
joeverbout 0:ea44dc9ed014 1257 /** @overload
joeverbout 0:ea44dc9ed014 1258 @param ndims Array dimensionality.
joeverbout 0:ea44dc9ed014 1259 @param sz Array of integers specifying the array shape.
joeverbout 0:ea44dc9ed014 1260 @param type Created matrix type.
joeverbout 0:ea44dc9ed014 1261 */
joeverbout 0:ea44dc9ed014 1262 static MatExpr ones(int ndims, const int* sz, int type);
joeverbout 0:ea44dc9ed014 1263
joeverbout 0:ea44dc9ed014 1264 /** @brief Returns an identity matrix of the specified size and type.
joeverbout 0:ea44dc9ed014 1265
joeverbout 0:ea44dc9ed014 1266 The method returns a Matlab-style identity matrix initializer, similarly to Mat::zeros. Similarly to
joeverbout 0:ea44dc9ed014 1267 Mat::ones, you can use a scale operation to create a scaled identity matrix efficiently:
joeverbout 0:ea44dc9ed014 1268 @code
joeverbout 0:ea44dc9ed014 1269 // make a 4x4 diagonal matrix with 0.1's on the diagonal.
joeverbout 0:ea44dc9ed014 1270 Mat A = Mat::eye(4, 4, CV_32F)*0.1;
joeverbout 0:ea44dc9ed014 1271 @endcode
joeverbout 0:ea44dc9ed014 1272 @param rows Number of rows.
joeverbout 0:ea44dc9ed014 1273 @param cols Number of columns.
joeverbout 0:ea44dc9ed014 1274 @param type Created matrix type.
joeverbout 0:ea44dc9ed014 1275 */
joeverbout 0:ea44dc9ed014 1276 static MatExpr eye(int rows, int cols, int type);
joeverbout 0:ea44dc9ed014 1277
joeverbout 0:ea44dc9ed014 1278 /** @overload
joeverbout 0:ea44dc9ed014 1279 @param size Alternative matrix size specification as Size(cols, rows) .
joeverbout 0:ea44dc9ed014 1280 @param type Created matrix type.
joeverbout 0:ea44dc9ed014 1281 */
joeverbout 0:ea44dc9ed014 1282 static MatExpr eye(Size size, int type);
joeverbout 0:ea44dc9ed014 1283
joeverbout 0:ea44dc9ed014 1284 /** @brief Allocates new array data if needed.
joeverbout 0:ea44dc9ed014 1285
joeverbout 0:ea44dc9ed014 1286 This is one of the key Mat methods. Most new-style OpenCV functions and methods that produce arrays
joeverbout 0:ea44dc9ed014 1287 call this method for each output array. The method uses the following algorithm:
joeverbout 0:ea44dc9ed014 1288
joeverbout 0:ea44dc9ed014 1289 -# If the current array shape and the type match the new ones, return immediately. Otherwise,
joeverbout 0:ea44dc9ed014 1290 de-reference the previous data by calling Mat::release.
joeverbout 0:ea44dc9ed014 1291 -# Initialize the new header.
joeverbout 0:ea44dc9ed014 1292 -# Allocate the new data of total()\*elemSize() bytes.
joeverbout 0:ea44dc9ed014 1293 -# Allocate the new, associated with the data, reference counter and set it to 1.
joeverbout 0:ea44dc9ed014 1294
joeverbout 0:ea44dc9ed014 1295 Such a scheme makes the memory management robust and efficient at the same time and helps avoid
joeverbout 0:ea44dc9ed014 1296 extra typing for you. This means that usually there is no need to explicitly allocate output arrays.
joeverbout 0:ea44dc9ed014 1297 That is, instead of writing:
joeverbout 0:ea44dc9ed014 1298 @code
joeverbout 0:ea44dc9ed014 1299 Mat color;
joeverbout 0:ea44dc9ed014 1300 ...
joeverbout 0:ea44dc9ed014 1301 Mat gray(color.rows, color.cols, color.depth());
joeverbout 0:ea44dc9ed014 1302 cvtColor(color, gray, COLOR_BGR2GRAY);
joeverbout 0:ea44dc9ed014 1303 @endcode
joeverbout 0:ea44dc9ed014 1304 you can simply write:
joeverbout 0:ea44dc9ed014 1305 @code
joeverbout 0:ea44dc9ed014 1306 Mat color;
joeverbout 0:ea44dc9ed014 1307 ...
joeverbout 0:ea44dc9ed014 1308 Mat gray;
joeverbout 0:ea44dc9ed014 1309 cvtColor(color, gray, COLOR_BGR2GRAY);
joeverbout 0:ea44dc9ed014 1310 @endcode
joeverbout 0:ea44dc9ed014 1311 because cvtColor, as well as the most of OpenCV functions, calls Mat::create() for the output array
joeverbout 0:ea44dc9ed014 1312 internally.
joeverbout 0:ea44dc9ed014 1313 @param rows New number of rows.
joeverbout 0:ea44dc9ed014 1314 @param cols New number of columns.
joeverbout 0:ea44dc9ed014 1315 @param type New matrix type.
joeverbout 0:ea44dc9ed014 1316 */
joeverbout 0:ea44dc9ed014 1317 void create(int rows, int cols, int type);
joeverbout 0:ea44dc9ed014 1318
joeverbout 0:ea44dc9ed014 1319 /** @overload
joeverbout 0:ea44dc9ed014 1320 @param size Alternative new matrix size specification: Size(cols, rows)
joeverbout 0:ea44dc9ed014 1321 @param type New matrix type.
joeverbout 0:ea44dc9ed014 1322 */
joeverbout 0:ea44dc9ed014 1323 void create(Size size, int type);
joeverbout 0:ea44dc9ed014 1324
joeverbout 0:ea44dc9ed014 1325 /** @overload
joeverbout 0:ea44dc9ed014 1326 @param ndims New array dimensionality.
joeverbout 0:ea44dc9ed014 1327 @param sizes Array of integers specifying a new array shape.
joeverbout 0:ea44dc9ed014 1328 @param type New matrix type.
joeverbout 0:ea44dc9ed014 1329 */
joeverbout 0:ea44dc9ed014 1330 void create(int ndims, const int* sizes, int type);
joeverbout 0:ea44dc9ed014 1331
joeverbout 0:ea44dc9ed014 1332 /** @brief Increments the reference counter.
joeverbout 0:ea44dc9ed014 1333
joeverbout 0:ea44dc9ed014 1334 The method increments the reference counter associated with the matrix data. If the matrix header
joeverbout 0:ea44dc9ed014 1335 points to an external data set (see Mat::Mat ), the reference counter is NULL, and the method has no
joeverbout 0:ea44dc9ed014 1336 effect in this case. Normally, to avoid memory leaks, the method should not be called explicitly. It
joeverbout 0:ea44dc9ed014 1337 is called implicitly by the matrix assignment operator. The reference counter increment is an atomic
joeverbout 0:ea44dc9ed014 1338 operation on the platforms that support it. Thus, it is safe to operate on the same matrices
joeverbout 0:ea44dc9ed014 1339 asynchronously in different threads.
joeverbout 0:ea44dc9ed014 1340 */
joeverbout 0:ea44dc9ed014 1341 void addref();
joeverbout 0:ea44dc9ed014 1342
joeverbout 0:ea44dc9ed014 1343 /** @brief Decrements the reference counter and deallocates the matrix if needed.
joeverbout 0:ea44dc9ed014 1344
joeverbout 0:ea44dc9ed014 1345 The method decrements the reference counter associated with the matrix data. When the reference
joeverbout 0:ea44dc9ed014 1346 counter reaches 0, the matrix data is deallocated and the data and the reference counter pointers
joeverbout 0:ea44dc9ed014 1347 are set to NULL's. If the matrix header points to an external data set (see Mat::Mat ), the
joeverbout 0:ea44dc9ed014 1348 reference counter is NULL, and the method has no effect in this case.
joeverbout 0:ea44dc9ed014 1349
joeverbout 0:ea44dc9ed014 1350 This method can be called manually to force the matrix data deallocation. But since this method is
joeverbout 0:ea44dc9ed014 1351 automatically called in the destructor, or by any other method that changes the data pointer, it is
joeverbout 0:ea44dc9ed014 1352 usually not needed. The reference counter decrement and check for 0 is an atomic operation on the
joeverbout 0:ea44dc9ed014 1353 platforms that support it. Thus, it is safe to operate on the same matrices asynchronously in
joeverbout 0:ea44dc9ed014 1354 different threads.
joeverbout 0:ea44dc9ed014 1355 */
joeverbout 0:ea44dc9ed014 1356 void release();
joeverbout 0:ea44dc9ed014 1357
joeverbout 0:ea44dc9ed014 1358 //! deallocates the matrix data
joeverbout 0:ea44dc9ed014 1359 void deallocate();
joeverbout 0:ea44dc9ed014 1360 //! internal use function; properly re-allocates _size, _step arrays
joeverbout 0:ea44dc9ed014 1361 void copySize(const Mat& m);
joeverbout 0:ea44dc9ed014 1362
joeverbout 0:ea44dc9ed014 1363 /** @brief Reserves space for the certain number of rows.
joeverbout 0:ea44dc9ed014 1364
joeverbout 0:ea44dc9ed014 1365 The method reserves space for sz rows. If the matrix already has enough space to store sz rows,
joeverbout 0:ea44dc9ed014 1366 nothing happens. If the matrix is reallocated, the first Mat::rows rows are preserved. The method
joeverbout 0:ea44dc9ed014 1367 emulates the corresponding method of the STL vector class.
joeverbout 0:ea44dc9ed014 1368 @param sz Number of rows.
joeverbout 0:ea44dc9ed014 1369 */
joeverbout 0:ea44dc9ed014 1370 void reserve(size_t sz);
joeverbout 0:ea44dc9ed014 1371
joeverbout 0:ea44dc9ed014 1372 /** @brief Changes the number of matrix rows.
joeverbout 0:ea44dc9ed014 1373
joeverbout 0:ea44dc9ed014 1374 The methods change the number of matrix rows. If the matrix is reallocated, the first
joeverbout 0:ea44dc9ed014 1375 min(Mat::rows, sz) rows are preserved. The methods emulate the corresponding methods of the STL
joeverbout 0:ea44dc9ed014 1376 vector class.
joeverbout 0:ea44dc9ed014 1377 @param sz New number of rows.
joeverbout 0:ea44dc9ed014 1378 */
joeverbout 0:ea44dc9ed014 1379 void resize(size_t sz);
joeverbout 0:ea44dc9ed014 1380
joeverbout 0:ea44dc9ed014 1381 /** @overload
joeverbout 0:ea44dc9ed014 1382 @param sz New number of rows.
joeverbout 0:ea44dc9ed014 1383 @param s Value assigned to the newly added elements.
joeverbout 0:ea44dc9ed014 1384 */
joeverbout 0:ea44dc9ed014 1385 void resize(size_t sz, const Scalar& s);
joeverbout 0:ea44dc9ed014 1386
joeverbout 0:ea44dc9ed014 1387 //! internal function
joeverbout 0:ea44dc9ed014 1388 void push_back_(const void* elem);
joeverbout 0:ea44dc9ed014 1389
joeverbout 0:ea44dc9ed014 1390 /** @brief Adds elements to the bottom of the matrix.
joeverbout 0:ea44dc9ed014 1391
joeverbout 0:ea44dc9ed014 1392 The methods add one or more elements to the bottom of the matrix. They emulate the corresponding
joeverbout 0:ea44dc9ed014 1393 method of the STL vector class. When elem is Mat , its type and the number of columns must be the
joeverbout 0:ea44dc9ed014 1394 same as in the container matrix.
joeverbout 0:ea44dc9ed014 1395 @param elem Added element(s).
joeverbout 0:ea44dc9ed014 1396 */
joeverbout 0:ea44dc9ed014 1397 template<typename _Tp> void push_back(const _Tp& elem);
joeverbout 0:ea44dc9ed014 1398
joeverbout 0:ea44dc9ed014 1399 /** @overload
joeverbout 0:ea44dc9ed014 1400 @param elem Added element(s).
joeverbout 0:ea44dc9ed014 1401 */
joeverbout 0:ea44dc9ed014 1402 template<typename _Tp> void push_back(const Mat_<_Tp>& elem);
joeverbout 0:ea44dc9ed014 1403
joeverbout 0:ea44dc9ed014 1404 /** @overload
joeverbout 0:ea44dc9ed014 1405 @param m Added line(s).
joeverbout 0:ea44dc9ed014 1406 */
joeverbout 0:ea44dc9ed014 1407 void push_back(const Mat& m);
joeverbout 0:ea44dc9ed014 1408
joeverbout 0:ea44dc9ed014 1409 /** @brief Removes elements from the bottom of the matrix.
joeverbout 0:ea44dc9ed014 1410
joeverbout 0:ea44dc9ed014 1411 The method removes one or more rows from the bottom of the matrix.
joeverbout 0:ea44dc9ed014 1412 @param nelems Number of removed rows. If it is greater than the total number of rows, an exception
joeverbout 0:ea44dc9ed014 1413 is thrown.
joeverbout 0:ea44dc9ed014 1414 */
joeverbout 0:ea44dc9ed014 1415 void pop_back(size_t nelems=1);
joeverbout 0:ea44dc9ed014 1416
joeverbout 0:ea44dc9ed014 1417 /** @brief Locates the matrix header within a parent matrix.
joeverbout 0:ea44dc9ed014 1418
joeverbout 0:ea44dc9ed014 1419 After you extracted a submatrix from a matrix using Mat::row, Mat::col, Mat::rowRange,
joeverbout 0:ea44dc9ed014 1420 Mat::colRange, and others, the resultant submatrix points just to the part of the original big
joeverbout 0:ea44dc9ed014 1421 matrix. However, each submatrix contains information (represented by datastart and dataend
joeverbout 0:ea44dc9ed014 1422 fields) that helps reconstruct the original matrix size and the position of the extracted
joeverbout 0:ea44dc9ed014 1423 submatrix within the original matrix. The method locateROI does exactly that.
joeverbout 0:ea44dc9ed014 1424 @param wholeSize Output parameter that contains the size of the whole matrix containing *this*
joeverbout 0:ea44dc9ed014 1425 as a part.
joeverbout 0:ea44dc9ed014 1426 @param ofs Output parameter that contains an offset of *this* inside the whole matrix.
joeverbout 0:ea44dc9ed014 1427 */
joeverbout 0:ea44dc9ed014 1428 void locateROI( Size& wholeSize, Point& ofs ) const;
joeverbout 0:ea44dc9ed014 1429
joeverbout 0:ea44dc9ed014 1430 /** @brief Adjusts a submatrix size and position within the parent matrix.
joeverbout 0:ea44dc9ed014 1431
joeverbout 0:ea44dc9ed014 1432 The method is complimentary to Mat::locateROI . The typical use of these functions is to determine
joeverbout 0:ea44dc9ed014 1433 the submatrix position within the parent matrix and then shift the position somehow. Typically, it
joeverbout 0:ea44dc9ed014 1434 can be required for filtering operations when pixels outside of the ROI should be taken into
joeverbout 0:ea44dc9ed014 1435 account. When all the method parameters are positive, the ROI needs to grow in all directions by the
joeverbout 0:ea44dc9ed014 1436 specified amount, for example:
joeverbout 0:ea44dc9ed014 1437 @code
joeverbout 0:ea44dc9ed014 1438 A.adjustROI(2, 2, 2, 2);
joeverbout 0:ea44dc9ed014 1439 @endcode
joeverbout 0:ea44dc9ed014 1440 In this example, the matrix size is increased by 4 elements in each direction. The matrix is shifted
joeverbout 0:ea44dc9ed014 1441 by 2 elements to the left and 2 elements up, which brings in all the necessary pixels for the
joeverbout 0:ea44dc9ed014 1442 filtering with the 5x5 kernel.
joeverbout 0:ea44dc9ed014 1443
joeverbout 0:ea44dc9ed014 1444 adjustROI forces the adjusted ROI to be inside of the parent matrix that is boundaries of the
joeverbout 0:ea44dc9ed014 1445 adjusted ROI are constrained by boundaries of the parent matrix. For example, if the submatrix A is
joeverbout 0:ea44dc9ed014 1446 located in the first row of a parent matrix and you called A.adjustROI(2, 2, 2, 2) then A will not
joeverbout 0:ea44dc9ed014 1447 be increased in the upward direction.
joeverbout 0:ea44dc9ed014 1448
joeverbout 0:ea44dc9ed014 1449 The function is used internally by the OpenCV filtering functions, like filter2D , morphological
joeverbout 0:ea44dc9ed014 1450 operations, and so on.
joeverbout 0:ea44dc9ed014 1451 @param dtop Shift of the top submatrix boundary upwards.
joeverbout 0:ea44dc9ed014 1452 @param dbottom Shift of the bottom submatrix boundary downwards.
joeverbout 0:ea44dc9ed014 1453 @param dleft Shift of the left submatrix boundary to the left.
joeverbout 0:ea44dc9ed014 1454 @param dright Shift of the right submatrix boundary to the right.
joeverbout 0:ea44dc9ed014 1455 @sa copyMakeBorder
joeverbout 0:ea44dc9ed014 1456 */
joeverbout 0:ea44dc9ed014 1457 Mat& adjustROI( int dtop, int dbottom, int dleft, int dright );
joeverbout 0:ea44dc9ed014 1458
joeverbout 0:ea44dc9ed014 1459 /** @brief Extracts a rectangular submatrix.
joeverbout 0:ea44dc9ed014 1460
joeverbout 0:ea44dc9ed014 1461 The operators make a new header for the specified sub-array of \*this . They are the most
joeverbout 0:ea44dc9ed014 1462 generalized forms of Mat::row, Mat::col, Mat::rowRange, and Mat::colRange . For example,
joeverbout 0:ea44dc9ed014 1463 `A(Range(0, 10), Range::all())` is equivalent to `A.rowRange(0, 10)`. Similarly to all of the above,
joeverbout 0:ea44dc9ed014 1464 the operators are O(1) operations, that is, no matrix data is copied.
joeverbout 0:ea44dc9ed014 1465 @param rowRange Start and end row of the extracted submatrix. The upper boundary is not included. To
joeverbout 0:ea44dc9ed014 1466 select all the rows, use Range::all().
joeverbout 0:ea44dc9ed014 1467 @param colRange Start and end column of the extracted submatrix. The upper boundary is not included.
joeverbout 0:ea44dc9ed014 1468 To select all the columns, use Range::all().
joeverbout 0:ea44dc9ed014 1469 */
joeverbout 0:ea44dc9ed014 1470 Mat operator()( Range rowRange, Range colRange ) const;
joeverbout 0:ea44dc9ed014 1471
joeverbout 0:ea44dc9ed014 1472 /** @overload
joeverbout 0:ea44dc9ed014 1473 @param roi Extracted submatrix specified as a rectangle.
joeverbout 0:ea44dc9ed014 1474 */
joeverbout 0:ea44dc9ed014 1475 Mat operator()( const Rect& roi ) const;
joeverbout 0:ea44dc9ed014 1476
joeverbout 0:ea44dc9ed014 1477 /** @overload
joeverbout 0:ea44dc9ed014 1478 @param ranges Array of selected ranges along each array dimension.
joeverbout 0:ea44dc9ed014 1479 */
joeverbout 0:ea44dc9ed014 1480 Mat operator()( const Range* ranges ) const;
joeverbout 0:ea44dc9ed014 1481
joeverbout 0:ea44dc9ed014 1482 // //! converts header to CvMat; no data is copied
joeverbout 0:ea44dc9ed014 1483 // operator CvMat() const;
joeverbout 0:ea44dc9ed014 1484 // //! converts header to CvMatND; no data is copied
joeverbout 0:ea44dc9ed014 1485 // operator CvMatND() const;
joeverbout 0:ea44dc9ed014 1486 // //! converts header to IplImage; no data is copied
joeverbout 0:ea44dc9ed014 1487 // operator IplImage() const;
joeverbout 0:ea44dc9ed014 1488
joeverbout 0:ea44dc9ed014 1489 template<typename _Tp> operator std::vector<_Tp>() const;
joeverbout 0:ea44dc9ed014 1490 template<typename _Tp, int n> operator Vec<_Tp, n>() const;
joeverbout 0:ea44dc9ed014 1491 template<typename _Tp, int m, int n> operator Matx<_Tp, m, n>() const;
joeverbout 0:ea44dc9ed014 1492
joeverbout 0:ea44dc9ed014 1493 /** @brief Reports whether the matrix is continuous or not.
joeverbout 0:ea44dc9ed014 1494
joeverbout 0:ea44dc9ed014 1495 The method returns true if the matrix elements are stored continuously without gaps at the end of
joeverbout 0:ea44dc9ed014 1496 each row. Otherwise, it returns false. Obviously, 1x1 or 1xN matrices are always continuous.
joeverbout 0:ea44dc9ed014 1497 Matrices created with Mat::create are always continuous. But if you extract a part of the matrix
joeverbout 0:ea44dc9ed014 1498 using Mat::col, Mat::diag, and so on, or constructed a matrix header for externally allocated data,
joeverbout 0:ea44dc9ed014 1499 such matrices may no longer have this property.
joeverbout 0:ea44dc9ed014 1500
joeverbout 0:ea44dc9ed014 1501 The continuity flag is stored as a bit in the Mat::flags field and is computed automatically when
joeverbout 0:ea44dc9ed014 1502 you construct a matrix header. Thus, the continuity check is a very fast operation, though
joeverbout 0:ea44dc9ed014 1503 theoretically it could be done as follows:
joeverbout 0:ea44dc9ed014 1504 @code
joeverbout 0:ea44dc9ed014 1505 // alternative implementation of Mat::isContinuous()
joeverbout 0:ea44dc9ed014 1506 bool myCheckMatContinuity(const Mat& m)
joeverbout 0:ea44dc9ed014 1507 {
joeverbout 0:ea44dc9ed014 1508 //return (m.flags & Mat::CONTINUOUS_FLAG) != 0;
joeverbout 0:ea44dc9ed014 1509 return m.rows == 1 || m.step == m.cols*m.elemSize();
joeverbout 0:ea44dc9ed014 1510 }
joeverbout 0:ea44dc9ed014 1511 @endcode
joeverbout 0:ea44dc9ed014 1512 The method is used in quite a few of OpenCV functions. The point is that element-wise operations
joeverbout 0:ea44dc9ed014 1513 (such as arithmetic and logical operations, math functions, alpha blending, color space
joeverbout 0:ea44dc9ed014 1514 transformations, and others) do not depend on the image geometry. Thus, if all the input and output
joeverbout 0:ea44dc9ed014 1515 arrays are continuous, the functions can process them as very long single-row vectors. The example
joeverbout 0:ea44dc9ed014 1516 below illustrates how an alpha-blending function can be implemented:
joeverbout 0:ea44dc9ed014 1517 @code
joeverbout 0:ea44dc9ed014 1518 template<typename T>
joeverbout 0:ea44dc9ed014 1519 void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst)
joeverbout 0:ea44dc9ed014 1520 {
joeverbout 0:ea44dc9ed014 1521 const float alpha_scale = (float)std::numeric_limits<T>::max(),
joeverbout 0:ea44dc9ed014 1522 inv_scale = 1.f/alpha_scale;
joeverbout 0:ea44dc9ed014 1523
joeverbout 0:ea44dc9ed014 1524 CV_Assert( src1.type() == src2.type() &&
joeverbout 0:ea44dc9ed014 1525 src1.type() == CV_MAKETYPE(DataType<T>::depth, 4) &&
joeverbout 0:ea44dc9ed014 1526 src1.size() == src2.size());
joeverbout 0:ea44dc9ed014 1527 Size size = src1.size();
joeverbout 0:ea44dc9ed014 1528 dst.create(size, src1.type());
joeverbout 0:ea44dc9ed014 1529
joeverbout 0:ea44dc9ed014 1530 // here is the idiom: check the arrays for continuity and,
joeverbout 0:ea44dc9ed014 1531 // if this is the case,
joeverbout 0:ea44dc9ed014 1532 // treat the arrays as 1D vectors
joeverbout 0:ea44dc9ed014 1533 if( src1.isContinuous() && src2.isContinuous() && dst.isContinuous() )
joeverbout 0:ea44dc9ed014 1534 {
joeverbout 0:ea44dc9ed014 1535 size.width *= size.height;
joeverbout 0:ea44dc9ed014 1536 size.height = 1;
joeverbout 0:ea44dc9ed014 1537 }
joeverbout 0:ea44dc9ed014 1538 size.width *= 4;
joeverbout 0:ea44dc9ed014 1539
joeverbout 0:ea44dc9ed014 1540 for( int i = 0; i < size.height; i++ )
joeverbout 0:ea44dc9ed014 1541 {
joeverbout 0:ea44dc9ed014 1542 // when the arrays are continuous,
joeverbout 0:ea44dc9ed014 1543 // the outer loop is executed only once
joeverbout 0:ea44dc9ed014 1544 const T* ptr1 = src1.ptr<T>(i);
joeverbout 0:ea44dc9ed014 1545 const T* ptr2 = src2.ptr<T>(i);
joeverbout 0:ea44dc9ed014 1546 T* dptr = dst.ptr<T>(i);
joeverbout 0:ea44dc9ed014 1547
joeverbout 0:ea44dc9ed014 1548 for( int j = 0; j < size.width; j += 4 )
joeverbout 0:ea44dc9ed014 1549 {
joeverbout 0:ea44dc9ed014 1550 float alpha = ptr1[j+3]*inv_scale, beta = ptr2[j+3]*inv_scale;
joeverbout 0:ea44dc9ed014 1551 dptr[j] = saturate_cast<T>(ptr1[j]*alpha + ptr2[j]*beta);
joeverbout 0:ea44dc9ed014 1552 dptr[j+1] = saturate_cast<T>(ptr1[j+1]*alpha + ptr2[j+1]*beta);
joeverbout 0:ea44dc9ed014 1553 dptr[j+2] = saturate_cast<T>(ptr1[j+2]*alpha + ptr2[j+2]*beta);
joeverbout 0:ea44dc9ed014 1554 dptr[j+3] = saturate_cast<T>((1 - (1-alpha)*(1-beta))*alpha_scale);
joeverbout 0:ea44dc9ed014 1555 }
joeverbout 0:ea44dc9ed014 1556 }
joeverbout 0:ea44dc9ed014 1557 }
joeverbout 0:ea44dc9ed014 1558 @endcode
joeverbout 0:ea44dc9ed014 1559 This approach, while being very simple, can boost the performance of a simple element-operation by
joeverbout 0:ea44dc9ed014 1560 10-20 percents, especially if the image is rather small and the operation is quite simple.
joeverbout 0:ea44dc9ed014 1561
joeverbout 0:ea44dc9ed014 1562 Another OpenCV idiom in this function, a call of Mat::create for the destination array, that
joeverbout 0:ea44dc9ed014 1563 allocates the destination array unless it already has the proper size and type. And while the newly
joeverbout 0:ea44dc9ed014 1564 allocated arrays are always continuous, you still need to check the destination array because
joeverbout 0:ea44dc9ed014 1565 Mat::create does not always allocate a new matrix.
joeverbout 0:ea44dc9ed014 1566 */
joeverbout 0:ea44dc9ed014 1567 bool isContinuous() const;
joeverbout 0:ea44dc9ed014 1568
joeverbout 0:ea44dc9ed014 1569 //! returns true if the matrix is a submatrix of another matrix
joeverbout 0:ea44dc9ed014 1570 bool isSubmatrix() const;
joeverbout 0:ea44dc9ed014 1571
joeverbout 0:ea44dc9ed014 1572 /** @brief Returns the matrix element size in bytes.
joeverbout 0:ea44dc9ed014 1573
joeverbout 0:ea44dc9ed014 1574 The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 ,
joeverbout 0:ea44dc9ed014 1575 the method returns 3\*sizeof(short) or 6.
joeverbout 0:ea44dc9ed014 1576 */
joeverbout 0:ea44dc9ed014 1577 size_t elemSize() const;
joeverbout 0:ea44dc9ed014 1578
joeverbout 0:ea44dc9ed014 1579 /** @brief Returns the size of each matrix element channel in bytes.
joeverbout 0:ea44dc9ed014 1580
joeverbout 0:ea44dc9ed014 1581 The method returns the matrix element channel size in bytes, that is, it ignores the number of
joeverbout 0:ea44dc9ed014 1582 channels. For example, if the matrix type is CV_16SC3 , the method returns sizeof(short) or 2.
joeverbout 0:ea44dc9ed014 1583 */
joeverbout 0:ea44dc9ed014 1584 size_t elemSize1() const;
joeverbout 0:ea44dc9ed014 1585
joeverbout 0:ea44dc9ed014 1586 /** @brief Returns the type of a matrix element.
joeverbout 0:ea44dc9ed014 1587
joeverbout 0:ea44dc9ed014 1588 The method returns a matrix element type. This is an identifier compatible with the CvMat type
joeverbout 0:ea44dc9ed014 1589 system, like CV_16SC3 or 16-bit signed 3-channel array, and so on.
joeverbout 0:ea44dc9ed014 1590 */
joeverbout 0:ea44dc9ed014 1591 int type() const;
joeverbout 0:ea44dc9ed014 1592
joeverbout 0:ea44dc9ed014 1593 /** @brief Returns the depth of a matrix element.
joeverbout 0:ea44dc9ed014 1594
joeverbout 0:ea44dc9ed014 1595 The method returns the identifier of the matrix element depth (the type of each individual channel).
joeverbout 0:ea44dc9ed014 1596 For example, for a 16-bit signed element array, the method returns CV_16S . A complete list of
joeverbout 0:ea44dc9ed014 1597 matrix types contains the following values:
joeverbout 0:ea44dc9ed014 1598 - CV_8U - 8-bit unsigned integers ( 0..255 )
joeverbout 0:ea44dc9ed014 1599 - CV_8S - 8-bit signed integers ( -128..127 )
joeverbout 0:ea44dc9ed014 1600 - CV_16U - 16-bit unsigned integers ( 0..65535 )
joeverbout 0:ea44dc9ed014 1601 - CV_16S - 16-bit signed integers ( -32768..32767 )
joeverbout 0:ea44dc9ed014 1602 - CV_32S - 32-bit signed integers ( -2147483648..2147483647 )
joeverbout 0:ea44dc9ed014 1603 - CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN )
joeverbout 0:ea44dc9ed014 1604 - CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN )
joeverbout 0:ea44dc9ed014 1605 */
joeverbout 0:ea44dc9ed014 1606 int depth() const;
joeverbout 0:ea44dc9ed014 1607
joeverbout 0:ea44dc9ed014 1608 /** @brief Returns the number of matrix channels.
joeverbout 0:ea44dc9ed014 1609
joeverbout 0:ea44dc9ed014 1610 The method returns the number of matrix channels.
joeverbout 0:ea44dc9ed014 1611 */
joeverbout 0:ea44dc9ed014 1612 int channels() const;
joeverbout 0:ea44dc9ed014 1613
joeverbout 0:ea44dc9ed014 1614 /** @brief Returns a normalized step.
joeverbout 0:ea44dc9ed014 1615
joeverbout 0:ea44dc9ed014 1616 The method returns a matrix step divided by Mat::elemSize1() . It can be useful to quickly access an
joeverbout 0:ea44dc9ed014 1617 arbitrary matrix element.
joeverbout 0:ea44dc9ed014 1618 */
joeverbout 0:ea44dc9ed014 1619 size_t step1(int i=0) const;
joeverbout 0:ea44dc9ed014 1620
joeverbout 0:ea44dc9ed014 1621 /** @brief Returns true if the array has no elements.
joeverbout 0:ea44dc9ed014 1622
joeverbout 0:ea44dc9ed014 1623 The method returns true if Mat::total() is 0 or if Mat::data is NULL. Because of pop_back() and
joeverbout 0:ea44dc9ed014 1624 resize() methods `M.total() == 0` does not imply that `M.data == NULL`.
joeverbout 0:ea44dc9ed014 1625 */
joeverbout 0:ea44dc9ed014 1626 bool empty() const;
joeverbout 0:ea44dc9ed014 1627
joeverbout 0:ea44dc9ed014 1628 /** @brief Returns the total number of array elements.
joeverbout 0:ea44dc9ed014 1629
joeverbout 0:ea44dc9ed014 1630 The method returns the number of array elements (a number of pixels if the array represents an
joeverbout 0:ea44dc9ed014 1631 image).
joeverbout 0:ea44dc9ed014 1632 */
joeverbout 0:ea44dc9ed014 1633 size_t total() const;
joeverbout 0:ea44dc9ed014 1634
joeverbout 0:ea44dc9ed014 1635 //! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise
joeverbout 0:ea44dc9ed014 1636 int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const;
joeverbout 0:ea44dc9ed014 1637
joeverbout 0:ea44dc9ed014 1638 /** @brief Returns a pointer to the specified matrix row.
joeverbout 0:ea44dc9ed014 1639
joeverbout 0:ea44dc9ed014 1640 The methods return `uchar*` or typed pointer to the specified matrix row. See the sample in
joeverbout 0:ea44dc9ed014 1641 Mat::isContinuous to know how to use these methods.
joeverbout 0:ea44dc9ed014 1642 @param i0 A 0-based row index.
joeverbout 0:ea44dc9ed014 1643 */
joeverbout 0:ea44dc9ed014 1644 uchar* ptr(int i0=0);
joeverbout 0:ea44dc9ed014 1645 /** @overload */
joeverbout 0:ea44dc9ed014 1646 const uchar* ptr(int i0=0) const;
joeverbout 0:ea44dc9ed014 1647
joeverbout 0:ea44dc9ed014 1648 /** @overload */
joeverbout 0:ea44dc9ed014 1649 uchar* ptr(int i0, int i1);
joeverbout 0:ea44dc9ed014 1650 /** @overload */
joeverbout 0:ea44dc9ed014 1651 const uchar* ptr(int i0, int i1) const;
joeverbout 0:ea44dc9ed014 1652
joeverbout 0:ea44dc9ed014 1653 /** @overload */
joeverbout 0:ea44dc9ed014 1654 uchar* ptr(int i0, int i1, int i2);
joeverbout 0:ea44dc9ed014 1655 /** @overload */
joeverbout 0:ea44dc9ed014 1656 const uchar* ptr(int i0, int i1, int i2) const;
joeverbout 0:ea44dc9ed014 1657
joeverbout 0:ea44dc9ed014 1658 /** @overload */
joeverbout 0:ea44dc9ed014 1659 uchar* ptr(const int* idx);
joeverbout 0:ea44dc9ed014 1660 /** @overload */
joeverbout 0:ea44dc9ed014 1661 const uchar* ptr(const int* idx) const;
joeverbout 0:ea44dc9ed014 1662 /** @overload */
joeverbout 0:ea44dc9ed014 1663 template<int n> uchar* ptr(const Vec<int, n>& idx);
joeverbout 0:ea44dc9ed014 1664 /** @overload */
joeverbout 0:ea44dc9ed014 1665 template<int n> const uchar* ptr(const Vec<int, n>& idx) const;
joeverbout 0:ea44dc9ed014 1666
joeverbout 0:ea44dc9ed014 1667 /** @overload */
joeverbout 0:ea44dc9ed014 1668 template<typename _Tp> _Tp* ptr(int i0=0);
joeverbout 0:ea44dc9ed014 1669 /** @overload */
joeverbout 0:ea44dc9ed014 1670 template<typename _Tp> const _Tp* ptr(int i0=0) const;
joeverbout 0:ea44dc9ed014 1671 /** @overload */
joeverbout 0:ea44dc9ed014 1672 template<typename _Tp> _Tp* ptr(int i0, int i1);
joeverbout 0:ea44dc9ed014 1673 /** @overload */
joeverbout 0:ea44dc9ed014 1674 template<typename _Tp> const _Tp* ptr(int i0, int i1) const;
joeverbout 0:ea44dc9ed014 1675 /** @overload */
joeverbout 0:ea44dc9ed014 1676 template<typename _Tp> _Tp* ptr(int i0, int i1, int i2);
joeverbout 0:ea44dc9ed014 1677 /** @overload */
joeverbout 0:ea44dc9ed014 1678 template<typename _Tp> const _Tp* ptr(int i0, int i1, int i2) const;
joeverbout 0:ea44dc9ed014 1679 /** @overload */
joeverbout 0:ea44dc9ed014 1680 template<typename _Tp> _Tp* ptr(const int* idx);
joeverbout 0:ea44dc9ed014 1681 /** @overload */
joeverbout 0:ea44dc9ed014 1682 template<typename _Tp> const _Tp* ptr(const int* idx) const;
joeverbout 0:ea44dc9ed014 1683 /** @overload */
joeverbout 0:ea44dc9ed014 1684 template<typename _Tp, int n> _Tp* ptr(const Vec<int, n>& idx);
joeverbout 0:ea44dc9ed014 1685 /** @overload */
joeverbout 0:ea44dc9ed014 1686 template<typename _Tp, int n> const _Tp* ptr(const Vec<int, n>& idx) const;
joeverbout 0:ea44dc9ed014 1687
joeverbout 0:ea44dc9ed014 1688 /** @brief Returns a reference to the specified array element.
joeverbout 0:ea44dc9ed014 1689
joeverbout 0:ea44dc9ed014 1690 The template methods return a reference to the specified array element. For the sake of higher
joeverbout 0:ea44dc9ed014 1691 performance, the index range checks are only performed in the Debug configuration.
joeverbout 0:ea44dc9ed014 1692
joeverbout 0:ea44dc9ed014 1693 Note that the variants with a single index (i) can be used to access elements of single-row or
joeverbout 0:ea44dc9ed014 1694 single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and
joeverbout 0:ea44dc9ed014 1695 B is an M x 1 integer matrix, you can simply write `A.at<float>(k+4)` and `B.at<int>(2*i+1)`
joeverbout 0:ea44dc9ed014 1696 instead of `A.at<float>(0,k+4)` and `B.at<int>(2*i+1,0)`, respectively.
joeverbout 0:ea44dc9ed014 1697
joeverbout 0:ea44dc9ed014 1698 The example below initializes a Hilbert matrix:
joeverbout 0:ea44dc9ed014 1699 @code
joeverbout 0:ea44dc9ed014 1700 Mat H(100, 100, CV_64F);
joeverbout 0:ea44dc9ed014 1701 for(int i = 0; i < H.rows; i++)
joeverbout 0:ea44dc9ed014 1702 for(int j = 0; j < H.cols; j++)
joeverbout 0:ea44dc9ed014 1703 H.at<double>(i,j)=1./(i+j+1);
joeverbout 0:ea44dc9ed014 1704 @endcode
joeverbout 0:ea44dc9ed014 1705 @param i0 Index along the dimension 0
joeverbout 0:ea44dc9ed014 1706 */
joeverbout 0:ea44dc9ed014 1707 template<typename _Tp> _Tp& at(int i0=0);
joeverbout 0:ea44dc9ed014 1708 /** @overload
joeverbout 0:ea44dc9ed014 1709 @param i0 Index along the dimension 0
joeverbout 0:ea44dc9ed014 1710 */
joeverbout 0:ea44dc9ed014 1711 template<typename _Tp> const _Tp& at(int i0=0) const;
joeverbout 0:ea44dc9ed014 1712 /** @overload
joeverbout 0:ea44dc9ed014 1713 @param i0 Index along the dimension 0
joeverbout 0:ea44dc9ed014 1714 @param i1 Index along the dimension 1
joeverbout 0:ea44dc9ed014 1715 */
joeverbout 0:ea44dc9ed014 1716 template<typename _Tp> _Tp& at(int i0, int i1);
joeverbout 0:ea44dc9ed014 1717 /** @overload
joeverbout 0:ea44dc9ed014 1718 @param i0 Index along the dimension 0
joeverbout 0:ea44dc9ed014 1719 @param i1 Index along the dimension 1
joeverbout 0:ea44dc9ed014 1720 */
joeverbout 0:ea44dc9ed014 1721 template<typename _Tp> const _Tp& at(int i0, int i1) const;
joeverbout 0:ea44dc9ed014 1722
joeverbout 0:ea44dc9ed014 1723 /** @overload
joeverbout 0:ea44dc9ed014 1724 @param i0 Index along the dimension 0
joeverbout 0:ea44dc9ed014 1725 @param i1 Index along the dimension 1
joeverbout 0:ea44dc9ed014 1726 @param i2 Index along the dimension 2
joeverbout 0:ea44dc9ed014 1727 */
joeverbout 0:ea44dc9ed014 1728 template<typename _Tp> _Tp& at(int i0, int i1, int i2);
joeverbout 0:ea44dc9ed014 1729 /** @overload
joeverbout 0:ea44dc9ed014 1730 @param i0 Index along the dimension 0
joeverbout 0:ea44dc9ed014 1731 @param i1 Index along the dimension 1
joeverbout 0:ea44dc9ed014 1732 @param i2 Index along the dimension 2
joeverbout 0:ea44dc9ed014 1733 */
joeverbout 0:ea44dc9ed014 1734 template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const;
joeverbout 0:ea44dc9ed014 1735
joeverbout 0:ea44dc9ed014 1736 /** @overload
joeverbout 0:ea44dc9ed014 1737 @param idx Array of Mat::dims indices.
joeverbout 0:ea44dc9ed014 1738 */
joeverbout 0:ea44dc9ed014 1739 template<typename _Tp> _Tp& at(const int* idx);
joeverbout 0:ea44dc9ed014 1740 /** @overload
joeverbout 0:ea44dc9ed014 1741 @param idx Array of Mat::dims indices.
joeverbout 0:ea44dc9ed014 1742 */
joeverbout 0:ea44dc9ed014 1743 template<typename _Tp> const _Tp& at(const int* idx) const;
joeverbout 0:ea44dc9ed014 1744
joeverbout 0:ea44dc9ed014 1745 /** @overload */
joeverbout 0:ea44dc9ed014 1746 template<typename _Tp, int n> _Tp& at(const Vec<int, n>& idx);
joeverbout 0:ea44dc9ed014 1747 /** @overload */
joeverbout 0:ea44dc9ed014 1748 template<typename _Tp, int n> const _Tp& at(const Vec<int, n>& idx) const;
joeverbout 0:ea44dc9ed014 1749
joeverbout 0:ea44dc9ed014 1750 /** @overload
joeverbout 0:ea44dc9ed014 1751 special versions for 2D arrays (especially convenient for referencing image pixels)
joeverbout 0:ea44dc9ed014 1752 @param pt Element position specified as Point(j,i) .
joeverbout 0:ea44dc9ed014 1753 */
joeverbout 0:ea44dc9ed014 1754 template<typename _Tp> _Tp& at(Point pt);
joeverbout 0:ea44dc9ed014 1755 /** @overload
joeverbout 0:ea44dc9ed014 1756 special versions for 2D arrays (especially convenient for referencing image pixels)
joeverbout 0:ea44dc9ed014 1757 @param pt Element position specified as Point(j,i) .
joeverbout 0:ea44dc9ed014 1758 */
joeverbout 0:ea44dc9ed014 1759 template<typename _Tp> const _Tp& at(Point pt) const;
joeverbout 0:ea44dc9ed014 1760
joeverbout 0:ea44dc9ed014 1761 /** @brief Returns the matrix iterator and sets it to the first matrix element.
joeverbout 0:ea44dc9ed014 1762
joeverbout 0:ea44dc9ed014 1763 The methods return the matrix read-only or read-write iterators. The use of matrix iterators is very
joeverbout 0:ea44dc9ed014 1764 similar to the use of bi-directional STL iterators. In the example below, the alpha blending
joeverbout 0:ea44dc9ed014 1765 function is rewritten using the matrix iterators:
joeverbout 0:ea44dc9ed014 1766 @code
joeverbout 0:ea44dc9ed014 1767 template<typename T>
joeverbout 0:ea44dc9ed014 1768 void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst)
joeverbout 0:ea44dc9ed014 1769 {
joeverbout 0:ea44dc9ed014 1770 typedef Vec<T, 4> VT;
joeverbout 0:ea44dc9ed014 1771
joeverbout 0:ea44dc9ed014 1772 const float alpha_scale = (float)std::numeric_limits<T>::max(),
joeverbout 0:ea44dc9ed014 1773 inv_scale = 1.f/alpha_scale;
joeverbout 0:ea44dc9ed014 1774
joeverbout 0:ea44dc9ed014 1775 CV_Assert( src1.type() == src2.type() &&
joeverbout 0:ea44dc9ed014 1776 src1.type() == DataType<VT>::type &&
joeverbout 0:ea44dc9ed014 1777 src1.size() == src2.size());
joeverbout 0:ea44dc9ed014 1778 Size size = src1.size();
joeverbout 0:ea44dc9ed014 1779 dst.create(size, src1.type());
joeverbout 0:ea44dc9ed014 1780
joeverbout 0:ea44dc9ed014 1781 MatConstIterator_<VT> it1 = src1.begin<VT>(), it1_end = src1.end<VT>();
joeverbout 0:ea44dc9ed014 1782 MatConstIterator_<VT> it2 = src2.begin<VT>();
joeverbout 0:ea44dc9ed014 1783 MatIterator_<VT> dst_it = dst.begin<VT>();
joeverbout 0:ea44dc9ed014 1784
joeverbout 0:ea44dc9ed014 1785 for( ; it1 != it1_end; ++it1, ++it2, ++dst_it )
joeverbout 0:ea44dc9ed014 1786 {
joeverbout 0:ea44dc9ed014 1787 VT pix1 = *it1, pix2 = *it2;
joeverbout 0:ea44dc9ed014 1788 float alpha = pix1[3]*inv_scale, beta = pix2[3]*inv_scale;
joeverbout 0:ea44dc9ed014 1789 *dst_it = VT(saturate_cast<T>(pix1[0]*alpha + pix2[0]*beta),
joeverbout 0:ea44dc9ed014 1790 saturate_cast<T>(pix1[1]*alpha + pix2[1]*beta),
joeverbout 0:ea44dc9ed014 1791 saturate_cast<T>(pix1[2]*alpha + pix2[2]*beta),
joeverbout 0:ea44dc9ed014 1792 saturate_cast<T>((1 - (1-alpha)*(1-beta))*alpha_scale));
joeverbout 0:ea44dc9ed014 1793 }
joeverbout 0:ea44dc9ed014 1794 }
joeverbout 0:ea44dc9ed014 1795 @endcode
joeverbout 0:ea44dc9ed014 1796 */
joeverbout 0:ea44dc9ed014 1797 template<typename _Tp> MatIterator_<_Tp> begin();
joeverbout 0:ea44dc9ed014 1798 template<typename _Tp> MatConstIterator_<_Tp> begin() const;
joeverbout 0:ea44dc9ed014 1799
joeverbout 0:ea44dc9ed014 1800 /** @brief Returns the matrix iterator and sets it to the after-last matrix element.
joeverbout 0:ea44dc9ed014 1801
joeverbout 0:ea44dc9ed014 1802 The methods return the matrix read-only or read-write iterators, set to the point following the last
joeverbout 0:ea44dc9ed014 1803 matrix element.
joeverbout 0:ea44dc9ed014 1804 */
joeverbout 0:ea44dc9ed014 1805 template<typename _Tp> MatIterator_<_Tp> end();
joeverbout 0:ea44dc9ed014 1806 template<typename _Tp> MatConstIterator_<_Tp> end() const;
joeverbout 0:ea44dc9ed014 1807
joeverbout 0:ea44dc9ed014 1808 /** @brief Invoke with arguments functor, and runs the functor over all matrix element.
joeverbout 0:ea44dc9ed014 1809
joeverbout 0:ea44dc9ed014 1810 The methods runs operation in parallel. Operation is passed by arguments. Operation have to be a
joeverbout 0:ea44dc9ed014 1811 function pointer, a function object or a lambda(C++11).
joeverbout 0:ea44dc9ed014 1812
joeverbout 0:ea44dc9ed014 1813 All of below operation is equal. Put 0xFF to first channel of all matrix elements:
joeverbout 0:ea44dc9ed014 1814 @code
joeverbout 0:ea44dc9ed014 1815 Mat image(1920, 1080, CV_8UC3);
joeverbout 0:ea44dc9ed014 1816 typedef cv::Point3_<uint8_t> Pixel;
joeverbout 0:ea44dc9ed014 1817
joeverbout 0:ea44dc9ed014 1818 // first. raw pointer access.
joeverbout 0:ea44dc9ed014 1819 for (int r = 0; r < image.rows; ++r) {
joeverbout 0:ea44dc9ed014 1820 Pixel* ptr = image.ptr<Pixel>(0, r);
joeverbout 0:ea44dc9ed014 1821 const Pixel* ptr_end = ptr + image.cols;
joeverbout 0:ea44dc9ed014 1822 for (; ptr != ptr_end; ++ptr) {
joeverbout 0:ea44dc9ed014 1823 ptr->x = 255;
joeverbout 0:ea44dc9ed014 1824 }
joeverbout 0:ea44dc9ed014 1825 }
joeverbout 0:ea44dc9ed014 1826
joeverbout 0:ea44dc9ed014 1827 // Using MatIterator. (Simple but there are a Iterator's overhead)
joeverbout 0:ea44dc9ed014 1828 for (Pixel &p : cv::Mat_<Pixel>(image)) {
joeverbout 0:ea44dc9ed014 1829 p.x = 255;
joeverbout 0:ea44dc9ed014 1830 }
joeverbout 0:ea44dc9ed014 1831
joeverbout 0:ea44dc9ed014 1832 // Parallel execution with function object.
joeverbout 0:ea44dc9ed014 1833 struct Operator {
joeverbout 0:ea44dc9ed014 1834 void operator ()(Pixel &pixel, const int * position) {
joeverbout 0:ea44dc9ed014 1835 pixel.x = 255;
joeverbout 0:ea44dc9ed014 1836 }
joeverbout 0:ea44dc9ed014 1837 };
joeverbout 0:ea44dc9ed014 1838 image.forEach<Pixel>(Operator());
joeverbout 0:ea44dc9ed014 1839
joeverbout 0:ea44dc9ed014 1840 // Parallel execution using C++11 lambda.
joeverbout 0:ea44dc9ed014 1841 image.forEach<Pixel>([](Pixel &p, const int * position) -> void {
joeverbout 0:ea44dc9ed014 1842 p.x = 255;
joeverbout 0:ea44dc9ed014 1843 });
joeverbout 0:ea44dc9ed014 1844 @endcode
joeverbout 0:ea44dc9ed014 1845 position parameter is index of current pixel:
joeverbout 0:ea44dc9ed014 1846 @code
joeverbout 0:ea44dc9ed014 1847 // Creating 3D matrix (255 x 255 x 255) typed uint8_t,
joeverbout 0:ea44dc9ed014 1848 // and initialize all elements by the value which equals elements position.
joeverbout 0:ea44dc9ed014 1849 // i.e. pixels (x,y,z) = (1,2,3) is (b,g,r) = (1,2,3).
joeverbout 0:ea44dc9ed014 1850
joeverbout 0:ea44dc9ed014 1851 int sizes[] = { 255, 255, 255 };
joeverbout 0:ea44dc9ed014 1852 typedef cv::Point3_<uint8_t> Pixel;
joeverbout 0:ea44dc9ed014 1853
joeverbout 0:ea44dc9ed014 1854 Mat_<Pixel> image = Mat::zeros(3, sizes, CV_8UC3);
joeverbout 0:ea44dc9ed014 1855
joeverbout 0:ea44dc9ed014 1856 image.forEachWithPosition([&](Pixel& pixel, const int position[]) -> void{
joeverbout 0:ea44dc9ed014 1857 pixel.x = position[0];
joeverbout 0:ea44dc9ed014 1858 pixel.y = position[1];
joeverbout 0:ea44dc9ed014 1859 pixel.z = position[2];
joeverbout 0:ea44dc9ed014 1860 });
joeverbout 0:ea44dc9ed014 1861 @endcode
joeverbout 0:ea44dc9ed014 1862 */
joeverbout 0:ea44dc9ed014 1863 template<typename _Tp, typename Functor> void forEach(const Functor& operation);
joeverbout 0:ea44dc9ed014 1864 /** @overload */
joeverbout 0:ea44dc9ed014 1865 template<typename _Tp, typename Functor> void forEach(const Functor& operation) const;
joeverbout 0:ea44dc9ed014 1866
joeverbout 0:ea44dc9ed014 1867 #ifdef CV_CXX_MOVE_SEMANTICS
joeverbout 0:ea44dc9ed014 1868 Mat(Mat&& m);
joeverbout 0:ea44dc9ed014 1869 Mat& operator = (Mat&& m);
joeverbout 0:ea44dc9ed014 1870 #endif
joeverbout 0:ea44dc9ed014 1871
joeverbout 0:ea44dc9ed014 1872 enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG };
joeverbout 0:ea44dc9ed014 1873 enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 };
joeverbout 0:ea44dc9ed014 1874
joeverbout 0:ea44dc9ed014 1875 /*! includes several bit-fields:
joeverbout 0:ea44dc9ed014 1876 - the magic signature
joeverbout 0:ea44dc9ed014 1877 - continuity flag
joeverbout 0:ea44dc9ed014 1878 - depth
joeverbout 0:ea44dc9ed014 1879 - number of channels
joeverbout 0:ea44dc9ed014 1880 */
joeverbout 0:ea44dc9ed014 1881 int flags;
joeverbout 0:ea44dc9ed014 1882 //! the matrix dimensionality, >= 2
joeverbout 0:ea44dc9ed014 1883 int dims;
joeverbout 0:ea44dc9ed014 1884 //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
joeverbout 0:ea44dc9ed014 1885 int rows, cols;
joeverbout 0:ea44dc9ed014 1886 //! pointer to the data
joeverbout 0:ea44dc9ed014 1887 uchar* data;
joeverbout 0:ea44dc9ed014 1888
joeverbout 0:ea44dc9ed014 1889 //! helper fields used in locateROI and adjustROI
joeverbout 0:ea44dc9ed014 1890 const uchar* datastart;
joeverbout 0:ea44dc9ed014 1891 const uchar* dataend;
joeverbout 0:ea44dc9ed014 1892 const uchar* datalimit;
joeverbout 0:ea44dc9ed014 1893
joeverbout 0:ea44dc9ed014 1894 //! custom allocator
joeverbout 0:ea44dc9ed014 1895 MatAllocator* allocator;
joeverbout 0:ea44dc9ed014 1896 //! and the standard allocator
joeverbout 0:ea44dc9ed014 1897 static MatAllocator* getStdAllocator();
joeverbout 0:ea44dc9ed014 1898 static MatAllocator* getDefaultAllocator();
joeverbout 0:ea44dc9ed014 1899 static void setDefaultAllocator(MatAllocator* allocator);
joeverbout 0:ea44dc9ed014 1900
joeverbout 0:ea44dc9ed014 1901 //! interaction with UMat
joeverbout 0:ea44dc9ed014 1902 UMatData* u;
joeverbout 0:ea44dc9ed014 1903
joeverbout 0:ea44dc9ed014 1904 MatSize size;
joeverbout 0:ea44dc9ed014 1905 MatStep step;
joeverbout 0:ea44dc9ed014 1906
joeverbout 0:ea44dc9ed014 1907 protected:
joeverbout 0:ea44dc9ed014 1908 template<typename _Tp, typename Functor> void forEach_impl(const Functor& operation);
joeverbout 0:ea44dc9ed014 1909 };
joeverbout 0:ea44dc9ed014 1910
joeverbout 0:ea44dc9ed014 1911
joeverbout 0:ea44dc9ed014 1912 ///////////////////////////////// Mat_<_Tp> ////////////////////////////////////
joeverbout 0:ea44dc9ed014 1913
joeverbout 0:ea44dc9ed014 1914 /** @brief Template matrix class derived from Mat
joeverbout 0:ea44dc9ed014 1915
joeverbout 0:ea44dc9ed014 1916 @code
joeverbout 0:ea44dc9ed014 1917 template<typename _Tp> class Mat_ : public Mat
joeverbout 0:ea44dc9ed014 1918 {
joeverbout 0:ea44dc9ed014 1919 public:
joeverbout 0:ea44dc9ed014 1920 // ... some specific methods
joeverbout 0:ea44dc9ed014 1921 // and
joeverbout 0:ea44dc9ed014 1922 // no new extra fields
joeverbout 0:ea44dc9ed014 1923 };
joeverbout 0:ea44dc9ed014 1924 @endcode
joeverbout 0:ea44dc9ed014 1925 The class `Mat_<_Tp>` is a *thin* template wrapper on top of the Mat class. It does not have any
joeverbout 0:ea44dc9ed014 1926 extra data fields. Nor this class nor Mat has any virtual methods. Thus, references or pointers to
joeverbout 0:ea44dc9ed014 1927 these two classes can be freely but carefully converted one to another. For example:
joeverbout 0:ea44dc9ed014 1928 @code
joeverbout 0:ea44dc9ed014 1929 // create a 100x100 8-bit matrix
joeverbout 0:ea44dc9ed014 1930 Mat M(100,100,CV_8U);
joeverbout 0:ea44dc9ed014 1931 // this will be compiled fine. no any data conversion will be done.
joeverbout 0:ea44dc9ed014 1932 Mat_<float>& M1 = (Mat_<float>&)M;
joeverbout 0:ea44dc9ed014 1933 // the program is likely to crash at the statement below
joeverbout 0:ea44dc9ed014 1934 M1(99,99) = 1.f;
joeverbout 0:ea44dc9ed014 1935 @endcode
joeverbout 0:ea44dc9ed014 1936 While Mat is sufficient in most cases, Mat_ can be more convenient if you use a lot of element
joeverbout 0:ea44dc9ed014 1937 access operations and if you know matrix type at the compilation time. Note that
joeverbout 0:ea44dc9ed014 1938 `Mat::at(int y,int x)` and `Mat_::operator()(int y,int x)` do absolutely the same
joeverbout 0:ea44dc9ed014 1939 and run at the same speed, but the latter is certainly shorter:
joeverbout 0:ea44dc9ed014 1940 @code
joeverbout 0:ea44dc9ed014 1941 Mat_<double> M(20,20);
joeverbout 0:ea44dc9ed014 1942 for(int i = 0; i < M.rows; i++)
joeverbout 0:ea44dc9ed014 1943 for(int j = 0; j < M.cols; j++)
joeverbout 0:ea44dc9ed014 1944 M(i,j) = 1./(i+j+1);
joeverbout 0:ea44dc9ed014 1945 Mat E, V;
joeverbout 0:ea44dc9ed014 1946 eigen(M,E,V);
joeverbout 0:ea44dc9ed014 1947 cout << E.at<double>(0,0)/E.at<double>(M.rows-1,0);
joeverbout 0:ea44dc9ed014 1948 @endcode
joeverbout 0:ea44dc9ed014 1949 To use Mat_ for multi-channel images/matrices, pass Vec as a Mat_ parameter:
joeverbout 0:ea44dc9ed014 1950 @code
joeverbout 0:ea44dc9ed014 1951 // allocate a 320x240 color image and fill it with green (in RGB space)
joeverbout 0:ea44dc9ed014 1952 Mat_<Vec3b> img(240, 320, Vec3b(0,255,0));
joeverbout 0:ea44dc9ed014 1953 // now draw a diagonal white line
joeverbout 0:ea44dc9ed014 1954 for(int i = 0; i < 100; i++)
joeverbout 0:ea44dc9ed014 1955 img(i,i)=Vec3b(255,255,255);
joeverbout 0:ea44dc9ed014 1956 // and now scramble the 2nd (red) channel of each pixel
joeverbout 0:ea44dc9ed014 1957 for(int i = 0; i < img.rows; i++)
joeverbout 0:ea44dc9ed014 1958 for(int j = 0; j < img.cols; j++)
joeverbout 0:ea44dc9ed014 1959 img(i,j)[2] ^= (uchar)(i ^ j);
joeverbout 0:ea44dc9ed014 1960 @endcode
joeverbout 0:ea44dc9ed014 1961 */
joeverbout 0:ea44dc9ed014 1962 template<typename _Tp> class Mat_ : public Mat
joeverbout 0:ea44dc9ed014 1963 {
joeverbout 0:ea44dc9ed014 1964 public:
joeverbout 0:ea44dc9ed014 1965 typedef _Tp value_type;
joeverbout 0:ea44dc9ed014 1966 typedef typename DataType<_Tp>::channel_type channel_type;
joeverbout 0:ea44dc9ed014 1967 typedef MatIterator_<_Tp> iterator;
joeverbout 0:ea44dc9ed014 1968 typedef MatConstIterator_<_Tp> const_iterator;
joeverbout 0:ea44dc9ed014 1969
joeverbout 0:ea44dc9ed014 1970 //! default constructor
joeverbout 0:ea44dc9ed014 1971 Mat_();
joeverbout 0:ea44dc9ed014 1972 //! equivalent to Mat(_rows, _cols, DataType<_Tp>::type)
joeverbout 0:ea44dc9ed014 1973 Mat_(int _rows, int _cols);
joeverbout 0:ea44dc9ed014 1974 //! constructor that sets each matrix element to specified value
joeverbout 0:ea44dc9ed014 1975 Mat_(int _rows, int _cols, const _Tp& value);
joeverbout 0:ea44dc9ed014 1976 //! equivalent to Mat(_size, DataType<_Tp>::type)
joeverbout 0:ea44dc9ed014 1977 explicit Mat_(Size _size);
joeverbout 0:ea44dc9ed014 1978 //! constructor that sets each matrix element to specified value
joeverbout 0:ea44dc9ed014 1979 Mat_(Size _size, const _Tp& value);
joeverbout 0:ea44dc9ed014 1980 //! n-dim array constructor
joeverbout 0:ea44dc9ed014 1981 Mat_(int _ndims, const int* _sizes);
joeverbout 0:ea44dc9ed014 1982 //! n-dim array constructor that sets each matrix element to specified value
joeverbout 0:ea44dc9ed014 1983 Mat_(int _ndims, const int* _sizes, const _Tp& value);
joeverbout 0:ea44dc9ed014 1984 //! copy/conversion contructor. If m is of different type, it's converted
joeverbout 0:ea44dc9ed014 1985 Mat_(const Mat& m);
joeverbout 0:ea44dc9ed014 1986 //! copy constructor
joeverbout 0:ea44dc9ed014 1987 Mat_(const Mat_& m);
joeverbout 0:ea44dc9ed014 1988 //! constructs a matrix on top of user-allocated data. step is in bytes(!!!), regardless of the type
joeverbout 0:ea44dc9ed014 1989 Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP);
joeverbout 0:ea44dc9ed014 1990 //! constructs n-dim matrix on top of user-allocated data. steps are in bytes(!!!), regardless of the type
joeverbout 0:ea44dc9ed014 1991 Mat_(int _ndims, const int* _sizes, _Tp* _data, const size_t* _steps=0);
joeverbout 0:ea44dc9ed014 1992 //! selects a submatrix
joeverbout 0:ea44dc9ed014 1993 Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all());
joeverbout 0:ea44dc9ed014 1994 //! selects a submatrix
joeverbout 0:ea44dc9ed014 1995 Mat_(const Mat_& m, const Rect& roi);
joeverbout 0:ea44dc9ed014 1996 //! selects a submatrix, n-dim version
joeverbout 0:ea44dc9ed014 1997 Mat_(const Mat_& m, const Range* ranges);
joeverbout 0:ea44dc9ed014 1998 //! from a matrix expression
joeverbout 0:ea44dc9ed014 1999 explicit Mat_(const MatExpr& e);
joeverbout 0:ea44dc9ed014 2000 //! makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will have a single column
joeverbout 0:ea44dc9ed014 2001 explicit Mat_(const std::vector<_Tp>& vec, bool copyData=false);
joeverbout 0:ea44dc9ed014 2002 template<int n> explicit Mat_(const Vec<typename DataType<_Tp>::channel_type, n>& vec, bool copyData=true);
joeverbout 0:ea44dc9ed014 2003 template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true);
joeverbout 0:ea44dc9ed014 2004 explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
joeverbout 0:ea44dc9ed014 2005 explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
joeverbout 0:ea44dc9ed014 2006 explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer);
joeverbout 0:ea44dc9ed014 2007
joeverbout 0:ea44dc9ed014 2008 Mat_& operator = (const Mat& m);
joeverbout 0:ea44dc9ed014 2009 Mat_& operator = (const Mat_& m);
joeverbout 0:ea44dc9ed014 2010 //! set all the elements to s.
joeverbout 0:ea44dc9ed014 2011 Mat_& operator = (const _Tp& s);
joeverbout 0:ea44dc9ed014 2012 //! assign a matrix expression
joeverbout 0:ea44dc9ed014 2013 Mat_& operator = (const MatExpr& e);
joeverbout 0:ea44dc9ed014 2014
joeverbout 0:ea44dc9ed014 2015 //! iterators; they are smart enough to skip gaps in the end of rows
joeverbout 0:ea44dc9ed014 2016 iterator begin();
joeverbout 0:ea44dc9ed014 2017 iterator end();
joeverbout 0:ea44dc9ed014 2018 const_iterator begin() const;
joeverbout 0:ea44dc9ed014 2019 const_iterator end() const;
joeverbout 0:ea44dc9ed014 2020
joeverbout 0:ea44dc9ed014 2021 //! template methods for for operation over all matrix elements.
joeverbout 0:ea44dc9ed014 2022 // the operations take care of skipping gaps in the end of rows (if any)
joeverbout 0:ea44dc9ed014 2023 template<typename Functor> void forEach(const Functor& operation);
joeverbout 0:ea44dc9ed014 2024 template<typename Functor> void forEach(const Functor& operation) const;
joeverbout 0:ea44dc9ed014 2025
joeverbout 0:ea44dc9ed014 2026 //! equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type)
joeverbout 0:ea44dc9ed014 2027 void create(int _rows, int _cols);
joeverbout 0:ea44dc9ed014 2028 //! equivalent to Mat::create(_size, DataType<_Tp>::type)
joeverbout 0:ea44dc9ed014 2029 void create(Size _size);
joeverbout 0:ea44dc9ed014 2030 //! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type)
joeverbout 0:ea44dc9ed014 2031 void create(int _ndims, const int* _sizes);
joeverbout 0:ea44dc9ed014 2032 //! cross-product
joeverbout 0:ea44dc9ed014 2033 Mat_ cross(const Mat_& m) const;
joeverbout 0:ea44dc9ed014 2034 //! data type conversion
joeverbout 0:ea44dc9ed014 2035 template<typename T2> operator Mat_<T2>() const;
joeverbout 0:ea44dc9ed014 2036 //! overridden forms of Mat::row() etc.
joeverbout 0:ea44dc9ed014 2037 Mat_ row(int y) const;
joeverbout 0:ea44dc9ed014 2038 Mat_ col(int x) const;
joeverbout 0:ea44dc9ed014 2039 Mat_ diag(int d=0) const;
joeverbout 0:ea44dc9ed014 2040 Mat_ clone() const;
joeverbout 0:ea44dc9ed014 2041
joeverbout 0:ea44dc9ed014 2042 //! overridden forms of Mat::elemSize() etc.
joeverbout 0:ea44dc9ed014 2043 size_t elemSize() const;
joeverbout 0:ea44dc9ed014 2044 size_t elemSize1() const;
joeverbout 0:ea44dc9ed014 2045 int type() const;
joeverbout 0:ea44dc9ed014 2046 int depth() const;
joeverbout 0:ea44dc9ed014 2047 int channels() const;
joeverbout 0:ea44dc9ed014 2048 size_t step1(int i=0) const;
joeverbout 0:ea44dc9ed014 2049 //! returns step()/sizeof(_Tp)
joeverbout 0:ea44dc9ed014 2050 size_t stepT(int i=0) const;
joeverbout 0:ea44dc9ed014 2051
joeverbout 0:ea44dc9ed014 2052 //! overridden forms of Mat::zeros() etc. Data type is omitted, of course
joeverbout 0:ea44dc9ed014 2053 static MatExpr zeros(int rows, int cols);
joeverbout 0:ea44dc9ed014 2054 static MatExpr zeros(Size size);
joeverbout 0:ea44dc9ed014 2055 static MatExpr zeros(int _ndims, const int* _sizes);
joeverbout 0:ea44dc9ed014 2056 static MatExpr ones(int rows, int cols);
joeverbout 0:ea44dc9ed014 2057 static MatExpr ones(Size size);
joeverbout 0:ea44dc9ed014 2058 static MatExpr ones(int _ndims, const int* _sizes);
joeverbout 0:ea44dc9ed014 2059 static MatExpr eye(int rows, int cols);
joeverbout 0:ea44dc9ed014 2060 static MatExpr eye(Size size);
joeverbout 0:ea44dc9ed014 2061
joeverbout 0:ea44dc9ed014 2062 //! some more overriden methods
joeverbout 0:ea44dc9ed014 2063 Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright );
joeverbout 0:ea44dc9ed014 2064 Mat_ operator()( const Range& rowRange, const Range& colRange ) const;
joeverbout 0:ea44dc9ed014 2065 Mat_ operator()( const Rect& roi ) const;
joeverbout 0:ea44dc9ed014 2066 Mat_ operator()( const Range* ranges ) const;
joeverbout 0:ea44dc9ed014 2067
joeverbout 0:ea44dc9ed014 2068 //! more convenient forms of row and element access operators
joeverbout 0:ea44dc9ed014 2069 _Tp* operator [](int y);
joeverbout 0:ea44dc9ed014 2070 const _Tp* operator [](int y) const;
joeverbout 0:ea44dc9ed014 2071
joeverbout 0:ea44dc9ed014 2072 //! returns reference to the specified element
joeverbout 0:ea44dc9ed014 2073 _Tp& operator ()(const int* idx);
joeverbout 0:ea44dc9ed014 2074 //! returns read-only reference to the specified element
joeverbout 0:ea44dc9ed014 2075 const _Tp& operator ()(const int* idx) const;
joeverbout 0:ea44dc9ed014 2076
joeverbout 0:ea44dc9ed014 2077 //! returns reference to the specified element
joeverbout 0:ea44dc9ed014 2078 template<int n> _Tp& operator ()(const Vec<int, n>& idx);
joeverbout 0:ea44dc9ed014 2079 //! returns read-only reference to the specified element
joeverbout 0:ea44dc9ed014 2080 template<int n> const _Tp& operator ()(const Vec<int, n>& idx) const;
joeverbout 0:ea44dc9ed014 2081
joeverbout 0:ea44dc9ed014 2082 //! returns reference to the specified element (1D case)
joeverbout 0:ea44dc9ed014 2083 _Tp& operator ()(int idx0);
joeverbout 0:ea44dc9ed014 2084 //! returns read-only reference to the specified element (1D case)
joeverbout 0:ea44dc9ed014 2085 const _Tp& operator ()(int idx0) const;
joeverbout 0:ea44dc9ed014 2086 //! returns reference to the specified element (2D case)
joeverbout 0:ea44dc9ed014 2087 _Tp& operator ()(int idx0, int idx1);
joeverbout 0:ea44dc9ed014 2088 //! returns read-only reference to the specified element (2D case)
joeverbout 0:ea44dc9ed014 2089 const _Tp& operator ()(int idx0, int idx1) const;
joeverbout 0:ea44dc9ed014 2090 //! returns reference to the specified element (3D case)
joeverbout 0:ea44dc9ed014 2091 _Tp& operator ()(int idx0, int idx1, int idx2);
joeverbout 0:ea44dc9ed014 2092 //! returns read-only reference to the specified element (3D case)
joeverbout 0:ea44dc9ed014 2093 const _Tp& operator ()(int idx0, int idx1, int idx2) const;
joeverbout 0:ea44dc9ed014 2094
joeverbout 0:ea44dc9ed014 2095 _Tp& operator ()(Point pt);
joeverbout 0:ea44dc9ed014 2096 const _Tp& operator ()(Point pt) const;
joeverbout 0:ea44dc9ed014 2097
joeverbout 0:ea44dc9ed014 2098 //! conversion to vector.
joeverbout 0:ea44dc9ed014 2099 operator std::vector<_Tp>() const;
joeverbout 0:ea44dc9ed014 2100 //! conversion to Vec
joeverbout 0:ea44dc9ed014 2101 template<int n> operator Vec<typename DataType<_Tp>::channel_type, n>() const;
joeverbout 0:ea44dc9ed014 2102 //! conversion to Matx
joeverbout 0:ea44dc9ed014 2103 template<int m, int n> operator Matx<typename DataType<_Tp>::channel_type, m, n>() const;
joeverbout 0:ea44dc9ed014 2104
joeverbout 0:ea44dc9ed014 2105 #ifdef CV_CXX_MOVE_SEMANTICS
joeverbout 0:ea44dc9ed014 2106 Mat_(Mat_&& m);
joeverbout 0:ea44dc9ed014 2107 Mat_& operator = (Mat_&& m);
joeverbout 0:ea44dc9ed014 2108
joeverbout 0:ea44dc9ed014 2109 Mat_(Mat&& m);
joeverbout 0:ea44dc9ed014 2110 Mat_& operator = (Mat&& m);
joeverbout 0:ea44dc9ed014 2111
joeverbout 0:ea44dc9ed014 2112 Mat_(MatExpr&& e);
joeverbout 0:ea44dc9ed014 2113 #endif
joeverbout 0:ea44dc9ed014 2114 };
joeverbout 0:ea44dc9ed014 2115
joeverbout 0:ea44dc9ed014 2116 typedef Mat_<uchar> Mat1b;
joeverbout 0:ea44dc9ed014 2117 typedef Mat_<Vec2b> Mat2b;
joeverbout 0:ea44dc9ed014 2118 typedef Mat_<Vec3b> Mat3b;
joeverbout 0:ea44dc9ed014 2119 typedef Mat_<Vec4b> Mat4b;
joeverbout 0:ea44dc9ed014 2120
joeverbout 0:ea44dc9ed014 2121 typedef Mat_<short> Mat1s;
joeverbout 0:ea44dc9ed014 2122 typedef Mat_<Vec2s> Mat2s;
joeverbout 0:ea44dc9ed014 2123 typedef Mat_<Vec3s> Mat3s;
joeverbout 0:ea44dc9ed014 2124 typedef Mat_<Vec4s> Mat4s;
joeverbout 0:ea44dc9ed014 2125
joeverbout 0:ea44dc9ed014 2126 typedef Mat_<ushort> Mat1w;
joeverbout 0:ea44dc9ed014 2127 typedef Mat_<Vec2w> Mat2w;
joeverbout 0:ea44dc9ed014 2128 typedef Mat_<Vec3w> Mat3w;
joeverbout 0:ea44dc9ed014 2129 typedef Mat_<Vec4w> Mat4w;
joeverbout 0:ea44dc9ed014 2130
joeverbout 0:ea44dc9ed014 2131 typedef Mat_<int> Mat1i;
joeverbout 0:ea44dc9ed014 2132 typedef Mat_<Vec2i> Mat2i;
joeverbout 0:ea44dc9ed014 2133 typedef Mat_<Vec3i> Mat3i;
joeverbout 0:ea44dc9ed014 2134 typedef Mat_<Vec4i> Mat4i;
joeverbout 0:ea44dc9ed014 2135
joeverbout 0:ea44dc9ed014 2136 typedef Mat_<float> Mat1f;
joeverbout 0:ea44dc9ed014 2137 typedef Mat_<Vec2f> Mat2f;
joeverbout 0:ea44dc9ed014 2138 typedef Mat_<Vec3f> Mat3f;
joeverbout 0:ea44dc9ed014 2139 typedef Mat_<Vec4f> Mat4f;
joeverbout 0:ea44dc9ed014 2140
joeverbout 0:ea44dc9ed014 2141 typedef Mat_<double> Mat1d;
joeverbout 0:ea44dc9ed014 2142 typedef Mat_<Vec2d> Mat2d;
joeverbout 0:ea44dc9ed014 2143 typedef Mat_<Vec3d> Mat3d;
joeverbout 0:ea44dc9ed014 2144 typedef Mat_<Vec4d> Mat4d;
joeverbout 0:ea44dc9ed014 2145
joeverbout 0:ea44dc9ed014 2146 /** @todo document */
joeverbout 0:ea44dc9ed014 2147 class CV_EXPORTS UMat
joeverbout 0:ea44dc9ed014 2148 {
joeverbout 0:ea44dc9ed014 2149 public:
joeverbout 0:ea44dc9ed014 2150 //! default constructor
joeverbout 0:ea44dc9ed014 2151 UMat(UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2152 //! constructs 2D matrix of the specified size and type
joeverbout 0:ea44dc9ed014 2153 // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
joeverbout 0:ea44dc9ed014 2154 UMat(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2155 UMat(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2156 //! constucts 2D matrix and fills it with the specified value _s.
joeverbout 0:ea44dc9ed014 2157 UMat(int rows, int cols, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2158 UMat(Size size, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2159
joeverbout 0:ea44dc9ed014 2160 //! constructs n-dimensional matrix
joeverbout 0:ea44dc9ed014 2161 UMat(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2162 UMat(int ndims, const int* sizes, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2163
joeverbout 0:ea44dc9ed014 2164 //! copy constructor
joeverbout 0:ea44dc9ed014 2165 UMat(const UMat& m);
joeverbout 0:ea44dc9ed014 2166
joeverbout 0:ea44dc9ed014 2167 //! creates a matrix header for a part of the bigger matrix
joeverbout 0:ea44dc9ed014 2168 UMat(const UMat& m, const Range& rowRange, const Range& colRange=Range::all());
joeverbout 0:ea44dc9ed014 2169 UMat(const UMat& m, const Rect& roi);
joeverbout 0:ea44dc9ed014 2170 UMat(const UMat& m, const Range* ranges);
joeverbout 0:ea44dc9ed014 2171 //! builds matrix from std::vector with or without copying the data
joeverbout 0:ea44dc9ed014 2172 template<typename _Tp> explicit UMat(const std::vector<_Tp>& vec, bool copyData=false);
joeverbout 0:ea44dc9ed014 2173 //! builds matrix from cv::Vec; the data is copied by default
joeverbout 0:ea44dc9ed014 2174 template<typename _Tp, int n> explicit UMat(const Vec<_Tp, n>& vec, bool copyData=true);
joeverbout 0:ea44dc9ed014 2175 //! builds matrix from cv::Matx; the data is copied by default
joeverbout 0:ea44dc9ed014 2176 template<typename _Tp, int m, int n> explicit UMat(const Matx<_Tp, m, n>& mtx, bool copyData=true);
joeverbout 0:ea44dc9ed014 2177 //! builds matrix from a 2D point
joeverbout 0:ea44dc9ed014 2178 template<typename _Tp> explicit UMat(const Point_<_Tp>& pt, bool copyData=true);
joeverbout 0:ea44dc9ed014 2179 //! builds matrix from a 3D point
joeverbout 0:ea44dc9ed014 2180 template<typename _Tp> explicit UMat(const Point3_<_Tp>& pt, bool copyData=true);
joeverbout 0:ea44dc9ed014 2181 //! builds matrix from comma initializer
joeverbout 0:ea44dc9ed014 2182 template<typename _Tp> explicit UMat(const MatCommaInitializer_<_Tp>& commaInitializer);
joeverbout 0:ea44dc9ed014 2183
joeverbout 0:ea44dc9ed014 2184 //! destructor - calls release()
joeverbout 0:ea44dc9ed014 2185 ~UMat();
joeverbout 0:ea44dc9ed014 2186 //! assignment operators
joeverbout 0:ea44dc9ed014 2187 UMat& operator = (const UMat& m);
joeverbout 0:ea44dc9ed014 2188
joeverbout 0:ea44dc9ed014 2189 Mat getMat(int flags) const;
joeverbout 0:ea44dc9ed014 2190
joeverbout 0:ea44dc9ed014 2191 //! returns a new matrix header for the specified row
joeverbout 0:ea44dc9ed014 2192 UMat row(int y) const;
joeverbout 0:ea44dc9ed014 2193 //! returns a new matrix header for the specified column
joeverbout 0:ea44dc9ed014 2194 UMat col(int x) const;
joeverbout 0:ea44dc9ed014 2195 //! ... for the specified row span
joeverbout 0:ea44dc9ed014 2196 UMat rowRange(int startrow, int endrow) const;
joeverbout 0:ea44dc9ed014 2197 UMat rowRange(const Range& r) const;
joeverbout 0:ea44dc9ed014 2198 //! ... for the specified column span
joeverbout 0:ea44dc9ed014 2199 UMat colRange(int startcol, int endcol) const;
joeverbout 0:ea44dc9ed014 2200 UMat colRange(const Range& r) const;
joeverbout 0:ea44dc9ed014 2201 //! ... for the specified diagonal
joeverbout 0:ea44dc9ed014 2202 // (d=0 - the main diagonal,
joeverbout 0:ea44dc9ed014 2203 // >0 - a diagonal from the lower half,
joeverbout 0:ea44dc9ed014 2204 // <0 - a diagonal from the upper half)
joeverbout 0:ea44dc9ed014 2205 UMat diag(int d=0) const;
joeverbout 0:ea44dc9ed014 2206 //! constructs a square diagonal matrix which main diagonal is vector "d"
joeverbout 0:ea44dc9ed014 2207 static UMat diag(const UMat& d);
joeverbout 0:ea44dc9ed014 2208
joeverbout 0:ea44dc9ed014 2209 //! returns deep copy of the matrix, i.e. the data is copied
joeverbout 0:ea44dc9ed014 2210 UMat clone() const;
joeverbout 0:ea44dc9ed014 2211 //! copies the matrix content to "m".
joeverbout 0:ea44dc9ed014 2212 // It calls m.create(this->size(), this->type()).
joeverbout 0:ea44dc9ed014 2213 void copyTo( OutputArray m ) const;
joeverbout 0:ea44dc9ed014 2214 //! copies those matrix elements to "m" that are marked with non-zero mask elements.
joeverbout 0:ea44dc9ed014 2215 void copyTo( OutputArray m, InputArray mask ) const;
joeverbout 0:ea44dc9ed014 2216 //! converts matrix to another datatype with optional scalng. See cvConvertScale.
joeverbout 0:ea44dc9ed014 2217 void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const;
joeverbout 0:ea44dc9ed014 2218
joeverbout 0:ea44dc9ed014 2219 void assignTo( UMat& m, int type=-1 ) const;
joeverbout 0:ea44dc9ed014 2220
joeverbout 0:ea44dc9ed014 2221 //! sets every matrix element to s
joeverbout 0:ea44dc9ed014 2222 UMat& operator = (const Scalar& s);
joeverbout 0:ea44dc9ed014 2223 //! sets some of the matrix elements to s, according to the mask
joeverbout 0:ea44dc9ed014 2224 UMat& setTo(InputArray value, InputArray mask=noArray());
joeverbout 0:ea44dc9ed014 2225 //! creates alternative matrix header for the same data, with different
joeverbout 0:ea44dc9ed014 2226 // number of channels and/or different number of rows. see cvReshape.
joeverbout 0:ea44dc9ed014 2227 UMat reshape(int cn, int rows=0) const;
joeverbout 0:ea44dc9ed014 2228 UMat reshape(int cn, int newndims, const int* newsz) const;
joeverbout 0:ea44dc9ed014 2229
joeverbout 0:ea44dc9ed014 2230 //! matrix transposition by means of matrix expressions
joeverbout 0:ea44dc9ed014 2231 UMat t() const;
joeverbout 0:ea44dc9ed014 2232 //! matrix inversion by means of matrix expressions
joeverbout 0:ea44dc9ed014 2233 UMat inv(int method=DECOMP_LU) const;
joeverbout 0:ea44dc9ed014 2234 //! per-element matrix multiplication by means of matrix expressions
joeverbout 0:ea44dc9ed014 2235 UMat mul(InputArray m, double scale=1) const;
joeverbout 0:ea44dc9ed014 2236
joeverbout 0:ea44dc9ed014 2237 //! computes dot-product
joeverbout 0:ea44dc9ed014 2238 double dot(InputArray m) const;
joeverbout 0:ea44dc9ed014 2239
joeverbout 0:ea44dc9ed014 2240 //! Matlab-style matrix initialization
joeverbout 0:ea44dc9ed014 2241 static UMat zeros(int rows, int cols, int type);
joeverbout 0:ea44dc9ed014 2242 static UMat zeros(Size size, int type);
joeverbout 0:ea44dc9ed014 2243 static UMat zeros(int ndims, const int* sz, int type);
joeverbout 0:ea44dc9ed014 2244 static UMat ones(int rows, int cols, int type);
joeverbout 0:ea44dc9ed014 2245 static UMat ones(Size size, int type);
joeverbout 0:ea44dc9ed014 2246 static UMat ones(int ndims, const int* sz, int type);
joeverbout 0:ea44dc9ed014 2247 static UMat eye(int rows, int cols, int type);
joeverbout 0:ea44dc9ed014 2248 static UMat eye(Size size, int type);
joeverbout 0:ea44dc9ed014 2249
joeverbout 0:ea44dc9ed014 2250 //! allocates new matrix data unless the matrix already has specified size and type.
joeverbout 0:ea44dc9ed014 2251 // previous data is unreferenced if needed.
joeverbout 0:ea44dc9ed014 2252 void create(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2253 void create(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2254 void create(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
joeverbout 0:ea44dc9ed014 2255
joeverbout 0:ea44dc9ed014 2256 //! increases the reference counter; use with care to avoid memleaks
joeverbout 0:ea44dc9ed014 2257 void addref();
joeverbout 0:ea44dc9ed014 2258 //! decreases reference counter;
joeverbout 0:ea44dc9ed014 2259 // deallocates the data when reference counter reaches 0.
joeverbout 0:ea44dc9ed014 2260 void release();
joeverbout 0:ea44dc9ed014 2261
joeverbout 0:ea44dc9ed014 2262 //! deallocates the matrix data
joeverbout 0:ea44dc9ed014 2263 void deallocate();
joeverbout 0:ea44dc9ed014 2264 //! internal use function; properly re-allocates _size, _step arrays
joeverbout 0:ea44dc9ed014 2265 void copySize(const UMat& m);
joeverbout 0:ea44dc9ed014 2266
joeverbout 0:ea44dc9ed014 2267 //! locates matrix header within a parent matrix. See below
joeverbout 0:ea44dc9ed014 2268 void locateROI( Size& wholeSize, Point& ofs ) const;
joeverbout 0:ea44dc9ed014 2269 //! moves/resizes the current matrix ROI inside the parent matrix.
joeverbout 0:ea44dc9ed014 2270 UMat& adjustROI( int dtop, int dbottom, int dleft, int dright );
joeverbout 0:ea44dc9ed014 2271 //! extracts a rectangular sub-matrix
joeverbout 0:ea44dc9ed014 2272 // (this is a generalized form of row, rowRange etc.)
joeverbout 0:ea44dc9ed014 2273 UMat operator()( Range rowRange, Range colRange ) const;
joeverbout 0:ea44dc9ed014 2274 UMat operator()( const Rect& roi ) const;
joeverbout 0:ea44dc9ed014 2275 UMat operator()( const Range* ranges ) const;
joeverbout 0:ea44dc9ed014 2276
joeverbout 0:ea44dc9ed014 2277 //! returns true iff the matrix data is continuous
joeverbout 0:ea44dc9ed014 2278 // (i.e. when there are no gaps between successive rows).
joeverbout 0:ea44dc9ed014 2279 // similar to CV_IS_MAT_CONT(cvmat->type)
joeverbout 0:ea44dc9ed014 2280 bool isContinuous() const;
joeverbout 0:ea44dc9ed014 2281
joeverbout 0:ea44dc9ed014 2282 //! returns true if the matrix is a submatrix of another matrix
joeverbout 0:ea44dc9ed014 2283 bool isSubmatrix() const;
joeverbout 0:ea44dc9ed014 2284
joeverbout 0:ea44dc9ed014 2285 //! returns element size in bytes,
joeverbout 0:ea44dc9ed014 2286 // similar to CV_ELEM_SIZE(cvmat->type)
joeverbout 0:ea44dc9ed014 2287 size_t elemSize() const;
joeverbout 0:ea44dc9ed014 2288 //! returns the size of element channel in bytes.
joeverbout 0:ea44dc9ed014 2289 size_t elemSize1() const;
joeverbout 0:ea44dc9ed014 2290 //! returns element type, similar to CV_MAT_TYPE(cvmat->type)
joeverbout 0:ea44dc9ed014 2291 int type() const;
joeverbout 0:ea44dc9ed014 2292 //! returns element type, similar to CV_MAT_DEPTH(cvmat->type)
joeverbout 0:ea44dc9ed014 2293 int depth() const;
joeverbout 0:ea44dc9ed014 2294 //! returns element type, similar to CV_MAT_CN(cvmat->type)
joeverbout 0:ea44dc9ed014 2295 int channels() const;
joeverbout 0:ea44dc9ed014 2296 //! returns step/elemSize1()
joeverbout 0:ea44dc9ed014 2297 size_t step1(int i=0) const;
joeverbout 0:ea44dc9ed014 2298 //! returns true if matrix data is NULL
joeverbout 0:ea44dc9ed014 2299 bool empty() const;
joeverbout 0:ea44dc9ed014 2300 //! returns the total number of matrix elements
joeverbout 0:ea44dc9ed014 2301 size_t total() const;
joeverbout 0:ea44dc9ed014 2302
joeverbout 0:ea44dc9ed014 2303 //! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise
joeverbout 0:ea44dc9ed014 2304 int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const;
joeverbout 0:ea44dc9ed014 2305
joeverbout 0:ea44dc9ed014 2306 #ifdef CV_CXX_MOVE_SEMANTICS
joeverbout 0:ea44dc9ed014 2307 UMat(UMat&& m);
joeverbout 0:ea44dc9ed014 2308 UMat& operator = (UMat&& m);
joeverbout 0:ea44dc9ed014 2309 #endif
joeverbout 0:ea44dc9ed014 2310
joeverbout 0:ea44dc9ed014 2311 void* handle(int accessFlags) const;
joeverbout 0:ea44dc9ed014 2312 void ndoffset(size_t* ofs) const;
joeverbout 0:ea44dc9ed014 2313
joeverbout 0:ea44dc9ed014 2314 enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG };
joeverbout 0:ea44dc9ed014 2315 enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 };
joeverbout 0:ea44dc9ed014 2316
joeverbout 0:ea44dc9ed014 2317 /*! includes several bit-fields:
joeverbout 0:ea44dc9ed014 2318 - the magic signature
joeverbout 0:ea44dc9ed014 2319 - continuity flag
joeverbout 0:ea44dc9ed014 2320 - depth
joeverbout 0:ea44dc9ed014 2321 - number of channels
joeverbout 0:ea44dc9ed014 2322 */
joeverbout 0:ea44dc9ed014 2323 int flags;
joeverbout 0:ea44dc9ed014 2324 //! the matrix dimensionality, >= 2
joeverbout 0:ea44dc9ed014 2325 int dims;
joeverbout 0:ea44dc9ed014 2326 //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
joeverbout 0:ea44dc9ed014 2327 int rows, cols;
joeverbout 0:ea44dc9ed014 2328
joeverbout 0:ea44dc9ed014 2329 //! custom allocator
joeverbout 0:ea44dc9ed014 2330 MatAllocator* allocator;
joeverbout 0:ea44dc9ed014 2331 UMatUsageFlags usageFlags; // usage flags for allocator
joeverbout 0:ea44dc9ed014 2332 //! and the standard allocator
joeverbout 0:ea44dc9ed014 2333 static MatAllocator* getStdAllocator();
joeverbout 0:ea44dc9ed014 2334
joeverbout 0:ea44dc9ed014 2335 // black-box container of UMat data
joeverbout 0:ea44dc9ed014 2336 UMatData* u;
joeverbout 0:ea44dc9ed014 2337
joeverbout 0:ea44dc9ed014 2338 // offset of the submatrix (or 0)
joeverbout 0:ea44dc9ed014 2339 size_t offset;
joeverbout 0:ea44dc9ed014 2340
joeverbout 0:ea44dc9ed014 2341 MatSize size;
joeverbout 0:ea44dc9ed014 2342 MatStep step;
joeverbout 0:ea44dc9ed014 2343
joeverbout 0:ea44dc9ed014 2344 protected:
joeverbout 0:ea44dc9ed014 2345 };
joeverbout 0:ea44dc9ed014 2346
joeverbout 0:ea44dc9ed014 2347
joeverbout 0:ea44dc9ed014 2348 /////////////////////////// multi-dimensional sparse matrix //////////////////////////
joeverbout 0:ea44dc9ed014 2349
joeverbout 0:ea44dc9ed014 2350 /** @brief The class SparseMat represents multi-dimensional sparse numerical arrays.
joeverbout 0:ea44dc9ed014 2351
joeverbout 0:ea44dc9ed014 2352 Such a sparse array can store elements of any type that Mat can store. *Sparse* means that only
joeverbout 0:ea44dc9ed014 2353 non-zero elements are stored (though, as a result of operations on a sparse matrix, some of its
joeverbout 0:ea44dc9ed014 2354 stored elements can actually become 0. It is up to you to detect such elements and delete them
joeverbout 0:ea44dc9ed014 2355 using SparseMat::erase ). The non-zero elements are stored in a hash table that grows when it is
joeverbout 0:ea44dc9ed014 2356 filled so that the search time is O(1) in average (regardless of whether element is there or not).
joeverbout 0:ea44dc9ed014 2357 Elements can be accessed using the following methods:
joeverbout 0:ea44dc9ed014 2358 - Query operations (SparseMat::ptr and the higher-level SparseMat::ref, SparseMat::value and
joeverbout 0:ea44dc9ed014 2359 SparseMat::find), for example:
joeverbout 0:ea44dc9ed014 2360 @code
joeverbout 0:ea44dc9ed014 2361 const int dims = 5;
joeverbout 0:ea44dc9ed014 2362 int size[] = {10, 10, 10, 10, 10};
joeverbout 0:ea44dc9ed014 2363 SparseMat sparse_mat(dims, size, CV_32F);
joeverbout 0:ea44dc9ed014 2364 for(int i = 0; i < 1000; i++)
joeverbout 0:ea44dc9ed014 2365 {
joeverbout 0:ea44dc9ed014 2366 int idx[dims];
joeverbout 0:ea44dc9ed014 2367 for(int k = 0; k < dims; k++)
joeverbout 0:ea44dc9ed014 2368 idx[k] = rand()
joeverbout 0:ea44dc9ed014 2369 sparse_mat.ref<float>(idx) += 1.f;
joeverbout 0:ea44dc9ed014 2370 }
joeverbout 0:ea44dc9ed014 2371 @endcode
joeverbout 0:ea44dc9ed014 2372 - Sparse matrix iterators. They are similar to MatIterator but different from NAryMatIterator.
joeverbout 0:ea44dc9ed014 2373 That is, the iteration loop is familiar to STL users:
joeverbout 0:ea44dc9ed014 2374 @code
joeverbout 0:ea44dc9ed014 2375 // prints elements of a sparse floating-point matrix
joeverbout 0:ea44dc9ed014 2376 // and the sum of elements.
joeverbout 0:ea44dc9ed014 2377 SparseMatConstIterator_<float>
joeverbout 0:ea44dc9ed014 2378 it = sparse_mat.begin<float>(),
joeverbout 0:ea44dc9ed014 2379 it_end = sparse_mat.end<float>();
joeverbout 0:ea44dc9ed014 2380 double s = 0;
joeverbout 0:ea44dc9ed014 2381 int dims = sparse_mat.dims();
joeverbout 0:ea44dc9ed014 2382 for(; it != it_end; ++it)
joeverbout 0:ea44dc9ed014 2383 {
joeverbout 0:ea44dc9ed014 2384 // print element indices and the element value
joeverbout 0:ea44dc9ed014 2385 const SparseMat::Node* n = it.node();
joeverbout 0:ea44dc9ed014 2386 printf("(");
joeverbout 0:ea44dc9ed014 2387 for(int i = 0; i < dims; i++)
joeverbout 0:ea44dc9ed014 2388 printf("%d%s", n->idx[i], i < dims-1 ? ", " : ")");
joeverbout 0:ea44dc9ed014 2389 printf(": %g\n", it.value<float>());
joeverbout 0:ea44dc9ed014 2390 s += *it;
joeverbout 0:ea44dc9ed014 2391 }
joeverbout 0:ea44dc9ed014 2392 printf("Element sum is %g\n", s);
joeverbout 0:ea44dc9ed014 2393 @endcode
joeverbout 0:ea44dc9ed014 2394 If you run this loop, you will notice that elements are not enumerated in a logical order
joeverbout 0:ea44dc9ed014 2395 (lexicographical, and so on). They come in the same order as they are stored in the hash table
joeverbout 0:ea44dc9ed014 2396 (semi-randomly). You may collect pointers to the nodes and sort them to get the proper ordering.
joeverbout 0:ea44dc9ed014 2397 Note, however, that pointers to the nodes may become invalid when you add more elements to the
joeverbout 0:ea44dc9ed014 2398 matrix. This may happen due to possible buffer reallocation.
joeverbout 0:ea44dc9ed014 2399 - Combination of the above 2 methods when you need to process 2 or more sparse matrices
joeverbout 0:ea44dc9ed014 2400 simultaneously. For example, this is how you can compute unnormalized cross-correlation of the 2
joeverbout 0:ea44dc9ed014 2401 floating-point sparse matrices:
joeverbout 0:ea44dc9ed014 2402 @code
joeverbout 0:ea44dc9ed014 2403 double cross_corr(const SparseMat& a, const SparseMat& b)
joeverbout 0:ea44dc9ed014 2404 {
joeverbout 0:ea44dc9ed014 2405 const SparseMat *_a = &a, *_b = &b;
joeverbout 0:ea44dc9ed014 2406 // if b contains less elements than a,
joeverbout 0:ea44dc9ed014 2407 // it is faster to iterate through b
joeverbout 0:ea44dc9ed014 2408 if(_a->nzcount() > _b->nzcount())
joeverbout 0:ea44dc9ed014 2409 std::swap(_a, _b);
joeverbout 0:ea44dc9ed014 2410 SparseMatConstIterator_<float> it = _a->begin<float>(),
joeverbout 0:ea44dc9ed014 2411 it_end = _a->end<float>();
joeverbout 0:ea44dc9ed014 2412 double ccorr = 0;
joeverbout 0:ea44dc9ed014 2413 for(; it != it_end; ++it)
joeverbout 0:ea44dc9ed014 2414 {
joeverbout 0:ea44dc9ed014 2415 // take the next element from the first matrix
joeverbout 0:ea44dc9ed014 2416 float avalue = *it;
joeverbout 0:ea44dc9ed014 2417 const Node* anode = it.node();
joeverbout 0:ea44dc9ed014 2418 // and try to find an element with the same index in the second matrix.
joeverbout 0:ea44dc9ed014 2419 // since the hash value depends only on the element index,
joeverbout 0:ea44dc9ed014 2420 // reuse the hash value stored in the node
joeverbout 0:ea44dc9ed014 2421 float bvalue = _b->value<float>(anode->idx,&anode->hashval);
joeverbout 0:ea44dc9ed014 2422 ccorr += avalue*bvalue;
joeverbout 0:ea44dc9ed014 2423 }
joeverbout 0:ea44dc9ed014 2424 return ccorr;
joeverbout 0:ea44dc9ed014 2425 }
joeverbout 0:ea44dc9ed014 2426 @endcode
joeverbout 0:ea44dc9ed014 2427 */
joeverbout 0:ea44dc9ed014 2428 class CV_EXPORTS SparseMat
joeverbout 0:ea44dc9ed014 2429 {
joeverbout 0:ea44dc9ed014 2430 public:
joeverbout 0:ea44dc9ed014 2431 typedef SparseMatIterator iterator;
joeverbout 0:ea44dc9ed014 2432 typedef SparseMatConstIterator const_iterator;
joeverbout 0:ea44dc9ed014 2433
joeverbout 0:ea44dc9ed014 2434 enum { MAGIC_VAL=0x42FD0000, MAX_DIM=32, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 };
joeverbout 0:ea44dc9ed014 2435
joeverbout 0:ea44dc9ed014 2436 //! the sparse matrix header
joeverbout 0:ea44dc9ed014 2437 struct CV_EXPORTS Hdr
joeverbout 0:ea44dc9ed014 2438 {
joeverbout 0:ea44dc9ed014 2439 Hdr(int _dims, const int* _sizes, int _type);
joeverbout 0:ea44dc9ed014 2440 void clear();
joeverbout 0:ea44dc9ed014 2441 int refcount;
joeverbout 0:ea44dc9ed014 2442 int dims;
joeverbout 0:ea44dc9ed014 2443 int valueOffset;
joeverbout 0:ea44dc9ed014 2444 size_t nodeSize;
joeverbout 0:ea44dc9ed014 2445 size_t nodeCount;
joeverbout 0:ea44dc9ed014 2446 size_t freeList;
joeverbout 0:ea44dc9ed014 2447 std::vector<uchar> pool;
joeverbout 0:ea44dc9ed014 2448 std::vector<size_t> hashtab;
joeverbout 0:ea44dc9ed014 2449 int size[MAX_DIM];
joeverbout 0:ea44dc9ed014 2450 };
joeverbout 0:ea44dc9ed014 2451
joeverbout 0:ea44dc9ed014 2452 //! sparse matrix node - element of a hash table
joeverbout 0:ea44dc9ed014 2453 struct CV_EXPORTS Node
joeverbout 0:ea44dc9ed014 2454 {
joeverbout 0:ea44dc9ed014 2455 //! hash value
joeverbout 0:ea44dc9ed014 2456 size_t hashval;
joeverbout 0:ea44dc9ed014 2457 //! index of the next node in the same hash table entry
joeverbout 0:ea44dc9ed014 2458 size_t next;
joeverbout 0:ea44dc9ed014 2459 //! index of the matrix element
joeverbout 0:ea44dc9ed014 2460 int idx[MAX_DIM];
joeverbout 0:ea44dc9ed014 2461 };
joeverbout 0:ea44dc9ed014 2462
joeverbout 0:ea44dc9ed014 2463 /** @brief Various SparseMat constructors.
joeverbout 0:ea44dc9ed014 2464 */
joeverbout 0:ea44dc9ed014 2465 SparseMat();
joeverbout 0:ea44dc9ed014 2466
joeverbout 0:ea44dc9ed014 2467 /** @overload
joeverbout 0:ea44dc9ed014 2468 @param dims Array dimensionality.
joeverbout 0:ea44dc9ed014 2469 @param _sizes Sparce matrix size on all dementions.
joeverbout 0:ea44dc9ed014 2470 @param _type Sparse matrix data type.
joeverbout 0:ea44dc9ed014 2471 */
joeverbout 0:ea44dc9ed014 2472 SparseMat(int dims, const int* _sizes, int _type);
joeverbout 0:ea44dc9ed014 2473
joeverbout 0:ea44dc9ed014 2474 /** @overload
joeverbout 0:ea44dc9ed014 2475 @param m Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted
joeverbout 0:ea44dc9ed014 2476 to sparse representation.
joeverbout 0:ea44dc9ed014 2477 */
joeverbout 0:ea44dc9ed014 2478 SparseMat(const SparseMat& m);
joeverbout 0:ea44dc9ed014 2479
joeverbout 0:ea44dc9ed014 2480 /** @overload
joeverbout 0:ea44dc9ed014 2481 @param m Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted
joeverbout 0:ea44dc9ed014 2482 to sparse representation.
joeverbout 0:ea44dc9ed014 2483 */
joeverbout 0:ea44dc9ed014 2484 explicit SparseMat(const Mat& m);
joeverbout 0:ea44dc9ed014 2485
joeverbout 0:ea44dc9ed014 2486 //! the destructor
joeverbout 0:ea44dc9ed014 2487 ~SparseMat();
joeverbout 0:ea44dc9ed014 2488
joeverbout 0:ea44dc9ed014 2489 //! assignment operator. This is O(1) operation, i.e. no data is copied
joeverbout 0:ea44dc9ed014 2490 SparseMat& operator = (const SparseMat& m);
joeverbout 0:ea44dc9ed014 2491 //! equivalent to the corresponding constructor
joeverbout 0:ea44dc9ed014 2492 SparseMat& operator = (const Mat& m);
joeverbout 0:ea44dc9ed014 2493
joeverbout 0:ea44dc9ed014 2494 //! creates full copy of the matrix
joeverbout 0:ea44dc9ed014 2495 SparseMat clone() const;
joeverbout 0:ea44dc9ed014 2496
joeverbout 0:ea44dc9ed014 2497 //! copies all the data to the destination matrix. All the previous content of m is erased
joeverbout 0:ea44dc9ed014 2498 void copyTo( SparseMat& m ) const;
joeverbout 0:ea44dc9ed014 2499 //! converts sparse matrix to dense matrix.
joeverbout 0:ea44dc9ed014 2500 void copyTo( Mat& m ) const;
joeverbout 0:ea44dc9ed014 2501 //! multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type
joeverbout 0:ea44dc9ed014 2502 void convertTo( SparseMat& m, int rtype, double alpha=1 ) const;
joeverbout 0:ea44dc9ed014 2503 //! converts sparse matrix to dense n-dim matrix with optional type conversion and scaling.
joeverbout 0:ea44dc9ed014 2504 /*!
joeverbout 0:ea44dc9ed014 2505 @param [out] m - output matrix; if it does not have a proper size or type before the operation,
joeverbout 0:ea44dc9ed014 2506 it is reallocated
joeverbout 0:ea44dc9ed014 2507 @param [in] rtype – desired output matrix type or, rather, the depth since the number of channels
joeverbout 0:ea44dc9ed014 2508 are the same as the input has; if rtype is negative, the output matrix will have the
joeverbout 0:ea44dc9ed014 2509 same type as the input.
joeverbout 0:ea44dc9ed014 2510 @param [in] alpha – optional scale factor
joeverbout 0:ea44dc9ed014 2511 @param [in] beta – optional delta added to the scaled values
joeverbout 0:ea44dc9ed014 2512 */
joeverbout 0:ea44dc9ed014 2513 void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
joeverbout 0:ea44dc9ed014 2514
joeverbout 0:ea44dc9ed014 2515 // not used now
joeverbout 0:ea44dc9ed014 2516 void assignTo( SparseMat& m, int type=-1 ) const;
joeverbout 0:ea44dc9ed014 2517
joeverbout 0:ea44dc9ed014 2518 //! reallocates sparse matrix.
joeverbout 0:ea44dc9ed014 2519 /*!
joeverbout 0:ea44dc9ed014 2520 If the matrix already had the proper size and type,
joeverbout 0:ea44dc9ed014 2521 it is simply cleared with clear(), otherwise,
joeverbout 0:ea44dc9ed014 2522 the old matrix is released (using release()) and the new one is allocated.
joeverbout 0:ea44dc9ed014 2523 */
joeverbout 0:ea44dc9ed014 2524 void create(int dims, const int* _sizes, int _type);
joeverbout 0:ea44dc9ed014 2525 //! sets all the sparse matrix elements to 0, which means clearing the hash table.
joeverbout 0:ea44dc9ed014 2526 void clear();
joeverbout 0:ea44dc9ed014 2527 //! manually increments the reference counter to the header.
joeverbout 0:ea44dc9ed014 2528 void addref();
joeverbout 0:ea44dc9ed014 2529 // decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated.
joeverbout 0:ea44dc9ed014 2530 void release();
joeverbout 0:ea44dc9ed014 2531
joeverbout 0:ea44dc9ed014 2532 //! converts sparse matrix to the old-style representation; all the elements are copied.
joeverbout 0:ea44dc9ed014 2533 //operator CvSparseMat*() const;
joeverbout 0:ea44dc9ed014 2534 //! returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements)
joeverbout 0:ea44dc9ed014 2535 size_t elemSize() const;
joeverbout 0:ea44dc9ed014 2536 //! returns elemSize()/channels()
joeverbout 0:ea44dc9ed014 2537 size_t elemSize1() const;
joeverbout 0:ea44dc9ed014 2538
joeverbout 0:ea44dc9ed014 2539 //! returns type of sparse matrix elements
joeverbout 0:ea44dc9ed014 2540 int type() const;
joeverbout 0:ea44dc9ed014 2541 //! returns the depth of sparse matrix elements
joeverbout 0:ea44dc9ed014 2542 int depth() const;
joeverbout 0:ea44dc9ed014 2543 //! returns the number of channels
joeverbout 0:ea44dc9ed014 2544 int channels() const;
joeverbout 0:ea44dc9ed014 2545
joeverbout 0:ea44dc9ed014 2546 //! returns the array of sizes, or NULL if the matrix is not allocated
joeverbout 0:ea44dc9ed014 2547 const int* size() const;
joeverbout 0:ea44dc9ed014 2548 //! returns the size of i-th matrix dimension (or 0)
joeverbout 0:ea44dc9ed014 2549 int size(int i) const;
joeverbout 0:ea44dc9ed014 2550 //! returns the matrix dimensionality
joeverbout 0:ea44dc9ed014 2551 int dims() const;
joeverbout 0:ea44dc9ed014 2552 //! returns the number of non-zero elements (=the number of hash table nodes)
joeverbout 0:ea44dc9ed014 2553 size_t nzcount() const;
joeverbout 0:ea44dc9ed014 2554
joeverbout 0:ea44dc9ed014 2555 //! computes the element hash value (1D case)
joeverbout 0:ea44dc9ed014 2556 size_t hash(int i0) const;
joeverbout 0:ea44dc9ed014 2557 //! computes the element hash value (2D case)
joeverbout 0:ea44dc9ed014 2558 size_t hash(int i0, int i1) const;
joeverbout 0:ea44dc9ed014 2559 //! computes the element hash value (3D case)
joeverbout 0:ea44dc9ed014 2560 size_t hash(int i0, int i1, int i2) const;
joeverbout 0:ea44dc9ed014 2561 //! computes the element hash value (nD case)
joeverbout 0:ea44dc9ed014 2562 size_t hash(const int* idx) const;
joeverbout 0:ea44dc9ed014 2563
joeverbout 0:ea44dc9ed014 2564 //!@{
joeverbout 0:ea44dc9ed014 2565 /*!
joeverbout 0:ea44dc9ed014 2566 specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D case.
joeverbout 0:ea44dc9ed014 2567 return pointer to the matrix element.
joeverbout 0:ea44dc9ed014 2568 - if the element is there (it's non-zero), the pointer to it is returned
joeverbout 0:ea44dc9ed014 2569 - if it's not there and createMissing=false, NULL pointer is returned
joeverbout 0:ea44dc9ed014 2570 - if it's not there and createMissing=true, then the new element
joeverbout 0:ea44dc9ed014 2571 is created and initialized with 0. Pointer to it is returned
joeverbout 0:ea44dc9ed014 2572 - if the optional hashval pointer is not NULL, the element hash value is
joeverbout 0:ea44dc9ed014 2573 not computed, but *hashval is taken instead.
joeverbout 0:ea44dc9ed014 2574 */
joeverbout 0:ea44dc9ed014 2575 //! returns pointer to the specified element (1D case)
joeverbout 0:ea44dc9ed014 2576 uchar* ptr(int i0, bool createMissing, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2577 //! returns pointer to the specified element (2D case)
joeverbout 0:ea44dc9ed014 2578 uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2579 //! returns pointer to the specified element (3D case)
joeverbout 0:ea44dc9ed014 2580 uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2581 //! returns pointer to the specified element (nD case)
joeverbout 0:ea44dc9ed014 2582 uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2583 //!@}
joeverbout 0:ea44dc9ed014 2584
joeverbout 0:ea44dc9ed014 2585 //!@{
joeverbout 0:ea44dc9ed014 2586 /*!
joeverbout 0:ea44dc9ed014 2587 return read-write reference to the specified sparse matrix element.
joeverbout 0:ea44dc9ed014 2588
joeverbout 0:ea44dc9ed014 2589 `ref<_Tp>(i0,...[,hashval])` is equivalent to `*(_Tp*)ptr(i0,...,true[,hashval])`.
joeverbout 0:ea44dc9ed014 2590 The methods always return a valid reference.
joeverbout 0:ea44dc9ed014 2591 If the element did not exist, it is created and initialiazed with 0.
joeverbout 0:ea44dc9ed014 2592 */
joeverbout 0:ea44dc9ed014 2593 //! returns reference to the specified element (1D case)
joeverbout 0:ea44dc9ed014 2594 template<typename _Tp> _Tp& ref(int i0, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2595 //! returns reference to the specified element (2D case)
joeverbout 0:ea44dc9ed014 2596 template<typename _Tp> _Tp& ref(int i0, int i1, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2597 //! returns reference to the specified element (3D case)
joeverbout 0:ea44dc9ed014 2598 template<typename _Tp> _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2599 //! returns reference to the specified element (nD case)
joeverbout 0:ea44dc9ed014 2600 template<typename _Tp> _Tp& ref(const int* idx, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2601 //!@}
joeverbout 0:ea44dc9ed014 2602
joeverbout 0:ea44dc9ed014 2603 //!@{
joeverbout 0:ea44dc9ed014 2604 /*!
joeverbout 0:ea44dc9ed014 2605 return value of the specified sparse matrix element.
joeverbout 0:ea44dc9ed014 2606
joeverbout 0:ea44dc9ed014 2607 `value<_Tp>(i0,...[,hashval])` is equivalent to
joeverbout 0:ea44dc9ed014 2608 @code
joeverbout 0:ea44dc9ed014 2609 { const _Tp* p = find<_Tp>(i0,...[,hashval]); return p ? *p : _Tp(); }
joeverbout 0:ea44dc9ed014 2610 @endcode
joeverbout 0:ea44dc9ed014 2611
joeverbout 0:ea44dc9ed014 2612 That is, if the element did not exist, the methods return 0.
joeverbout 0:ea44dc9ed014 2613 */
joeverbout 0:ea44dc9ed014 2614 //! returns value of the specified element (1D case)
joeverbout 0:ea44dc9ed014 2615 template<typename _Tp> _Tp value(int i0, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2616 //! returns value of the specified element (2D case)
joeverbout 0:ea44dc9ed014 2617 template<typename _Tp> _Tp value(int i0, int i1, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2618 //! returns value of the specified element (3D case)
joeverbout 0:ea44dc9ed014 2619 template<typename _Tp> _Tp value(int i0, int i1, int i2, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2620 //! returns value of the specified element (nD case)
joeverbout 0:ea44dc9ed014 2621 template<typename _Tp> _Tp value(const int* idx, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2622 //!@}
joeverbout 0:ea44dc9ed014 2623
joeverbout 0:ea44dc9ed014 2624 //!@{
joeverbout 0:ea44dc9ed014 2625 /*!
joeverbout 0:ea44dc9ed014 2626 Return pointer to the specified sparse matrix element if it exists
joeverbout 0:ea44dc9ed014 2627
joeverbout 0:ea44dc9ed014 2628 `find<_Tp>(i0,...[,hashval])` is equivalent to `(_const Tp*)ptr(i0,...false[,hashval])`.
joeverbout 0:ea44dc9ed014 2629
joeverbout 0:ea44dc9ed014 2630 If the specified element does not exist, the methods return NULL.
joeverbout 0:ea44dc9ed014 2631 */
joeverbout 0:ea44dc9ed014 2632 //! returns pointer to the specified element (1D case)
joeverbout 0:ea44dc9ed014 2633 template<typename _Tp> const _Tp* find(int i0, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2634 //! returns pointer to the specified element (2D case)
joeverbout 0:ea44dc9ed014 2635 template<typename _Tp> const _Tp* find(int i0, int i1, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2636 //! returns pointer to the specified element (3D case)
joeverbout 0:ea44dc9ed014 2637 template<typename _Tp> const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2638 //! returns pointer to the specified element (nD case)
joeverbout 0:ea44dc9ed014 2639 template<typename _Tp> const _Tp* find(const int* idx, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2640 //!@}
joeverbout 0:ea44dc9ed014 2641
joeverbout 0:ea44dc9ed014 2642 //! erases the specified element (2D case)
joeverbout 0:ea44dc9ed014 2643 void erase(int i0, int i1, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2644 //! erases the specified element (3D case)
joeverbout 0:ea44dc9ed014 2645 void erase(int i0, int i1, int i2, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2646 //! erases the specified element (nD case)
joeverbout 0:ea44dc9ed014 2647 void erase(const int* idx, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2648
joeverbout 0:ea44dc9ed014 2649 //!@{
joeverbout 0:ea44dc9ed014 2650 /*!
joeverbout 0:ea44dc9ed014 2651 return the sparse matrix iterator pointing to the first sparse matrix element
joeverbout 0:ea44dc9ed014 2652 */
joeverbout 0:ea44dc9ed014 2653 //! returns the sparse matrix iterator at the matrix beginning
joeverbout 0:ea44dc9ed014 2654 SparseMatIterator begin();
joeverbout 0:ea44dc9ed014 2655 //! returns the sparse matrix iterator at the matrix beginning
joeverbout 0:ea44dc9ed014 2656 template<typename _Tp> SparseMatIterator_<_Tp> begin();
joeverbout 0:ea44dc9ed014 2657 //! returns the read-only sparse matrix iterator at the matrix beginning
joeverbout 0:ea44dc9ed014 2658 SparseMatConstIterator begin() const;
joeverbout 0:ea44dc9ed014 2659 //! returns the read-only sparse matrix iterator at the matrix beginning
joeverbout 0:ea44dc9ed014 2660 template<typename _Tp> SparseMatConstIterator_<_Tp> begin() const;
joeverbout 0:ea44dc9ed014 2661 //!@}
joeverbout 0:ea44dc9ed014 2662 /*!
joeverbout 0:ea44dc9ed014 2663 return the sparse matrix iterator pointing to the element following the last sparse matrix element
joeverbout 0:ea44dc9ed014 2664 */
joeverbout 0:ea44dc9ed014 2665 //! returns the sparse matrix iterator at the matrix end
joeverbout 0:ea44dc9ed014 2666 SparseMatIterator end();
joeverbout 0:ea44dc9ed014 2667 //! returns the read-only sparse matrix iterator at the matrix end
joeverbout 0:ea44dc9ed014 2668 SparseMatConstIterator end() const;
joeverbout 0:ea44dc9ed014 2669 //! returns the typed sparse matrix iterator at the matrix end
joeverbout 0:ea44dc9ed014 2670 template<typename _Tp> SparseMatIterator_<_Tp> end();
joeverbout 0:ea44dc9ed014 2671 //! returns the typed read-only sparse matrix iterator at the matrix end
joeverbout 0:ea44dc9ed014 2672 template<typename _Tp> SparseMatConstIterator_<_Tp> end() const;
joeverbout 0:ea44dc9ed014 2673
joeverbout 0:ea44dc9ed014 2674 //! returns the value stored in the sparse martix node
joeverbout 0:ea44dc9ed014 2675 template<typename _Tp> _Tp& value(Node* n);
joeverbout 0:ea44dc9ed014 2676 //! returns the value stored in the sparse martix node
joeverbout 0:ea44dc9ed014 2677 template<typename _Tp> const _Tp& value(const Node* n) const;
joeverbout 0:ea44dc9ed014 2678
joeverbout 0:ea44dc9ed014 2679 ////////////// some internal-use methods ///////////////
joeverbout 0:ea44dc9ed014 2680 Node* node(size_t nidx);
joeverbout 0:ea44dc9ed014 2681 const Node* node(size_t nidx) const;
joeverbout 0:ea44dc9ed014 2682
joeverbout 0:ea44dc9ed014 2683 uchar* newNode(const int* idx, size_t hashval);
joeverbout 0:ea44dc9ed014 2684 void removeNode(size_t hidx, size_t nidx, size_t previdx);
joeverbout 0:ea44dc9ed014 2685 void resizeHashTab(size_t newsize);
joeverbout 0:ea44dc9ed014 2686
joeverbout 0:ea44dc9ed014 2687 int flags;
joeverbout 0:ea44dc9ed014 2688 Hdr* hdr;
joeverbout 0:ea44dc9ed014 2689 };
joeverbout 0:ea44dc9ed014 2690
joeverbout 0:ea44dc9ed014 2691
joeverbout 0:ea44dc9ed014 2692
joeverbout 0:ea44dc9ed014 2693 ///////////////////////////////// SparseMat_<_Tp> ////////////////////////////////////
joeverbout 0:ea44dc9ed014 2694
joeverbout 0:ea44dc9ed014 2695 /** @brief Template sparse n-dimensional array class derived from SparseMat
joeverbout 0:ea44dc9ed014 2696
joeverbout 0:ea44dc9ed014 2697 SparseMat_ is a thin wrapper on top of SparseMat created in the same way as Mat_ . It simplifies
joeverbout 0:ea44dc9ed014 2698 notation of some operations:
joeverbout 0:ea44dc9ed014 2699 @code
joeverbout 0:ea44dc9ed014 2700 int sz[] = {10, 20, 30};
joeverbout 0:ea44dc9ed014 2701 SparseMat_<double> M(3, sz);
joeverbout 0:ea44dc9ed014 2702 ...
joeverbout 0:ea44dc9ed014 2703 M.ref(1, 2, 3) = M(4, 5, 6) + M(7, 8, 9);
joeverbout 0:ea44dc9ed014 2704 @endcode
joeverbout 0:ea44dc9ed014 2705 */
joeverbout 0:ea44dc9ed014 2706 template<typename _Tp> class SparseMat_ : public SparseMat
joeverbout 0:ea44dc9ed014 2707 {
joeverbout 0:ea44dc9ed014 2708 public:
joeverbout 0:ea44dc9ed014 2709 typedef SparseMatIterator_<_Tp> iterator;
joeverbout 0:ea44dc9ed014 2710 typedef SparseMatConstIterator_<_Tp> const_iterator;
joeverbout 0:ea44dc9ed014 2711
joeverbout 0:ea44dc9ed014 2712 //! the default constructor
joeverbout 0:ea44dc9ed014 2713 SparseMat_();
joeverbout 0:ea44dc9ed014 2714 //! the full constructor equivelent to SparseMat(dims, _sizes, DataType<_Tp>::type)
joeverbout 0:ea44dc9ed014 2715 SparseMat_(int dims, const int* _sizes);
joeverbout 0:ea44dc9ed014 2716 //! the copy constructor. If DataType<_Tp>.type != m.type(), the m elements are converted
joeverbout 0:ea44dc9ed014 2717 SparseMat_(const SparseMat& m);
joeverbout 0:ea44dc9ed014 2718 //! the copy constructor. This is O(1) operation - no data is copied
joeverbout 0:ea44dc9ed014 2719 SparseMat_(const SparseMat_& m);
joeverbout 0:ea44dc9ed014 2720 //! converts dense matrix to the sparse form
joeverbout 0:ea44dc9ed014 2721 SparseMat_(const Mat& m);
joeverbout 0:ea44dc9ed014 2722 //! converts the old-style sparse matrix to the C++ class. All the elements are copied
joeverbout 0:ea44dc9ed014 2723 //SparseMat_(const CvSparseMat* m);
joeverbout 0:ea44dc9ed014 2724 //! the assignment operator. If DataType<_Tp>.type != m.type(), the m elements are converted
joeverbout 0:ea44dc9ed014 2725 SparseMat_& operator = (const SparseMat& m);
joeverbout 0:ea44dc9ed014 2726 //! the assignment operator. This is O(1) operation - no data is copied
joeverbout 0:ea44dc9ed014 2727 SparseMat_& operator = (const SparseMat_& m);
joeverbout 0:ea44dc9ed014 2728 //! converts dense matrix to the sparse form
joeverbout 0:ea44dc9ed014 2729 SparseMat_& operator = (const Mat& m);
joeverbout 0:ea44dc9ed014 2730
joeverbout 0:ea44dc9ed014 2731 //! makes full copy of the matrix. All the elements are duplicated
joeverbout 0:ea44dc9ed014 2732 SparseMat_ clone() const;
joeverbout 0:ea44dc9ed014 2733 //! equivalent to cv::SparseMat::create(dims, _sizes, DataType<_Tp>::type)
joeverbout 0:ea44dc9ed014 2734 void create(int dims, const int* _sizes);
joeverbout 0:ea44dc9ed014 2735 //! converts sparse matrix to the old-style CvSparseMat. All the elements are copied
joeverbout 0:ea44dc9ed014 2736 //operator CvSparseMat*() const;
joeverbout 0:ea44dc9ed014 2737
joeverbout 0:ea44dc9ed014 2738 //! returns type of the matrix elements
joeverbout 0:ea44dc9ed014 2739 int type() const;
joeverbout 0:ea44dc9ed014 2740 //! returns depth of the matrix elements
joeverbout 0:ea44dc9ed014 2741 int depth() const;
joeverbout 0:ea44dc9ed014 2742 //! returns the number of channels in each matrix element
joeverbout 0:ea44dc9ed014 2743 int channels() const;
joeverbout 0:ea44dc9ed014 2744
joeverbout 0:ea44dc9ed014 2745 //! equivalent to SparseMat::ref<_Tp>(i0, hashval)
joeverbout 0:ea44dc9ed014 2746 _Tp& ref(int i0, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2747 //! equivalent to SparseMat::ref<_Tp>(i0, i1, hashval)
joeverbout 0:ea44dc9ed014 2748 _Tp& ref(int i0, int i1, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2749 //! equivalent to SparseMat::ref<_Tp>(i0, i1, i2, hashval)
joeverbout 0:ea44dc9ed014 2750 _Tp& ref(int i0, int i1, int i2, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2751 //! equivalent to SparseMat::ref<_Tp>(idx, hashval)
joeverbout 0:ea44dc9ed014 2752 _Tp& ref(const int* idx, size_t* hashval=0);
joeverbout 0:ea44dc9ed014 2753
joeverbout 0:ea44dc9ed014 2754 //! equivalent to SparseMat::value<_Tp>(i0, hashval)
joeverbout 0:ea44dc9ed014 2755 _Tp operator()(int i0, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2756 //! equivalent to SparseMat::value<_Tp>(i0, i1, hashval)
joeverbout 0:ea44dc9ed014 2757 _Tp operator()(int i0, int i1, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2758 //! equivalent to SparseMat::value<_Tp>(i0, i1, i2, hashval)
joeverbout 0:ea44dc9ed014 2759 _Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2760 //! equivalent to SparseMat::value<_Tp>(idx, hashval)
joeverbout 0:ea44dc9ed014 2761 _Tp operator()(const int* idx, size_t* hashval=0) const;
joeverbout 0:ea44dc9ed014 2762
joeverbout 0:ea44dc9ed014 2763 //! returns sparse matrix iterator pointing to the first sparse matrix element
joeverbout 0:ea44dc9ed014 2764 SparseMatIterator_<_Tp> begin();
joeverbout 0:ea44dc9ed014 2765 //! returns read-only sparse matrix iterator pointing to the first sparse matrix element
joeverbout 0:ea44dc9ed014 2766 SparseMatConstIterator_<_Tp> begin() const;
joeverbout 0:ea44dc9ed014 2767 //! returns sparse matrix iterator pointing to the element following the last sparse matrix element
joeverbout 0:ea44dc9ed014 2768 SparseMatIterator_<_Tp> end();
joeverbout 0:ea44dc9ed014 2769 //! returns read-only sparse matrix iterator pointing to the element following the last sparse matrix element
joeverbout 0:ea44dc9ed014 2770 SparseMatConstIterator_<_Tp> end() const;
joeverbout 0:ea44dc9ed014 2771 };
joeverbout 0:ea44dc9ed014 2772
joeverbout 0:ea44dc9ed014 2773
joeverbout 0:ea44dc9ed014 2774
joeverbout 0:ea44dc9ed014 2775 ////////////////////////////////// MatConstIterator //////////////////////////////////
joeverbout 0:ea44dc9ed014 2776
joeverbout 0:ea44dc9ed014 2777 class CV_EXPORTS MatConstIterator
joeverbout 0:ea44dc9ed014 2778 {
joeverbout 0:ea44dc9ed014 2779 public:
joeverbout 0:ea44dc9ed014 2780 typedef uchar* value_type;
joeverbout 0:ea44dc9ed014 2781 typedef ptrdiff_t difference_type;
joeverbout 0:ea44dc9ed014 2782 typedef const uchar** pointer;
joeverbout 0:ea44dc9ed014 2783 typedef uchar* reference;
joeverbout 0:ea44dc9ed014 2784
joeverbout 0:ea44dc9ed014 2785 #ifndef OPENCV_NOSTL
joeverbout 0:ea44dc9ed014 2786 typedef std::random_access_iterator_tag iterator_category;
joeverbout 0:ea44dc9ed014 2787 #endif
joeverbout 0:ea44dc9ed014 2788
joeverbout 0:ea44dc9ed014 2789 //! default constructor
joeverbout 0:ea44dc9ed014 2790 MatConstIterator();
joeverbout 0:ea44dc9ed014 2791 //! constructor that sets the iterator to the beginning of the matrix
joeverbout 0:ea44dc9ed014 2792 MatConstIterator(const Mat* _m);
joeverbout 0:ea44dc9ed014 2793 //! constructor that sets the iterator to the specified element of the matrix
joeverbout 0:ea44dc9ed014 2794 MatConstIterator(const Mat* _m, int _row, int _col=0);
joeverbout 0:ea44dc9ed014 2795 //! constructor that sets the iterator to the specified element of the matrix
joeverbout 0:ea44dc9ed014 2796 MatConstIterator(const Mat* _m, Point _pt);
joeverbout 0:ea44dc9ed014 2797 //! constructor that sets the iterator to the specified element of the matrix
joeverbout 0:ea44dc9ed014 2798 MatConstIterator(const Mat* _m, const int* _idx);
joeverbout 0:ea44dc9ed014 2799 //! copy constructor
joeverbout 0:ea44dc9ed014 2800 MatConstIterator(const MatConstIterator& it);
joeverbout 0:ea44dc9ed014 2801
joeverbout 0:ea44dc9ed014 2802 //! copy operator
joeverbout 0:ea44dc9ed014 2803 MatConstIterator& operator = (const MatConstIterator& it);
joeverbout 0:ea44dc9ed014 2804 //! returns the current matrix element
joeverbout 0:ea44dc9ed014 2805 const uchar* operator *() const;
joeverbout 0:ea44dc9ed014 2806 //! returns the i-th matrix element, relative to the current
joeverbout 0:ea44dc9ed014 2807 const uchar* operator [](ptrdiff_t i) const;
joeverbout 0:ea44dc9ed014 2808
joeverbout 0:ea44dc9ed014 2809 //! shifts the iterator forward by the specified number of elements
joeverbout 0:ea44dc9ed014 2810 MatConstIterator& operator += (ptrdiff_t ofs);
joeverbout 0:ea44dc9ed014 2811 //! shifts the iterator backward by the specified number of elements
joeverbout 0:ea44dc9ed014 2812 MatConstIterator& operator -= (ptrdiff_t ofs);
joeverbout 0:ea44dc9ed014 2813 //! decrements the iterator
joeverbout 0:ea44dc9ed014 2814 MatConstIterator& operator --();
joeverbout 0:ea44dc9ed014 2815 //! decrements the iterator
joeverbout 0:ea44dc9ed014 2816 MatConstIterator operator --(int);
joeverbout 0:ea44dc9ed014 2817 //! increments the iterator
joeverbout 0:ea44dc9ed014 2818 MatConstIterator& operator ++();
joeverbout 0:ea44dc9ed014 2819 //! increments the iterator
joeverbout 0:ea44dc9ed014 2820 MatConstIterator operator ++(int);
joeverbout 0:ea44dc9ed014 2821 //! returns the current iterator position
joeverbout 0:ea44dc9ed014 2822 Point pos() const;
joeverbout 0:ea44dc9ed014 2823 //! returns the current iterator position
joeverbout 0:ea44dc9ed014 2824 void pos(int* _idx) const;
joeverbout 0:ea44dc9ed014 2825
joeverbout 0:ea44dc9ed014 2826 ptrdiff_t lpos() const;
joeverbout 0:ea44dc9ed014 2827 void seek(ptrdiff_t ofs, bool relative = false);
joeverbout 0:ea44dc9ed014 2828 void seek(const int* _idx, bool relative = false);
joeverbout 0:ea44dc9ed014 2829
joeverbout 0:ea44dc9ed014 2830 const Mat* m;
joeverbout 0:ea44dc9ed014 2831 size_t elemSize;
joeverbout 0:ea44dc9ed014 2832 const uchar* ptr;
joeverbout 0:ea44dc9ed014 2833 const uchar* sliceStart;
joeverbout 0:ea44dc9ed014 2834 const uchar* sliceEnd;
joeverbout 0:ea44dc9ed014 2835 };
joeverbout 0:ea44dc9ed014 2836
joeverbout 0:ea44dc9ed014 2837
joeverbout 0:ea44dc9ed014 2838
joeverbout 0:ea44dc9ed014 2839 ////////////////////////////////// MatConstIterator_ /////////////////////////////////
joeverbout 0:ea44dc9ed014 2840
joeverbout 0:ea44dc9ed014 2841 /** @brief Matrix read-only iterator
joeverbout 0:ea44dc9ed014 2842 */
joeverbout 0:ea44dc9ed014 2843 template<typename _Tp>
joeverbout 0:ea44dc9ed014 2844 class MatConstIterator_ : public MatConstIterator
joeverbout 0:ea44dc9ed014 2845 {
joeverbout 0:ea44dc9ed014 2846 public:
joeverbout 0:ea44dc9ed014 2847 typedef _Tp value_type;
joeverbout 0:ea44dc9ed014 2848 typedef ptrdiff_t difference_type;
joeverbout 0:ea44dc9ed014 2849 typedef const _Tp* pointer;
joeverbout 0:ea44dc9ed014 2850 typedef const _Tp& reference;
joeverbout 0:ea44dc9ed014 2851
joeverbout 0:ea44dc9ed014 2852 #ifndef OPENCV_NOSTL
joeverbout 0:ea44dc9ed014 2853 typedef std::random_access_iterator_tag iterator_category;
joeverbout 0:ea44dc9ed014 2854 #endif
joeverbout 0:ea44dc9ed014 2855
joeverbout 0:ea44dc9ed014 2856 //! default constructor
joeverbout 0:ea44dc9ed014 2857 MatConstIterator_();
joeverbout 0:ea44dc9ed014 2858 //! constructor that sets the iterator to the beginning of the matrix
joeverbout 0:ea44dc9ed014 2859 MatConstIterator_(const Mat_<_Tp>* _m);
joeverbout 0:ea44dc9ed014 2860 //! constructor that sets the iterator to the specified element of the matrix
joeverbout 0:ea44dc9ed014 2861 MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0);
joeverbout 0:ea44dc9ed014 2862 //! constructor that sets the iterator to the specified element of the matrix
joeverbout 0:ea44dc9ed014 2863 MatConstIterator_(const Mat_<_Tp>* _m, Point _pt);
joeverbout 0:ea44dc9ed014 2864 //! constructor that sets the iterator to the specified element of the matrix
joeverbout 0:ea44dc9ed014 2865 MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx);
joeverbout 0:ea44dc9ed014 2866 //! copy constructor
joeverbout 0:ea44dc9ed014 2867 MatConstIterator_(const MatConstIterator_& it);
joeverbout 0:ea44dc9ed014 2868
joeverbout 0:ea44dc9ed014 2869 //! copy operator
joeverbout 0:ea44dc9ed014 2870 MatConstIterator_& operator = (const MatConstIterator_& it);
joeverbout 0:ea44dc9ed014 2871 //! returns the current matrix element
joeverbout 0:ea44dc9ed014 2872 _Tp operator *() const;
joeverbout 0:ea44dc9ed014 2873 //! returns the i-th matrix element, relative to the current
joeverbout 0:ea44dc9ed014 2874 _Tp operator [](ptrdiff_t i) const;
joeverbout 0:ea44dc9ed014 2875
joeverbout 0:ea44dc9ed014 2876 //! shifts the iterator forward by the specified number of elements
joeverbout 0:ea44dc9ed014 2877 MatConstIterator_& operator += (ptrdiff_t ofs);
joeverbout 0:ea44dc9ed014 2878 //! shifts the iterator backward by the specified number of elements
joeverbout 0:ea44dc9ed014 2879 MatConstIterator_& operator -= (ptrdiff_t ofs);
joeverbout 0:ea44dc9ed014 2880 //! decrements the iterator
joeverbout 0:ea44dc9ed014 2881 MatConstIterator_& operator --();
joeverbout 0:ea44dc9ed014 2882 //! decrements the iterator
joeverbout 0:ea44dc9ed014 2883 MatConstIterator_ operator --(int);
joeverbout 0:ea44dc9ed014 2884 //! increments the iterator
joeverbout 0:ea44dc9ed014 2885 MatConstIterator_& operator ++();
joeverbout 0:ea44dc9ed014 2886 //! increments the iterator
joeverbout 0:ea44dc9ed014 2887 MatConstIterator_ operator ++(int);
joeverbout 0:ea44dc9ed014 2888 //! returns the current iterator position
joeverbout 0:ea44dc9ed014 2889 Point pos() const;
joeverbout 0:ea44dc9ed014 2890 };
joeverbout 0:ea44dc9ed014 2891
joeverbout 0:ea44dc9ed014 2892
joeverbout 0:ea44dc9ed014 2893
joeverbout 0:ea44dc9ed014 2894 //////////////////////////////////// MatIterator_ ////////////////////////////////////
joeverbout 0:ea44dc9ed014 2895
joeverbout 0:ea44dc9ed014 2896 /** @brief Matrix read-write iterator
joeverbout 0:ea44dc9ed014 2897 */
joeverbout 0:ea44dc9ed014 2898 template<typename _Tp>
joeverbout 0:ea44dc9ed014 2899 class MatIterator_ : public MatConstIterator_<_Tp>
joeverbout 0:ea44dc9ed014 2900 {
joeverbout 0:ea44dc9ed014 2901 public:
joeverbout 0:ea44dc9ed014 2902 typedef _Tp* pointer;
joeverbout 0:ea44dc9ed014 2903 typedef _Tp& reference;
joeverbout 0:ea44dc9ed014 2904
joeverbout 0:ea44dc9ed014 2905 #ifndef OPENCV_NOSTL
joeverbout 0:ea44dc9ed014 2906 typedef std::random_access_iterator_tag iterator_category;
joeverbout 0:ea44dc9ed014 2907 #endif
joeverbout 0:ea44dc9ed014 2908
joeverbout 0:ea44dc9ed014 2909 //! the default constructor
joeverbout 0:ea44dc9ed014 2910 MatIterator_();
joeverbout 0:ea44dc9ed014 2911 //! constructor that sets the iterator to the beginning of the matrix
joeverbout 0:ea44dc9ed014 2912 MatIterator_(Mat_<_Tp>* _m);
joeverbout 0:ea44dc9ed014 2913 //! constructor that sets the iterator to the specified element of the matrix
joeverbout 0:ea44dc9ed014 2914 MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0);
joeverbout 0:ea44dc9ed014 2915 //! constructor that sets the iterator to the specified element of the matrix
joeverbout 0:ea44dc9ed014 2916 MatIterator_(Mat_<_Tp>* _m, Point _pt);
joeverbout 0:ea44dc9ed014 2917 //! constructor that sets the iterator to the specified element of the matrix
joeverbout 0:ea44dc9ed014 2918 MatIterator_(Mat_<_Tp>* _m, const int* _idx);
joeverbout 0:ea44dc9ed014 2919 //! copy constructor
joeverbout 0:ea44dc9ed014 2920 MatIterator_(const MatIterator_& it);
joeverbout 0:ea44dc9ed014 2921 //! copy operator
joeverbout 0:ea44dc9ed014 2922 MatIterator_& operator = (const MatIterator_<_Tp>& it );
joeverbout 0:ea44dc9ed014 2923
joeverbout 0:ea44dc9ed014 2924 //! returns the current matrix element
joeverbout 0:ea44dc9ed014 2925 _Tp& operator *() const;
joeverbout 0:ea44dc9ed014 2926 //! returns the i-th matrix element, relative to the current
joeverbout 0:ea44dc9ed014 2927 _Tp& operator [](ptrdiff_t i) const;
joeverbout 0:ea44dc9ed014 2928
joeverbout 0:ea44dc9ed014 2929 //! shifts the iterator forward by the specified number of elements
joeverbout 0:ea44dc9ed014 2930 MatIterator_& operator += (ptrdiff_t ofs);
joeverbout 0:ea44dc9ed014 2931 //! shifts the iterator backward by the specified number of elements
joeverbout 0:ea44dc9ed014 2932 MatIterator_& operator -= (ptrdiff_t ofs);
joeverbout 0:ea44dc9ed014 2933 //! decrements the iterator
joeverbout 0:ea44dc9ed014 2934 MatIterator_& operator --();
joeverbout 0:ea44dc9ed014 2935 //! decrements the iterator
joeverbout 0:ea44dc9ed014 2936 MatIterator_ operator --(int);
joeverbout 0:ea44dc9ed014 2937 //! increments the iterator
joeverbout 0:ea44dc9ed014 2938 MatIterator_& operator ++();
joeverbout 0:ea44dc9ed014 2939 //! increments the iterator
joeverbout 0:ea44dc9ed014 2940 MatIterator_ operator ++(int);
joeverbout 0:ea44dc9ed014 2941 };
joeverbout 0:ea44dc9ed014 2942
joeverbout 0:ea44dc9ed014 2943
joeverbout 0:ea44dc9ed014 2944
joeverbout 0:ea44dc9ed014 2945 /////////////////////////////// SparseMatConstIterator ///////////////////////////////
joeverbout 0:ea44dc9ed014 2946
joeverbout 0:ea44dc9ed014 2947 /** @brief Read-Only Sparse Matrix Iterator.
joeverbout 0:ea44dc9ed014 2948
joeverbout 0:ea44dc9ed014 2949 Here is how to use the iterator to compute the sum of floating-point sparse matrix elements:
joeverbout 0:ea44dc9ed014 2950
joeverbout 0:ea44dc9ed014 2951 \code
joeverbout 0:ea44dc9ed014 2952 SparseMatConstIterator it = m.begin(), it_end = m.end();
joeverbout 0:ea44dc9ed014 2953 double s = 0;
joeverbout 0:ea44dc9ed014 2954 CV_Assert( m.type() == CV_32F );
joeverbout 0:ea44dc9ed014 2955 for( ; it != it_end; ++it )
joeverbout 0:ea44dc9ed014 2956 s += it.value<float>();
joeverbout 0:ea44dc9ed014 2957 \endcode
joeverbout 0:ea44dc9ed014 2958 */
joeverbout 0:ea44dc9ed014 2959 class CV_EXPORTS SparseMatConstIterator
joeverbout 0:ea44dc9ed014 2960 {
joeverbout 0:ea44dc9ed014 2961 public:
joeverbout 0:ea44dc9ed014 2962 //! the default constructor
joeverbout 0:ea44dc9ed014 2963 SparseMatConstIterator();
joeverbout 0:ea44dc9ed014 2964 //! the full constructor setting the iterator to the first sparse matrix element
joeverbout 0:ea44dc9ed014 2965 SparseMatConstIterator(const SparseMat* _m);
joeverbout 0:ea44dc9ed014 2966 //! the copy constructor
joeverbout 0:ea44dc9ed014 2967 SparseMatConstIterator(const SparseMatConstIterator& it);
joeverbout 0:ea44dc9ed014 2968
joeverbout 0:ea44dc9ed014 2969 //! the assignment operator
joeverbout 0:ea44dc9ed014 2970 SparseMatConstIterator& operator = (const SparseMatConstIterator& it);
joeverbout 0:ea44dc9ed014 2971
joeverbout 0:ea44dc9ed014 2972 //! template method returning the current matrix element
joeverbout 0:ea44dc9ed014 2973 template<typename _Tp> const _Tp& value() const;
joeverbout 0:ea44dc9ed014 2974 //! returns the current node of the sparse matrix. it.node->idx is the current element index
joeverbout 0:ea44dc9ed014 2975 const SparseMat::Node* node() const;
joeverbout 0:ea44dc9ed014 2976
joeverbout 0:ea44dc9ed014 2977 //! moves iterator to the previous element
joeverbout 0:ea44dc9ed014 2978 SparseMatConstIterator& operator --();
joeverbout 0:ea44dc9ed014 2979 //! moves iterator to the previous element
joeverbout 0:ea44dc9ed014 2980 SparseMatConstIterator operator --(int);
joeverbout 0:ea44dc9ed014 2981 //! moves iterator to the next element
joeverbout 0:ea44dc9ed014 2982 SparseMatConstIterator& operator ++();
joeverbout 0:ea44dc9ed014 2983 //! moves iterator to the next element
joeverbout 0:ea44dc9ed014 2984 SparseMatConstIterator operator ++(int);
joeverbout 0:ea44dc9ed014 2985
joeverbout 0:ea44dc9ed014 2986 //! moves iterator to the element after the last element
joeverbout 0:ea44dc9ed014 2987 void seekEnd();
joeverbout 0:ea44dc9ed014 2988
joeverbout 0:ea44dc9ed014 2989 const SparseMat* m;
joeverbout 0:ea44dc9ed014 2990 size_t hashidx;
joeverbout 0:ea44dc9ed014 2991 uchar* ptr;
joeverbout 0:ea44dc9ed014 2992 };
joeverbout 0:ea44dc9ed014 2993
joeverbout 0:ea44dc9ed014 2994
joeverbout 0:ea44dc9ed014 2995
joeverbout 0:ea44dc9ed014 2996 ////////////////////////////////// SparseMatIterator /////////////////////////////////
joeverbout 0:ea44dc9ed014 2997
joeverbout 0:ea44dc9ed014 2998 /** @brief Read-write Sparse Matrix Iterator
joeverbout 0:ea44dc9ed014 2999
joeverbout 0:ea44dc9ed014 3000 The class is similar to cv::SparseMatConstIterator,
joeverbout 0:ea44dc9ed014 3001 but can be used for in-place modification of the matrix elements.
joeverbout 0:ea44dc9ed014 3002 */
joeverbout 0:ea44dc9ed014 3003 class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator
joeverbout 0:ea44dc9ed014 3004 {
joeverbout 0:ea44dc9ed014 3005 public:
joeverbout 0:ea44dc9ed014 3006 //! the default constructor
joeverbout 0:ea44dc9ed014 3007 SparseMatIterator();
joeverbout 0:ea44dc9ed014 3008 //! the full constructor setting the iterator to the first sparse matrix element
joeverbout 0:ea44dc9ed014 3009 SparseMatIterator(SparseMat* _m);
joeverbout 0:ea44dc9ed014 3010 //! the full constructor setting the iterator to the specified sparse matrix element
joeverbout 0:ea44dc9ed014 3011 SparseMatIterator(SparseMat* _m, const int* idx);
joeverbout 0:ea44dc9ed014 3012 //! the copy constructor
joeverbout 0:ea44dc9ed014 3013 SparseMatIterator(const SparseMatIterator& it);
joeverbout 0:ea44dc9ed014 3014
joeverbout 0:ea44dc9ed014 3015 //! the assignment operator
joeverbout 0:ea44dc9ed014 3016 SparseMatIterator& operator = (const SparseMatIterator& it);
joeverbout 0:ea44dc9ed014 3017 //! returns read-write reference to the current sparse matrix element
joeverbout 0:ea44dc9ed014 3018 template<typename _Tp> _Tp& value() const;
joeverbout 0:ea44dc9ed014 3019 //! returns pointer to the current sparse matrix node. it.node->idx is the index of the current element (do not modify it!)
joeverbout 0:ea44dc9ed014 3020 SparseMat::Node* node() const;
joeverbout 0:ea44dc9ed014 3021
joeverbout 0:ea44dc9ed014 3022 //! moves iterator to the next element
joeverbout 0:ea44dc9ed014 3023 SparseMatIterator& operator ++();
joeverbout 0:ea44dc9ed014 3024 //! moves iterator to the next element
joeverbout 0:ea44dc9ed014 3025 SparseMatIterator operator ++(int);
joeverbout 0:ea44dc9ed014 3026 };
joeverbout 0:ea44dc9ed014 3027
joeverbout 0:ea44dc9ed014 3028
joeverbout 0:ea44dc9ed014 3029
joeverbout 0:ea44dc9ed014 3030 /////////////////////////////// SparseMatConstIterator_ //////////////////////////////
joeverbout 0:ea44dc9ed014 3031
joeverbout 0:ea44dc9ed014 3032 /** @brief Template Read-Only Sparse Matrix Iterator Class.
joeverbout 0:ea44dc9ed014 3033
joeverbout 0:ea44dc9ed014 3034 This is the derived from SparseMatConstIterator class that
joeverbout 0:ea44dc9ed014 3035 introduces more convenient operator *() for accessing the current element.
joeverbout 0:ea44dc9ed014 3036 */
joeverbout 0:ea44dc9ed014 3037 template<typename _Tp> class SparseMatConstIterator_ : public SparseMatConstIterator
joeverbout 0:ea44dc9ed014 3038 {
joeverbout 0:ea44dc9ed014 3039 public:
joeverbout 0:ea44dc9ed014 3040
joeverbout 0:ea44dc9ed014 3041 #ifndef OPENCV_NOSTL
joeverbout 0:ea44dc9ed014 3042 typedef std::forward_iterator_tag iterator_category;
joeverbout 0:ea44dc9ed014 3043 #endif
joeverbout 0:ea44dc9ed014 3044
joeverbout 0:ea44dc9ed014 3045 //! the default constructor
joeverbout 0:ea44dc9ed014 3046 SparseMatConstIterator_();
joeverbout 0:ea44dc9ed014 3047 //! the full constructor setting the iterator to the first sparse matrix element
joeverbout 0:ea44dc9ed014 3048 SparseMatConstIterator_(const SparseMat_<_Tp>* _m);
joeverbout 0:ea44dc9ed014 3049 SparseMatConstIterator_(const SparseMat* _m);
joeverbout 0:ea44dc9ed014 3050 //! the copy constructor
joeverbout 0:ea44dc9ed014 3051 SparseMatConstIterator_(const SparseMatConstIterator_& it);
joeverbout 0:ea44dc9ed014 3052
joeverbout 0:ea44dc9ed014 3053 //! the assignment operator
joeverbout 0:ea44dc9ed014 3054 SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it);
joeverbout 0:ea44dc9ed014 3055 //! the element access operator
joeverbout 0:ea44dc9ed014 3056 const _Tp& operator *() const;
joeverbout 0:ea44dc9ed014 3057
joeverbout 0:ea44dc9ed014 3058 //! moves iterator to the next element
joeverbout 0:ea44dc9ed014 3059 SparseMatConstIterator_& operator ++();
joeverbout 0:ea44dc9ed014 3060 //! moves iterator to the next element
joeverbout 0:ea44dc9ed014 3061 SparseMatConstIterator_ operator ++(int);
joeverbout 0:ea44dc9ed014 3062 };
joeverbout 0:ea44dc9ed014 3063
joeverbout 0:ea44dc9ed014 3064
joeverbout 0:ea44dc9ed014 3065
joeverbout 0:ea44dc9ed014 3066 ///////////////////////////////// SparseMatIterator_ /////////////////////////////////
joeverbout 0:ea44dc9ed014 3067
joeverbout 0:ea44dc9ed014 3068 /** @brief Template Read-Write Sparse Matrix Iterator Class.
joeverbout 0:ea44dc9ed014 3069
joeverbout 0:ea44dc9ed014 3070 This is the derived from cv::SparseMatConstIterator_ class that
joeverbout 0:ea44dc9ed014 3071 introduces more convenient operator *() for accessing the current element.
joeverbout 0:ea44dc9ed014 3072 */
joeverbout 0:ea44dc9ed014 3073 template<typename _Tp> class SparseMatIterator_ : public SparseMatConstIterator_<_Tp>
joeverbout 0:ea44dc9ed014 3074 {
joeverbout 0:ea44dc9ed014 3075 public:
joeverbout 0:ea44dc9ed014 3076
joeverbout 0:ea44dc9ed014 3077 #ifndef OPENCV_NOSTL
joeverbout 0:ea44dc9ed014 3078 typedef std::forward_iterator_tag iterator_category;
joeverbout 0:ea44dc9ed014 3079 #endif
joeverbout 0:ea44dc9ed014 3080
joeverbout 0:ea44dc9ed014 3081 //! the default constructor
joeverbout 0:ea44dc9ed014 3082 SparseMatIterator_();
joeverbout 0:ea44dc9ed014 3083 //! the full constructor setting the iterator to the first sparse matrix element
joeverbout 0:ea44dc9ed014 3084 SparseMatIterator_(SparseMat_<_Tp>* _m);
joeverbout 0:ea44dc9ed014 3085 SparseMatIterator_(SparseMat* _m);
joeverbout 0:ea44dc9ed014 3086 //! the copy constructor
joeverbout 0:ea44dc9ed014 3087 SparseMatIterator_(const SparseMatIterator_& it);
joeverbout 0:ea44dc9ed014 3088
joeverbout 0:ea44dc9ed014 3089 //! the assignment operator
joeverbout 0:ea44dc9ed014 3090 SparseMatIterator_& operator = (const SparseMatIterator_& it);
joeverbout 0:ea44dc9ed014 3091 //! returns the reference to the current element
joeverbout 0:ea44dc9ed014 3092 _Tp& operator *() const;
joeverbout 0:ea44dc9ed014 3093
joeverbout 0:ea44dc9ed014 3094 //! moves the iterator to the next element
joeverbout 0:ea44dc9ed014 3095 SparseMatIterator_& operator ++();
joeverbout 0:ea44dc9ed014 3096 //! moves the iterator to the next element
joeverbout 0:ea44dc9ed014 3097 SparseMatIterator_ operator ++(int);
joeverbout 0:ea44dc9ed014 3098 };
joeverbout 0:ea44dc9ed014 3099
joeverbout 0:ea44dc9ed014 3100
joeverbout 0:ea44dc9ed014 3101
joeverbout 0:ea44dc9ed014 3102 /////////////////////////////////// NAryMatIterator //////////////////////////////////
joeverbout 0:ea44dc9ed014 3103
joeverbout 0:ea44dc9ed014 3104 /** @brief n-ary multi-dimensional array iterator.
joeverbout 0:ea44dc9ed014 3105
joeverbout 0:ea44dc9ed014 3106 Use the class to implement unary, binary, and, generally, n-ary element-wise operations on
joeverbout 0:ea44dc9ed014 3107 multi-dimensional arrays. Some of the arguments of an n-ary function may be continuous arrays, some
joeverbout 0:ea44dc9ed014 3108 may be not. It is possible to use conventional MatIterator 's for each array but incrementing all of
joeverbout 0:ea44dc9ed014 3109 the iterators after each small operations may be a big overhead. In this case consider using
joeverbout 0:ea44dc9ed014 3110 NAryMatIterator to iterate through several matrices simultaneously as long as they have the same
joeverbout 0:ea44dc9ed014 3111 geometry (dimensionality and all the dimension sizes are the same). On each iteration `it.planes[0]`,
joeverbout 0:ea44dc9ed014 3112 `it.planes[1]`,... will be the slices of the corresponding matrices.
joeverbout 0:ea44dc9ed014 3113
joeverbout 0:ea44dc9ed014 3114 The example below illustrates how you can compute a normalized and threshold 3D color histogram:
joeverbout 0:ea44dc9ed014 3115 @code
joeverbout 0:ea44dc9ed014 3116 void computeNormalizedColorHist(const Mat& image, Mat& hist, int N, double minProb)
joeverbout 0:ea44dc9ed014 3117 {
joeverbout 0:ea44dc9ed014 3118 const int histSize[] = {N, N, N};
joeverbout 0:ea44dc9ed014 3119
joeverbout 0:ea44dc9ed014 3120 // make sure that the histogram has a proper size and type
joeverbout 0:ea44dc9ed014 3121 hist.create(3, histSize, CV_32F);
joeverbout 0:ea44dc9ed014 3122
joeverbout 0:ea44dc9ed014 3123 // and clear it
joeverbout 0:ea44dc9ed014 3124 hist = Scalar(0);
joeverbout 0:ea44dc9ed014 3125
joeverbout 0:ea44dc9ed014 3126 // the loop below assumes that the image
joeverbout 0:ea44dc9ed014 3127 // is a 8-bit 3-channel. check it.
joeverbout 0:ea44dc9ed014 3128 CV_Assert(image.type() == CV_8UC3);
joeverbout 0:ea44dc9ed014 3129 MatConstIterator_<Vec3b> it = image.begin<Vec3b>(),
joeverbout 0:ea44dc9ed014 3130 it_end = image.end<Vec3b>();
joeverbout 0:ea44dc9ed014 3131 for( ; it != it_end; ++it )
joeverbout 0:ea44dc9ed014 3132 {
joeverbout 0:ea44dc9ed014 3133 const Vec3b& pix = *it;
joeverbout 0:ea44dc9ed014 3134 hist.at<float>(pix[0]*N/256, pix[1]*N/256, pix[2]*N/256) += 1.f;
joeverbout 0:ea44dc9ed014 3135 }
joeverbout 0:ea44dc9ed014 3136
joeverbout 0:ea44dc9ed014 3137 minProb *= image.rows*image.cols;
joeverbout 0:ea44dc9ed014 3138 Mat plane;
joeverbout 0:ea44dc9ed014 3139 NAryMatIterator it(&hist, &plane, 1);
joeverbout 0:ea44dc9ed014 3140 double s = 0;
joeverbout 0:ea44dc9ed014 3141 // iterate through the matrix. on each iteration
joeverbout 0:ea44dc9ed014 3142 // it.planes[*] (of type Mat) will be set to the current plane.
joeverbout 0:ea44dc9ed014 3143 for(int p = 0; p < it.nplanes; p++, ++it)
joeverbout 0:ea44dc9ed014 3144 {
joeverbout 0:ea44dc9ed014 3145 threshold(it.planes[0], it.planes[0], minProb, 0, THRESH_TOZERO);
joeverbout 0:ea44dc9ed014 3146 s += sum(it.planes[0])[0];
joeverbout 0:ea44dc9ed014 3147 }
joeverbout 0:ea44dc9ed014 3148
joeverbout 0:ea44dc9ed014 3149 s = 1./s;
joeverbout 0:ea44dc9ed014 3150 it = NAryMatIterator(&hist, &plane, 1);
joeverbout 0:ea44dc9ed014 3151 for(int p = 0; p < it.nplanes; p++, ++it)
joeverbout 0:ea44dc9ed014 3152 it.planes[0] *= s;
joeverbout 0:ea44dc9ed014 3153 }
joeverbout 0:ea44dc9ed014 3154 @endcode
joeverbout 0:ea44dc9ed014 3155 */
joeverbout 0:ea44dc9ed014 3156 class CV_EXPORTS NAryMatIterator
joeverbout 0:ea44dc9ed014 3157 {
joeverbout 0:ea44dc9ed014 3158 public:
joeverbout 0:ea44dc9ed014 3159 //! the default constructor
joeverbout 0:ea44dc9ed014 3160 NAryMatIterator();
joeverbout 0:ea44dc9ed014 3161 //! the full constructor taking arbitrary number of n-dim matrices
joeverbout 0:ea44dc9ed014 3162 NAryMatIterator(const Mat** arrays, uchar** ptrs, int narrays=-1);
joeverbout 0:ea44dc9ed014 3163 //! the full constructor taking arbitrary number of n-dim matrices
joeverbout 0:ea44dc9ed014 3164 NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1);
joeverbout 0:ea44dc9ed014 3165 //! the separate iterator initialization method
joeverbout 0:ea44dc9ed014 3166 void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1);
joeverbout 0:ea44dc9ed014 3167
joeverbout 0:ea44dc9ed014 3168 //! proceeds to the next plane of every iterated matrix
joeverbout 0:ea44dc9ed014 3169 NAryMatIterator& operator ++();
joeverbout 0:ea44dc9ed014 3170 //! proceeds to the next plane of every iterated matrix (postfix increment operator)
joeverbout 0:ea44dc9ed014 3171 NAryMatIterator operator ++(int);
joeverbout 0:ea44dc9ed014 3172
joeverbout 0:ea44dc9ed014 3173 //! the iterated arrays
joeverbout 0:ea44dc9ed014 3174 const Mat** arrays;
joeverbout 0:ea44dc9ed014 3175 //! the current planes
joeverbout 0:ea44dc9ed014 3176 Mat* planes;
joeverbout 0:ea44dc9ed014 3177 //! data pointers
joeverbout 0:ea44dc9ed014 3178 uchar** ptrs;
joeverbout 0:ea44dc9ed014 3179 //! the number of arrays
joeverbout 0:ea44dc9ed014 3180 int narrays;
joeverbout 0:ea44dc9ed014 3181 //! the number of hyper-planes that the iterator steps through
joeverbout 0:ea44dc9ed014 3182 size_t nplanes;
joeverbout 0:ea44dc9ed014 3183 //! the size of each segment (in elements)
joeverbout 0:ea44dc9ed014 3184 size_t size;
joeverbout 0:ea44dc9ed014 3185 protected:
joeverbout 0:ea44dc9ed014 3186 int iterdepth;
joeverbout 0:ea44dc9ed014 3187 size_t idx;
joeverbout 0:ea44dc9ed014 3188 };
joeverbout 0:ea44dc9ed014 3189
joeverbout 0:ea44dc9ed014 3190
joeverbout 0:ea44dc9ed014 3191
joeverbout 0:ea44dc9ed014 3192 ///////////////////////////////// Matrix Expressions /////////////////////////////////
joeverbout 0:ea44dc9ed014 3193
joeverbout 0:ea44dc9ed014 3194 class CV_EXPORTS MatOp
joeverbout 0:ea44dc9ed014 3195 {
joeverbout 0:ea44dc9ed014 3196 public:
joeverbout 0:ea44dc9ed014 3197 MatOp();
joeverbout 0:ea44dc9ed014 3198 virtual ~MatOp();
joeverbout 0:ea44dc9ed014 3199
joeverbout 0:ea44dc9ed014 3200 virtual bool elementWise(const MatExpr& expr) const;
joeverbout 0:ea44dc9ed014 3201 virtual void assign(const MatExpr& expr, Mat& m, int type=-1) const = 0;
joeverbout 0:ea44dc9ed014 3202 virtual void roi(const MatExpr& expr, const Range& rowRange,
joeverbout 0:ea44dc9ed014 3203 const Range& colRange, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3204 virtual void diag(const MatExpr& expr, int d, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3205 virtual void augAssignAdd(const MatExpr& expr, Mat& m) const;
joeverbout 0:ea44dc9ed014 3206 virtual void augAssignSubtract(const MatExpr& expr, Mat& m) const;
joeverbout 0:ea44dc9ed014 3207 virtual void augAssignMultiply(const MatExpr& expr, Mat& m) const;
joeverbout 0:ea44dc9ed014 3208 virtual void augAssignDivide(const MatExpr& expr, Mat& m) const;
joeverbout 0:ea44dc9ed014 3209 virtual void augAssignAnd(const MatExpr& expr, Mat& m) const;
joeverbout 0:ea44dc9ed014 3210 virtual void augAssignOr(const MatExpr& expr, Mat& m) const;
joeverbout 0:ea44dc9ed014 3211 virtual void augAssignXor(const MatExpr& expr, Mat& m) const;
joeverbout 0:ea44dc9ed014 3212
joeverbout 0:ea44dc9ed014 3213 virtual void add(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3214 virtual void add(const MatExpr& expr1, const Scalar& s, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3215
joeverbout 0:ea44dc9ed014 3216 virtual void subtract(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3217 virtual void subtract(const Scalar& s, const MatExpr& expr, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3218
joeverbout 0:ea44dc9ed014 3219 virtual void multiply(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const;
joeverbout 0:ea44dc9ed014 3220 virtual void multiply(const MatExpr& expr1, double s, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3221
joeverbout 0:ea44dc9ed014 3222 virtual void divide(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const;
joeverbout 0:ea44dc9ed014 3223 virtual void divide(double s, const MatExpr& expr, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3224
joeverbout 0:ea44dc9ed014 3225 virtual void abs(const MatExpr& expr, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3226
joeverbout 0:ea44dc9ed014 3227 virtual void transpose(const MatExpr& expr, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3228 virtual void matmul(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3229 virtual void invert(const MatExpr& expr, int method, MatExpr& res) const;
joeverbout 0:ea44dc9ed014 3230
joeverbout 0:ea44dc9ed014 3231 virtual Size size(const MatExpr& expr) const;
joeverbout 0:ea44dc9ed014 3232 virtual int type(const MatExpr& expr) const;
joeverbout 0:ea44dc9ed014 3233 };
joeverbout 0:ea44dc9ed014 3234
joeverbout 0:ea44dc9ed014 3235 /** @brief Matrix expression representation
joeverbout 0:ea44dc9ed014 3236 @anchor MatrixExpressions
joeverbout 0:ea44dc9ed014 3237 This is a list of implemented matrix operations that can be combined in arbitrary complex
joeverbout 0:ea44dc9ed014 3238 expressions (here A, B stand for matrices ( Mat ), s for a scalar ( Scalar ), alpha for a
joeverbout 0:ea44dc9ed014 3239 real-valued scalar ( double )):
joeverbout 0:ea44dc9ed014 3240 - Addition, subtraction, negation: `A+B`, `A-B`, `A+s`, `A-s`, `s+A`, `s-A`, `-A`
joeverbout 0:ea44dc9ed014 3241 - Scaling: `A*alpha`
joeverbout 0:ea44dc9ed014 3242 - Per-element multiplication and division: `A.mul(B)`, `A/B`, `alpha/A`
joeverbout 0:ea44dc9ed014 3243 - Matrix multiplication: `A*B`
joeverbout 0:ea44dc9ed014 3244 - Transposition: `A.t()` (means A<sup>T</sup>)
joeverbout 0:ea44dc9ed014 3245 - Matrix inversion and pseudo-inversion, solving linear systems and least-squares problems:
joeverbout 0:ea44dc9ed014 3246 `A.inv([method]) (~ A<sup>-1</sup>)`, `A.inv([method])*B (~ X: AX=B)`
joeverbout 0:ea44dc9ed014 3247 - Comparison: `A cmpop B`, `A cmpop alpha`, `alpha cmpop A`, where *cmpop* is one of
joeverbout 0:ea44dc9ed014 3248 `>`, `>=`, `==`, `!=`, `<=`, `<`. The result of comparison is an 8-bit single channel mask whose
joeverbout 0:ea44dc9ed014 3249 elements are set to 255 (if the particular element or pair of elements satisfy the condition) or
joeverbout 0:ea44dc9ed014 3250 0.
joeverbout 0:ea44dc9ed014 3251 - Bitwise logical operations: `A logicop B`, `A logicop s`, `s logicop A`, `~A`, where *logicop* is one of
joeverbout 0:ea44dc9ed014 3252 `&`, `|`, `^`.
joeverbout 0:ea44dc9ed014 3253 - Element-wise minimum and maximum: `min(A, B)`, `min(A, alpha)`, `max(A, B)`, `max(A, alpha)`
joeverbout 0:ea44dc9ed014 3254 - Element-wise absolute value: `abs(A)`
joeverbout 0:ea44dc9ed014 3255 - Cross-product, dot-product: `A.cross(B)`, `A.dot(B)`
joeverbout 0:ea44dc9ed014 3256 - Any function of matrix or matrices and scalars that returns a matrix or a scalar, such as norm,
joeverbout 0:ea44dc9ed014 3257 mean, sum, countNonZero, trace, determinant, repeat, and others.
joeverbout 0:ea44dc9ed014 3258 - Matrix initializers ( Mat::eye(), Mat::zeros(), Mat::ones() ), matrix comma-separated
joeverbout 0:ea44dc9ed014 3259 initializers, matrix constructors and operators that extract sub-matrices (see Mat description).
joeverbout 0:ea44dc9ed014 3260 - Mat_<destination_type>() constructors to cast the result to the proper type.
joeverbout 0:ea44dc9ed014 3261 @note Comma-separated initializers and probably some other operations may require additional
joeverbout 0:ea44dc9ed014 3262 explicit Mat() or Mat_<T>() constructor calls to resolve a possible ambiguity.
joeverbout 0:ea44dc9ed014 3263
joeverbout 0:ea44dc9ed014 3264 Here are examples of matrix expressions:
joeverbout 0:ea44dc9ed014 3265 @code
joeverbout 0:ea44dc9ed014 3266 // compute pseudo-inverse of A, equivalent to A.inv(DECOMP_SVD)
joeverbout 0:ea44dc9ed014 3267 SVD svd(A);
joeverbout 0:ea44dc9ed014 3268 Mat pinvA = svd.vt.t()*Mat::diag(1./svd.w)*svd.u.t();
joeverbout 0:ea44dc9ed014 3269
joeverbout 0:ea44dc9ed014 3270 // compute the new vector of parameters in the Levenberg-Marquardt algorithm
joeverbout 0:ea44dc9ed014 3271 x -= (A.t()*A + lambda*Mat::eye(A.cols,A.cols,A.type())).inv(DECOMP_CHOLESKY)*(A.t()*err);
joeverbout 0:ea44dc9ed014 3272
joeverbout 0:ea44dc9ed014 3273 // sharpen image using "unsharp mask" algorithm
joeverbout 0:ea44dc9ed014 3274 Mat blurred; double sigma = 1, threshold = 5, amount = 1;
joeverbout 0:ea44dc9ed014 3275 GaussianBlur(img, blurred, Size(), sigma, sigma);
joeverbout 0:ea44dc9ed014 3276 Mat lowContrastMask = abs(img - blurred) < threshold;
joeverbout 0:ea44dc9ed014 3277 Mat sharpened = img*(1+amount) + blurred*(-amount);
joeverbout 0:ea44dc9ed014 3278 img.copyTo(sharpened, lowContrastMask);
joeverbout 0:ea44dc9ed014 3279 @endcode
joeverbout 0:ea44dc9ed014 3280 */
joeverbout 0:ea44dc9ed014 3281 class CV_EXPORTS MatExpr
joeverbout 0:ea44dc9ed014 3282 {
joeverbout 0:ea44dc9ed014 3283 public:
joeverbout 0:ea44dc9ed014 3284 MatExpr();
joeverbout 0:ea44dc9ed014 3285 explicit MatExpr(const Mat& m);
joeverbout 0:ea44dc9ed014 3286
joeverbout 0:ea44dc9ed014 3287 MatExpr(const MatOp* _op, int _flags, const Mat& _a = Mat(), const Mat& _b = Mat(),
joeverbout 0:ea44dc9ed014 3288 const Mat& _c = Mat(), double _alpha = 1, double _beta = 1, const Scalar& _s = Scalar());
joeverbout 0:ea44dc9ed014 3289
joeverbout 0:ea44dc9ed014 3290 operator Mat() const;
joeverbout 0:ea44dc9ed014 3291 template<typename _Tp> operator Mat_<_Tp>() const;
joeverbout 0:ea44dc9ed014 3292
joeverbout 0:ea44dc9ed014 3293 Size size() const;
joeverbout 0:ea44dc9ed014 3294 int type() const;
joeverbout 0:ea44dc9ed014 3295
joeverbout 0:ea44dc9ed014 3296 MatExpr row(int y) const;
joeverbout 0:ea44dc9ed014 3297 MatExpr col(int x) const;
joeverbout 0:ea44dc9ed014 3298 MatExpr diag(int d = 0) const;
joeverbout 0:ea44dc9ed014 3299 MatExpr operator()( const Range& rowRange, const Range& colRange ) const;
joeverbout 0:ea44dc9ed014 3300 MatExpr operator()( const Rect& roi ) const;
joeverbout 0:ea44dc9ed014 3301
joeverbout 0:ea44dc9ed014 3302 MatExpr t() const;
joeverbout 0:ea44dc9ed014 3303 MatExpr inv(int method = DECOMP_LU) const;
joeverbout 0:ea44dc9ed014 3304 MatExpr mul(const MatExpr& e, double scale=1) const;
joeverbout 0:ea44dc9ed014 3305 MatExpr mul(const Mat& m, double scale=1) const;
joeverbout 0:ea44dc9ed014 3306
joeverbout 0:ea44dc9ed014 3307 Mat cross(const Mat& m) const;
joeverbout 0:ea44dc9ed014 3308 double dot(const Mat& m) const;
joeverbout 0:ea44dc9ed014 3309
joeverbout 0:ea44dc9ed014 3310 const MatOp* op;
joeverbout 0:ea44dc9ed014 3311 int flags;
joeverbout 0:ea44dc9ed014 3312
joeverbout 0:ea44dc9ed014 3313 Mat a, b, c;
joeverbout 0:ea44dc9ed014 3314 double alpha, beta;
joeverbout 0:ea44dc9ed014 3315 Scalar s;
joeverbout 0:ea44dc9ed014 3316 };
joeverbout 0:ea44dc9ed014 3317
joeverbout 0:ea44dc9ed014 3318 //! @} core_basic
joeverbout 0:ea44dc9ed014 3319
joeverbout 0:ea44dc9ed014 3320 //! @relates cv::MatExpr
joeverbout 0:ea44dc9ed014 3321 //! @{
joeverbout 0:ea44dc9ed014 3322 CV_EXPORTS MatExpr operator + (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3323 CV_EXPORTS MatExpr operator + (const Mat& a, const Scalar& s);
joeverbout 0:ea44dc9ed014 3324 CV_EXPORTS MatExpr operator + (const Scalar& s, const Mat& a);
joeverbout 0:ea44dc9ed014 3325 CV_EXPORTS MatExpr operator + (const MatExpr& e, const Mat& m);
joeverbout 0:ea44dc9ed014 3326 CV_EXPORTS MatExpr operator + (const Mat& m, const MatExpr& e);
joeverbout 0:ea44dc9ed014 3327 CV_EXPORTS MatExpr operator + (const MatExpr& e, const Scalar& s);
joeverbout 0:ea44dc9ed014 3328 CV_EXPORTS MatExpr operator + (const Scalar& s, const MatExpr& e);
joeverbout 0:ea44dc9ed014 3329 CV_EXPORTS MatExpr operator + (const MatExpr& e1, const MatExpr& e2);
joeverbout 0:ea44dc9ed014 3330
joeverbout 0:ea44dc9ed014 3331 CV_EXPORTS MatExpr operator - (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3332 CV_EXPORTS MatExpr operator - (const Mat& a, const Scalar& s);
joeverbout 0:ea44dc9ed014 3333 CV_EXPORTS MatExpr operator - (const Scalar& s, const Mat& a);
joeverbout 0:ea44dc9ed014 3334 CV_EXPORTS MatExpr operator - (const MatExpr& e, const Mat& m);
joeverbout 0:ea44dc9ed014 3335 CV_EXPORTS MatExpr operator - (const Mat& m, const MatExpr& e);
joeverbout 0:ea44dc9ed014 3336 CV_EXPORTS MatExpr operator - (const MatExpr& e, const Scalar& s);
joeverbout 0:ea44dc9ed014 3337 CV_EXPORTS MatExpr operator - (const Scalar& s, const MatExpr& e);
joeverbout 0:ea44dc9ed014 3338 CV_EXPORTS MatExpr operator - (const MatExpr& e1, const MatExpr& e2);
joeverbout 0:ea44dc9ed014 3339
joeverbout 0:ea44dc9ed014 3340 CV_EXPORTS MatExpr operator - (const Mat& m);
joeverbout 0:ea44dc9ed014 3341 CV_EXPORTS MatExpr operator - (const MatExpr& e);
joeverbout 0:ea44dc9ed014 3342
joeverbout 0:ea44dc9ed014 3343 CV_EXPORTS MatExpr operator * (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3344 CV_EXPORTS MatExpr operator * (const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3345 CV_EXPORTS MatExpr operator * (double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3346 CV_EXPORTS MatExpr operator * (const MatExpr& e, const Mat& m);
joeverbout 0:ea44dc9ed014 3347 CV_EXPORTS MatExpr operator * (const Mat& m, const MatExpr& e);
joeverbout 0:ea44dc9ed014 3348 CV_EXPORTS MatExpr operator * (const MatExpr& e, double s);
joeverbout 0:ea44dc9ed014 3349 CV_EXPORTS MatExpr operator * (double s, const MatExpr& e);
joeverbout 0:ea44dc9ed014 3350 CV_EXPORTS MatExpr operator * (const MatExpr& e1, const MatExpr& e2);
joeverbout 0:ea44dc9ed014 3351
joeverbout 0:ea44dc9ed014 3352 CV_EXPORTS MatExpr operator / (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3353 CV_EXPORTS MatExpr operator / (const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3354 CV_EXPORTS MatExpr operator / (double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3355 CV_EXPORTS MatExpr operator / (const MatExpr& e, const Mat& m);
joeverbout 0:ea44dc9ed014 3356 CV_EXPORTS MatExpr operator / (const Mat& m, const MatExpr& e);
joeverbout 0:ea44dc9ed014 3357 CV_EXPORTS MatExpr operator / (const MatExpr& e, double s);
joeverbout 0:ea44dc9ed014 3358 CV_EXPORTS MatExpr operator / (double s, const MatExpr& e);
joeverbout 0:ea44dc9ed014 3359 CV_EXPORTS MatExpr operator / (const MatExpr& e1, const MatExpr& e2);
joeverbout 0:ea44dc9ed014 3360
joeverbout 0:ea44dc9ed014 3361 CV_EXPORTS MatExpr operator < (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3362 CV_EXPORTS MatExpr operator < (const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3363 CV_EXPORTS MatExpr operator < (double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3364
joeverbout 0:ea44dc9ed014 3365 CV_EXPORTS MatExpr operator <= (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3366 CV_EXPORTS MatExpr operator <= (const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3367 CV_EXPORTS MatExpr operator <= (double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3368
joeverbout 0:ea44dc9ed014 3369 CV_EXPORTS MatExpr operator == (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3370 CV_EXPORTS MatExpr operator == (const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3371 CV_EXPORTS MatExpr operator == (double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3372
joeverbout 0:ea44dc9ed014 3373 CV_EXPORTS MatExpr operator != (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3374 CV_EXPORTS MatExpr operator != (const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3375 CV_EXPORTS MatExpr operator != (double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3376
joeverbout 0:ea44dc9ed014 3377 CV_EXPORTS MatExpr operator >= (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3378 CV_EXPORTS MatExpr operator >= (const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3379 CV_EXPORTS MatExpr operator >= (double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3380
joeverbout 0:ea44dc9ed014 3381 CV_EXPORTS MatExpr operator > (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3382 CV_EXPORTS MatExpr operator > (const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3383 CV_EXPORTS MatExpr operator > (double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3384
joeverbout 0:ea44dc9ed014 3385 CV_EXPORTS MatExpr operator & (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3386 CV_EXPORTS MatExpr operator & (const Mat& a, const Scalar& s);
joeverbout 0:ea44dc9ed014 3387 CV_EXPORTS MatExpr operator & (const Scalar& s, const Mat& a);
joeverbout 0:ea44dc9ed014 3388
joeverbout 0:ea44dc9ed014 3389 CV_EXPORTS MatExpr operator | (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3390 CV_EXPORTS MatExpr operator | (const Mat& a, const Scalar& s);
joeverbout 0:ea44dc9ed014 3391 CV_EXPORTS MatExpr operator | (const Scalar& s, const Mat& a);
joeverbout 0:ea44dc9ed014 3392
joeverbout 0:ea44dc9ed014 3393 CV_EXPORTS MatExpr operator ^ (const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3394 CV_EXPORTS MatExpr operator ^ (const Mat& a, const Scalar& s);
joeverbout 0:ea44dc9ed014 3395 CV_EXPORTS MatExpr operator ^ (const Scalar& s, const Mat& a);
joeverbout 0:ea44dc9ed014 3396
joeverbout 0:ea44dc9ed014 3397 CV_EXPORTS MatExpr operator ~(const Mat& m);
joeverbout 0:ea44dc9ed014 3398
joeverbout 0:ea44dc9ed014 3399 CV_EXPORTS MatExpr min(const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3400 CV_EXPORTS MatExpr min(const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3401 CV_EXPORTS MatExpr min(double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3402
joeverbout 0:ea44dc9ed014 3403 CV_EXPORTS MatExpr max(const Mat& a, const Mat& b);
joeverbout 0:ea44dc9ed014 3404 CV_EXPORTS MatExpr max(const Mat& a, double s);
joeverbout 0:ea44dc9ed014 3405 CV_EXPORTS MatExpr max(double s, const Mat& a);
joeverbout 0:ea44dc9ed014 3406
joeverbout 0:ea44dc9ed014 3407 /** @brief Calculates an absolute value of each matrix element.
joeverbout 0:ea44dc9ed014 3408
joeverbout 0:ea44dc9ed014 3409 abs is a meta-function that is expanded to one of absdiff or convertScaleAbs forms:
joeverbout 0:ea44dc9ed014 3410 - C = abs(A-B) is equivalent to `absdiff(A, B, C)`
joeverbout 0:ea44dc9ed014 3411 - C = abs(A) is equivalent to `absdiff(A, Scalar::all(0), C)`
joeverbout 0:ea44dc9ed014 3412 - C = `Mat_<Vec<uchar,n> >(abs(A*alpha + beta))` is equivalent to `convertScaleAbs(A, C, alpha,
joeverbout 0:ea44dc9ed014 3413 beta)`
joeverbout 0:ea44dc9ed014 3414
joeverbout 0:ea44dc9ed014 3415 The output matrix has the same size and the same type as the input one except for the last case,
joeverbout 0:ea44dc9ed014 3416 where C is depth=CV_8U .
joeverbout 0:ea44dc9ed014 3417 @param m matrix.
joeverbout 0:ea44dc9ed014 3418 @sa @ref MatrixExpressions, absdiff, convertScaleAbs
joeverbout 0:ea44dc9ed014 3419 */
joeverbout 0:ea44dc9ed014 3420 CV_EXPORTS MatExpr abs(const Mat& m);
joeverbout 0:ea44dc9ed014 3421 /** @overload
joeverbout 0:ea44dc9ed014 3422 @param e matrix expression.
joeverbout 0:ea44dc9ed014 3423 */
joeverbout 0:ea44dc9ed014 3424 CV_EXPORTS MatExpr abs(const MatExpr& e);
joeverbout 0:ea44dc9ed014 3425 //! @} relates cv::MatExpr
joeverbout 0:ea44dc9ed014 3426
joeverbout 0:ea44dc9ed014 3427 } // cv
joeverbout 0:ea44dc9ed014 3428
joeverbout 0:ea44dc9ed014 3429 #include "opencv2/core/mat.inl.hpp"
joeverbout 0:ea44dc9ed014 3430
joeverbout 0:ea44dc9ed014 3431 #endif // __OPENCV_CORE_MAT_HPP__
joeverbout 0:ea44dc9ed014 3432