ndimensional dense array class More...
#include <opencv2/core/mat.hpp>
Public Types  
enum  { MAGIC_VAL = 0x42FF0000 , AUTO_STEP = 0 , CONTINUOUS_FLAG = CV_MAT_CONT_FLAG , SUBMATRIX_FLAG = CV_SUBMAT_FLAG } 
enum  { MAGIC_MASK = 0xFFFF0000 , TYPE_MASK = 0x00000FFF , DEPTH_MASK = 7 } 
Public Member Functions  
Mat () CV_NOEXCEPT  
Mat (const cuda::GpuMat &m)  
download data from GpuMat  
Mat (const Mat &m)  
Mat (const Mat &m, const Range &rowRange, const Range &colRange=Range::all())  
Mat (const Mat &m, const Range *ranges)  
Mat (const Mat &m, const Rect &roi)  
Mat (const Mat &m, const std::vector< Range > &ranges)  
template<typename _Tp >  
Mat (const MatCommaInitializer_< _Tp > &commaInitializer)  
template<typename _Tp , int m, int n>  
Mat (const Matx< _Tp, m, n > &mtx, bool copyData=true)  
template<typename _Tp >  
Mat (const Point3_< _Tp > &pt, bool copyData=true)  
template<typename _Tp >  
Mat (const Point_< _Tp > &pt, bool copyData=true)  
template<typename _Tp , size_t _Nm>  
Mat (const std::array< _Tp, _Nm > &arr, bool copyData=false)  
template<typename _Tp , typename = typename std::enable_if<std::is_arithmetic<_Tp>::value>::type>  
Mat (const std::initializer_list< _Tp > list)  
template<typename _Tp >  
Mat (const std::initializer_list< int > sizes, const std::initializer_list< _Tp > list)  
template<typename _Tp >  
Mat (const std::vector< _Tp > &vec, bool copyData=false)  
Mat (const std::vector< int > &sizes, int type)  
Mat (const std::vector< int > &sizes, int type, const Scalar &s)  
Mat (const std::vector< int > &sizes, int type, void *data, const size_t *steps=0)  
template<typename _Tp , int n>  
Mat (const Vec< _Tp, n > &vec, bool copyData=true)  
Mat (int ndims, const int *sizes, int type)  
Mat (int ndims, const int *sizes, int type, const Scalar &s)  
Mat (int ndims, const int *sizes, int type, void *data, const size_t *steps=0)  
Mat (int rows, int cols, int type)  
Mat (int rows, int cols, int type, const Scalar &s)  
Mat (int rows, int cols, int type, void *data, size_t step=AUTO_STEP)  
Mat (Mat &&m)  
Mat (Size size, int type)  
Mat (Size size, int type, const Scalar &s)  
Mat (Size size, int type, void *data, size_t step=AUTO_STEP)  
~Mat ()  
destructor  calls release()  
void  addref () 
Increments the reference counter.  
Mat &  adjustROI (int dtop, int dbottom, int dleft, int dright) 
Adjusts a submatrix size and position within the parent matrix.  
void  assignTo (Mat &m, int type=1) const 
Provides a functional form of convertTo.  
template<typename _Tp >  
_Tp &  at (const int *idx) 
template<typename _Tp >  
const _Tp &  at (const int *idx) const 
template<typename _Tp , int n>  
_Tp &  at (const Vec< int, n > &idx) 
template<typename _Tp , int n>  
const _Tp &  at (const Vec< int, n > &idx) const 
template<typename _Tp >  
_Tp &  at (int i0, int i1, int i2) 
template<typename _Tp >  
const _Tp &  at (int i0, int i1, int i2) const 
template<typename _Tp >  
_Tp &  at (int i0=0) 
Returns a reference to the specified array element.  
template<typename _Tp >  
const _Tp &  at (int i0=0) const 
template<typename _Tp >  
_Tp &  at (int row, int col) 
template<typename _Tp >  
const _Tp &  at (int row, int col) const 
template<typename _Tp >  
_Tp &  at (Point pt) 
template<typename _Tp >  
const _Tp &  at (Point pt) const 
template<typename _Tp >  
MatIterator_< _Tp >  begin () 
Returns the matrix iterator and sets it to the first matrix element.  
template<typename _Tp >  
MatConstIterator_< _Tp >  begin () const 
int  channels () const 
Returns the number of matrix channels.  
int  checkVector (int elemChannels, int depth=1, bool requireContinuous=true) const 
CV_NODISCARD_STD Mat  clone () const 
Creates a full copy of the array and the underlying data.  
Mat  col (int x) const 
Creates a matrix header for the specified matrix column.  
Mat  colRange (const Range &r) const 
Mat  colRange (int startcol, int endcol) const 
Creates a matrix header for the specified column span.  
void  convertTo (OutputArray m, int rtype, double alpha=1, double beta=0) const 
Converts an array to another data type with optional scaling.  
void  copySize (const Mat &m) 
internal use function; properly reallocates _size, _step arrays  
void  copyTo (OutputArray m) const 
Copies the matrix to another one.  
void  copyTo (OutputArray m, InputArray mask) const 
void  create (const std::vector< int > &sizes, int type) 
void  create (int ndims, const int *sizes, int type) 
void  create (int rows, int cols, int type) 
Allocates new array data if needed.  
void  create (Size size, int type) 
Mat  cross (InputArray m) const 
Computes a crossproduct of two 3element vectors.  
void  deallocate () 
internal use function, consider to use 'release' method instead; deallocates the matrix data  
int  depth () const 
Returns the depth of a matrix element.  
Mat  diag (int d=0) const 
Extracts a diagonal from a matrix.  
double  dot (InputArray m) const 
Computes a dotproduct of two vectors.  
size_t  elemSize () const 
Returns the matrix element size in bytes.  
size_t  elemSize1 () const 
Returns the size of each matrix element channel in bytes.  
bool  empty () const 
Returns true if the array has no elements.  
template<typename _Tp >  
MatIterator_< _Tp >  end () 
Returns the matrix iterator and sets it to the afterlast matrix element.  
template<typename _Tp >  
MatConstIterator_< _Tp >  end () const 
template<typename _Tp , typename Functor >  
void  forEach (const Functor &operation) 
Runs the given functor over all matrix elements in parallel.  
template<typename _Tp , typename Functor >  
void  forEach (const Functor &operation) const 
UMat  getUMat (AccessFlag accessFlags, UMatUsageFlags usageFlags=USAGE_DEFAULT) const 
retrieve UMat from Mat  
MatExpr  inv (int method=DECOMP_LU) const 
Inverses a matrix.  
bool  isContinuous () const 
Reports whether the matrix is continuous or not.  
bool  isSubmatrix () const 
returns true if the matrix is a submatrix of another matrix  
void  locateROI (Size &wholeSize, Point &ofs) const 
Locates the matrix header within a parent matrix.  
MatExpr  mul (InputArray m, double scale=1) const 
Performs an elementwise multiplication or division of the two matrices.  
template<typename _Tp , int m, int n>  
operator Matx< _Tp, m, n > () const  
template<typename _Tp , std::size_t _Nm>  
operator std::array< _Tp, _Nm > () const  
template<typename _Tp >  
operator std::vector< _Tp > () const  
template<typename _Tp , int n>  
operator Vec< _Tp, n > () const  
Mat  operator() (const Range *ranges) const 
Mat  operator() (const Rect &roi) const 
Mat  operator() (const std::vector< Range > &ranges) const 
Mat  operator() (Range rowRange, Range colRange) const 
Extracts a rectangular submatrix.  
Mat &  operator= (const Mat &m) 
assignment operators  
Mat &  operator= (const MatExpr &expr) 
Mat &  operator= (const Scalar &s) 
Sets all or some of the array elements to the specified value.  
Mat &  operator= (Mat &&m) 
void  pop_back (size_t nelems=1) 
Removes elements from the bottom of the matrix.  
uchar *  ptr (const int *idx) 
template<typename _Tp >  
_Tp *  ptr (const int *idx) 
const uchar *  ptr (const int *idx) const 
template<typename _Tp >  
const _Tp *  ptr (const int *idx) const 
template<int n>  
uchar *  ptr (const Vec< int, n > &idx) 
template<typename _Tp , int n>  
_Tp *  ptr (const Vec< int, n > &idx) 
template<int n>  
const uchar *  ptr (const Vec< int, n > &idx) const 
template<typename _Tp , int n>  
const _Tp *  ptr (const Vec< int, n > &idx) const 
uchar *  ptr (int i0, int i1, int i2) 
template<typename _Tp >  
_Tp *  ptr (int i0, int i1, int i2) 
const uchar *  ptr (int i0, int i1, int i2) const 
template<typename _Tp >  
const _Tp *  ptr (int i0, int i1, int i2) const 
uchar *  ptr (int i0=0) 
Returns a pointer to the specified matrix row.  
template<typename _Tp >  
_Tp *  ptr (int i0=0) 
const uchar *  ptr (int i0=0) const 
template<typename _Tp >  
const _Tp *  ptr (int i0=0) const 
uchar *  ptr (int row, int col) 
template<typename _Tp >  
_Tp *  ptr (int row, int col) 
const uchar *  ptr (int row, int col) const 
template<typename _Tp >  
const _Tp *  ptr (int row, int col) const 
template<typename _Tp >  
void  push_back (const _Tp &elem) 
Adds elements to the bottom of the matrix.  
void  push_back (const Mat &m) 
template<typename _Tp >  
void  push_back (const Mat_< _Tp > &elem) 
template<typename _Tp >  
void  push_back (const std::vector< _Tp > &elem) 
void  push_back_ (const void *elem) 
internal function  
template<typename _Tp >  
std::reverse_iterator< MatIterator_< _Tp > >  rbegin () 
Same as begin() but for inverse traversal.  
template<typename _Tp >  
std::reverse_iterator< MatConstIterator_< _Tp > >  rbegin () const 
void  release () 
Decrements the reference counter and deallocates the matrix if needed.  
template<typename _Tp >  
std::reverse_iterator< MatIterator_< _Tp > >  rend () 
Same as end() but for inverse traversal.  
template<typename _Tp >  
std::reverse_iterator< MatConstIterator_< _Tp > >  rend () const 
void  reserve (size_t sz) 
Reserves space for the certain number of rows.  
void  reserveBuffer (size_t sz) 
Reserves space for the certain number of bytes.  
Mat  reshape (int cn, const std::vector< int > &newshape) const 
Mat  reshape (int cn, int newndims, const int *newsz) const 
Mat  reshape (int cn, int rows=0) const 
Changes the shape and/or the number of channels of a 2D matrix without copying the data.  
void  resize (size_t sz) 
Changes the number of matrix rows.  
void  resize (size_t sz, const Scalar &s) 
Mat  row (int y) const 
Creates a matrix header for the specified matrix row.  
Mat  rowRange (const Range &r) const 
Mat  rowRange (int startrow, int endrow) const 
Creates a matrix header for the specified row span.  
Mat &  setTo (InputArray value, InputArray mask=noArray()) 
Sets all or some of the array elements to the specified value.  
size_t  step1 (int i=0) const 
Returns a normalized step.  
MatExpr  t () const 
Transposes a matrix.  
size_t  total () const 
Returns the total number of array elements.  
size_t  total (int startDim, int endDim=INT_MAX) const 
Returns the total number of array elements.  
int  type () const 
Returns the type of a matrix element.  
void  updateContinuityFlag () 
internal use method: updates the continuity flag  
Static Public Member Functions  
static CV_NODISCARD_STD Mat  diag (const Mat &d) 
creates a diagonal matrix  
static CV_NODISCARD_STD MatExpr  eye (int rows, int cols, int type) 
Returns an identity matrix of the specified size and type.  
static CV_NODISCARD_STD MatExpr  eye (Size size, int type) 
static MatAllocator *  getDefaultAllocator () 
static MatAllocator *  getStdAllocator () 
and the standard allocator  
static CV_NODISCARD_STD MatExpr  ones (int ndims, const int *sz, int type) 
static CV_NODISCARD_STD MatExpr  ones (int rows, int cols, int type) 
Returns an array of all 1's of the specified size and type.  
static CV_NODISCARD_STD MatExpr  ones (Size size, int type) 
static void  setDefaultAllocator (MatAllocator *allocator) 
static CV_NODISCARD_STD MatExpr  zeros (int ndims, const int *sz, int type) 
static CV_NODISCARD_STD MatExpr  zeros (int rows, int cols, int type) 
Returns a zero array of the specified size and type.  
static CV_NODISCARD_STD MatExpr  zeros (Size size, int type) 
Public Attributes  
MatAllocator *  allocator 
custom allocator  
int  cols 
uchar *  data 
pointer to the data  
const uchar *  dataend 
const uchar *  datalimit 
const uchar *  datastart 
helper fields used in locateROI and adjustROI  
int  dims 
the matrix dimensionality, >= 2  
int  flags 
int  rows 
the number of rows and columns or (1, 1) when the matrix has more than 2 dimensions  
MatSize  size 
MatStep  step 
UMatData *  u 
interaction with UMat  
Protected Member Functions  
template<typename _Tp , typename Functor >  
void  forEach_impl (const Functor &operation) 
Detailed Description
ndimensional dense array class
The class Mat represents an ndimensional dense numerical singlechannel or multichannel array. It can be used to store real or complexvalued vectors and matrices, grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms (though, very highdimensional histograms may be better stored in a SparseMat ). The data layout of the array M
is defined by the array M.step[]
, so that the address of element \((i_0,...,i_{M.dims1})\), where \(0\leq i_k<M.size[k]\), is computed as:
\[addr(M_{i_0,...,i_{M.dims1}}) = M.data + M.step[0]*i_0 + M.step[1]*i_1 + ... + M.step[M.dims1]*i_{M.dims1}\]
In case of a 2dimensional array, the above formula is reduced to:
\[addr(M_{i,j}) = M.data + M.step[0]*i + M.step[1]*j\]
Note that M.step[i] >= M.step[i+1]
(in fact, M.step[i] >= M.step[i+1]*M.size[i+1]
). This means that 2dimensional matrices are stored rowbyrow, 3dimensional matrices are stored planebyplane, and so on. M.step[M.dims1] is minimal and always equal to the element size M.elemSize() .
So, the data layout in Mat is compatible with the majority of dense array types from the standard toolkits and SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, that is, with any array that uses steps (or strides) to compute the position of a pixel. Due to this compatibility, it is possible to make a Mat header for userallocated data and process it inplace using OpenCV functions.
There are many different ways to create a Mat object. The most popular options are listed below:
 Use the create(nrows, ncols, type) method or the similar Mat(nrows, ncols, type[, fillValue]) constructor. A new array of the specified size and type is allocated. type has the same meaning as in the cvCreateMat method. For example, CV_8UC1 means a 8bit singlechannel array, CV_32FC2 means a 2channel (complex) floatingpoint array, and so on. As noted in the introduction to this chapter, create() allocates only a new array when the shape or type of the current array are different from the specified ones.// make a 7x7 complex matrix filled with 1+3j.// and now turn M to a 100x60 15channel 8bit matrix.// The old content will be deallocatedM.create(100,60,CV_8UC(15));
 Create a multidimensional array: It passes the number of dimensions =1 to the Mat constructor but the created array will be 2dimensional with the number of columns set to 1. So, Mat::dims is always >= 2 (can also be 0 when the array is empty).// create a 100x100x100 8bit arrayint sz[] = {100, 100, 100};static Scalar_< double > all(double v0)returns a scalar with all elements set to v0
 Use a copy constructor or assignment operator where there can be an array or expression on the right side (see below). As noted in the introduction, the array assignment is an O(1) operation because it only copies the header and increases the reference counter. The Mat::clone() method can be used to get a full (deep) copy of the array when you need it.
 Construct a header for a part of another array. It can be a single row, single column, several rows, several columns, rectangular region in the array (called a minor in algebra) or a diagonal. Such operations are also O(1) because the new header references the same data. You can actually modify a part of the array using this feature, for example: Due to the additional datastart and dataend members, it is possible to compute a relative subarray position in the main container array using locateROI():// add the 5th row, multiplied by 3 to the 3rd rowM.row(3) = M.row(3) + M.row(5)*3;// now copy the 7th column to the 1st column// M.col(1) = M.col(7); // this will not work// create a new 320x240 image// select a ROI// fill the ROI with (0,255,0) (which is green in RGB space);// the original 320x240 image will be modifiedroi = Scalar(0,255,0);// extracts A columns, 1 (inclusive) to 3 (exclusive).// extracts B rows, 5 (inclusive) to 9 (exclusive).// that is, C \~ A(Range(5, 9), Range(1, 3))// size will be (width=10,height=10) and the ofs will be (x=1, y=5)void locateROI(Size &wholeSize, Point &ofs) constLocates the matrix header within a parent matrix.static CV_NODISCARD_STD MatExpr eye(int rows, int cols, int type)Returns an identity matrix of the specified size and type.Template class specifying a continuous subsequence (slice) of a sequence.Definition: types.hpp:623static Range all()
clone()
method of the extracted submatrices.  Make a header for userallocated data. It can be useful to do the following:
 Process "foreign" data using OpenCV (for example, when you implement a DirectShow* filter or a processing module for gstreamer, and so on). For example: {// wrap input bufferMat result;GaussianBlur(img, result, Size(7, 7), 1.5, 1.5);return result;}void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT)Blurs an image using a Gaussian filter.
 Quickly initialize small matrices and/or get a superfast element access. double m[3][3] = {{a, b, c}, {d, e, f}, {g, h, i}};Mat() CV_NOEXCEPT
 Process "foreign" data using OpenCV (for example, when you implement a DirectShow* filter or a processing module for gstreamer, and so on). For example:
 Use MATLABstyle array initializers, zeros(), ones(), eye(), for example:
 Use a commaseparated initializer: With this approach, you first call a constructor of the Mat class with the proper parameters, and then you just put// create a 3x3 doubleprecision identity matrixMat M = (Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
<< operator
followed by commaseparated values that can be constants, variables, expressions, and so on. Also, note the extra parentheses required to avoid compilation errors.
Once the array is created, it is automatically managed via a referencecounting mechanism. If the array header is built on top of userallocated data, you should handle the data by yourself. The array data is deallocated when no one points to it. If you want to release the data pointed by a array header before the array destructor is called, use Mat::release().
The next important thing to learn about the array class is element access. This manual already described how to compute an address of each array element. Normally, you are not required to use the formula directly in the code. If you know the array element type (which can be retrieved using the method Mat::type() ), you can access the element \(M_{ij}\) of a 2dimensional array as:
assuming that M
is a doubleprecision floatingpoint array. There are several variants of the method at for a different number of dimensions.
If you need to process a whole row of a 2D array, the most efficient way is to get the pointer to the row first, and then just use the plain C operator [] :
Some operations, like the one above, do not actually depend on the array shape. They just process elements of an array one by one (or elements from multiple arrays that have the same coordinates, for example, array addition). Such operations are called elementwise. It makes sense to check whether all the input/output arrays are continuous, namely, have no gaps at the end of each row. If yes, process them as a long single row:
In case of the continuous matrix, the outer loop body is executed just once. So, the overhead is smaller, which is especially noticeable in case of small matrices.
Finally, there are STLstyle iterators that are smart enough to skip gaps between successive rows:
The matrix iterators are randomaccess iterators, so they can be passed to any STL algorithm, including std::sort().
 Note
 Matrix Expressions and arithmetic see MatExpr
 Examples
 fld_lines.cpp, modules/shape/samples/shape_example.cpp, samples/cpp/camshiftdemo.cpp, samples/cpp/connected_components.cpp, samples/cpp/contours2.cpp, samples/cpp/convexhull.cpp, samples/cpp/cout_mat.cpp, samples/cpp/create_mask.cpp, samples/cpp/demhist.cpp, samples/cpp/distrans.cpp, samples/cpp/edge.cpp, samples/cpp/facedetect.cpp, samples/cpp/falsecolor.cpp, samples/cpp/ffilldemo.cpp, samples/cpp/filestorage.cpp, samples/cpp/fitellipse.cpp, samples/cpp/grabcut.cpp, samples/cpp/image_alignment.cpp, samples/cpp/intersectExample.cpp, samples/cpp/kalman.cpp, samples/cpp/kmeans.cpp, samples/cpp/laplace.cpp, samples/cpp/lkdemo.cpp, samples/cpp/lsd_lines.cpp, samples/cpp/minarea.cpp, samples/cpp/pca.cpp, samples/cpp/peopledetect.cpp, samples/cpp/polar_transforms.cpp, samples/cpp/segment_objects.cpp, samples/cpp/squares.cpp, samples/cpp/stitching.cpp, samples/cpp/stitching_detailed.cpp, samples/cpp/train_HOG.cpp, samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp, samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp, samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp, samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp, samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp, samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp, samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_1.cpp, samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_2.cpp, samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp, samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp, samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp, samples/cpp/tutorial_code/ImgTrans/houghlines.cpp, samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp, samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp, samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp, samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp, samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp, samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp, samples/cpp/tutorial_code/videoio/videowrite/videowrite.cpp, samples/cpp/videowriter_basic.cpp, samples/cpp/warpPerspective_demo.cpp, samples/cpp/watershed.cpp, samples/dnn/classification.cpp, samples/dnn/colorization.cpp, samples/dnn/object_detection.cpp, samples/dnn/openpose.cpp, samples/dnn/segmentation.cpp, samples/dnn/text_detection.cpp, and samples/tapi/squares.cpp.
Member Enumeration Documentation
◆ anonymous enum
◆ anonymous enum
Constructor & Destructor Documentation
◆ Mat() [1/29]
cv::Mat::Mat  (  ) 
These are various constructors that form a matrix. As noted in the AutomaticAllocation, often the default constructor is enough, and the proper matrix will be allocated by an OpenCV function. The constructed matrix can further be assigned to another matrix or matrix expression or can be allocated with Mat::create . In the former case, the old content is dereferenced.
◆ Mat() [2/29]
cv::Mat::Mat  (  int  rows, 
int  cols,  
int  type  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

rows Number of rows in a 2D array. cols Number of columns in a 2D array. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
◆ Mat() [3/29]
cv::Mat::Mat  (  Size  size, 
int  type  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
◆ Mat() [4/29]
cv::Mat::Mat  (  int  rows, 
int  cols,  
int  type,  
const Scalar &  s  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

rows Number of rows in a 2D array. cols Number of columns in a 2D array. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices. s An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use the assignment operator Mat::operator=(const Scalar& value) .
◆ Mat() [5/29]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices. s An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use the assignment operator Mat::operator=(const Scalar& value) .
◆ Mat() [6/29]
cv::Mat::Mat  (  int  ndims, 
const int *  sizes,  
int  type  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

ndims Array dimensionality. sizes Array of integers specifying an ndimensional array shape. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
◆ Mat() [7/29]
cv::Mat::Mat  (  const std::vector< int > &  sizes, 
int  type  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

sizes Array of integers specifying an ndimensional array shape. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices.
◆ Mat() [8/29]
cv::Mat::Mat  (  int  ndims, 
const int *  sizes,  
int  type,  
const Scalar &  s  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

ndims Array dimensionality. sizes Array of integers specifying an ndimensional array shape. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices. s An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use the assignment operator Mat::operator=(const Scalar& value) .
◆ Mat() [9/29]
cv::Mat::Mat  (  const std::vector< int > &  sizes, 
int  type,  
const Scalar &  s  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

sizes Array of integers specifying an ndimensional array shape. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices. s An optional value to initialize each matrix element with. To set all the matrix elements to the particular value after the construction, use the assignment operator Mat::operator=(const Scalar& value) .
◆ Mat() [10/29]
cv::Mat::Mat  (  const Mat &  m  ) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its subarray is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the subarray, use Mat::clone() .
◆ Mat() [11/29]
cv::Mat::Mat  (  int  rows, 
int  cols,  
int  type,  
void *  data,  
size_t  step = AUTO_STEP 

) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

rows Number of rows in a 2D array. cols Number of columns in a 2D array. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices. data Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it. step Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize(). See Mat::elemSize.
◆ Mat() [12/29]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the number of columns go in the reverse order. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices. data Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it. step Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed and the actual step is calculated as cols*elemSize(). See Mat::elemSize.
◆ Mat() [13/29]
cv::Mat::Mat  (  int  ndims, 
const int *  sizes,  
int  type,  
void *  data,  
const size_t *  steps = 0 

) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

ndims Array dimensionality. sizes Array of integers specifying an ndimensional array shape. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices. data Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it. steps Array of ndims1 steps in case of a multidimensional array (the last step is always set to the element size). If not specified, the matrix is assumed to be continuous.
◆ Mat() [14/29]
cv::Mat::Mat  (  const std::vector< int > &  sizes, 
int  type,  
void *  data,  
const size_t *  steps = 0 

) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

sizes Array of integers specifying an ndimensional array shape. type Array type. Use CV_8UC1, ..., CV_64FC4 to create 14 channel matrices, or CV_8UC(n), ..., CV_64FC(n) to create multichannel (up to CV_CN_MAX channels) matrices. data Pointer to the user data. Matrix constructors that take data and step parameters do not allocate matrix data. Instead, they just initialize the matrix header that points to the specified data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it. steps Array of ndims1 steps in case of a multidimensional array (the last step is always set to the element size). If not specified, the matrix is assumed to be continuous.
◆ Mat() [15/29]
cv::Mat::Mat  (  const Mat &  m, 
const Range &  rowRange,  
const Range &  colRange = Range::all() 

) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its subarray is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the subarray, use Mat::clone() . rowRange Range of the m rows to take. As usual, the range start is inclusive and the range end is exclusive. Use Range::all() to take all the rows. colRange Range of the m columns to take. Use Range::all() to take all the columns.
◆ Mat() [16/29]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its subarray is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the subarray, use Mat::clone() . roi Region of interest.
◆ Mat() [17/29]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its subarray is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the subarray, use Mat::clone() . ranges Array of selected ranges of m along each dimensionality.
◆ Mat() [18/29]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied by these constructors. Instead, the header pointing to m data or its subarray is constructed and associated with it. The reference counter, if any, is incremented. So, when you modify the matrix formed using such a constructor, you also modify the corresponding elements of m . If you want to have an independent copy of the subarray, use Mat::clone() . ranges Array of selected ranges of m along each dimensionality.
◆ Mat() [19/29]

explicit 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

vec STL vector whose elements form the matrix. The matrix has a single column and the number of rows equal to the number of vector elements. Type of the matrix matches the type of vector elements. The constructor can handle arbitrary types, for which there is a properly declared DataType . This means that the vector elements must be primitive numbers or unitype numerical tuples of numbers. Mixedtype structures are not supported. The corresponding constructor is explicit. Since STL vectors are not automatically converted to Mat instances, you should write Mat(vec) explicitly. Unless you copy the data into the matrix ( copyData=true ), no new elements will be added to the vector because it can potentially yield vector data reallocation, and, thus, the matrix data pointer will be invalid. copyData Flag to specify whether the underlying data of the STL vector should be copied to (true) or shared with (false) the newly constructed matrix. When the data is copied, the allocated buffer is managed using Mat reference counting mechanism. While the data is shared, the reference counter is NULL, and you should not deallocate the data until the matrix is destructed.
◆ Mat() [20/29]

explicit 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ Mat() [21/29]

explicit 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ Mat() [22/29]

explicit 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ Mat() [23/29]

explicit 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ Mat() [24/29]

explicit 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ Mat() [25/29]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ Mat() [26/29]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ Mat() [27/29]

explicit 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ Mat() [28/29]

explicit 
download data from GpuMat
◆ ~Mat()
cv::Mat::~Mat  (  ) 
destructor  calls release()
◆ Mat() [29/29]
cv::Mat::Mat  (  Mat &&  m  ) 
Member Function Documentation
◆ addref()
void cv::Mat::addref  (  ) 
Increments the reference counter.
The method increments the reference counter associated with the matrix data. If the matrix header points to an external data set (see Mat::Mat ), the reference counter is NULL, and the method has no effect in this case. Normally, to avoid memory leaks, the method should not be called explicitly. It is called implicitly by the matrix assignment operator. The reference counter increment is an atomic operation on the platforms that support it. Thus, it is safe to operate on the same matrices asynchronously in different threads.
◆ adjustROI()
Mat & cv::Mat::adjustROI  (  int  dtop, 
int  dbottom,  
int  dleft,  
int  dright  
) 
Adjusts a submatrix size and position within the parent matrix.
The method is complimentary to Mat::locateROI . The typical use of these functions is to determine the submatrix position within the parent matrix and then shift the position somehow. Typically, it can be required for filtering operations when pixels outside of the ROI should be taken into account. When all the method parameters are positive, the ROI needs to grow in all directions by the specified amount, for example:
In this example, the matrix size is increased by 4 elements in each direction. The matrix is shifted by 2 elements to the left and 2 elements up, which brings in all the necessary pixels for the filtering with the 5x5 kernel.
adjustROI forces the adjusted ROI to be inside of the parent matrix that is boundaries of the adjusted ROI are constrained by boundaries of the parent matrix. For example, if the submatrix A is located in the first row of a parent matrix and you called A.adjustROI(2, 2, 2, 2) then A will not be increased in the upward direction.
The function is used internally by the OpenCV filtering functions, like filter2D , morphological operations, and so on.
 Parameters

dtop Shift of the top submatrix boundary upwards. dbottom Shift of the bottom submatrix boundary downwards. dleft Shift of the left submatrix boundary to the left. dright Shift of the right submatrix boundary to the right.
 See also
 copyMakeBorder
◆ assignTo()
void cv::Mat::assignTo  (  Mat &  m, 
int  type = 1 

)  const 
Provides a functional form of convertTo.
This is an internally used method called by the MatrixExpressions engine.
 Parameters

m Destination array. type Desired destination array depth (or 1 if it should be the same as the source type).
◆ at() [1/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

idx Array of Mat::dims indices.
◆ at() [2/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

idx Array of Mat::dims indices.
◆ at() [3/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ at() [4/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ at() [5/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

i0 Index along the dimension 0 i1 Index along the dimension 1 i2 Index along the dimension 2
◆ at() [6/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

i0 Index along the dimension 0 i1 Index along the dimension 1 i2 Index along the dimension 2
◆ at() [7/12]
Returns a reference to the specified array element.
The template methods return a reference to the specified array element. For the sake of higher performance, the index range checks are only performed in the Debug configuration.
Note that the variants with a single index (i) can be used to access elements of singlerow or singlecolumn 2dimensional arrays. That is, if, for example, A is a 1 x N floatingpoint matrix and B is an M x 1 integer matrix, you can simply write A.at<float>(k+4)
and B.at<int>(2*i+1)
instead of A.at<float>(0,k+4)
and B.at<int>(2*i+1,0)
, respectively.
The example below initializes a Hilbert matrix:
Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends on the image from which you are trying to retrieve the data. The table below gives a better insight in this:
 If matrix is of type
CV_8U
then useMat.at<uchar>(y,x)
.  If matrix is of type
CV_8S
then useMat.at<schar>(y,x)
.  If matrix is of type
CV_16U
then useMat.at<ushort>(y,x)
.  If matrix is of type
CV_16S
then useMat.at<short>(y,x)
.  If matrix is of type
CV_32S
then useMat.at<int>(y,x)
.  If matrix is of type
CV_32F
then useMat.at<float>(y,x)
.  If matrix is of type
CV_64F
then useMat.at<double>(y,x)
.
 Parameters

i0 Index along the dimension 0
 Examples
 samples/cpp/camshiftdemo.cpp, samples/cpp/connected_components.cpp, samples/cpp/cout_mat.cpp, samples/cpp/demhist.cpp, samples/cpp/fitellipse.cpp, samples/cpp/image_alignment.cpp, samples/cpp/kalman.cpp, samples/cpp/kmeans.cpp, samples/cpp/train_HOG.cpp, samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp, samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp, samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp, and samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp.
◆ at() [8/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

i0 Index along the dimension 0
◆ at() [9/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

row Index along the dimension 0 col Index along the dimension 1
◆ at() [10/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

row Index along the dimension 0 col Index along the dimension 1
◆ at() [11/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. special versions for 2D arrays (especially convenient for referencing image pixels)
 Parameters

pt Element position specified as Point(j,i) .
◆ at() [12/12]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. special versions for 2D arrays (especially convenient for referencing image pixels)
 Parameters

pt Element position specified as Point(j,i) .
◆ begin() [1/2]
MatIterator_< _Tp > cv::Mat::begin  (  ) 
Returns the matrix iterator and sets it to the first matrix element.
The methods return the matrix readonly or readwrite iterators. The use of matrix iterators is very similar to the use of bidirectional STL iterators. In the example below, the alpha blending function is rewritten using the matrix iterators:
 Examples
 samples/dnn/classification.cpp.
◆ begin() [2/2]
MatConstIterator_< _Tp > cv::Mat::begin  (  )  const 
◆ channels()
int cv::Mat::channels  (  )  const 
Returns the number of matrix channels.
The method returns the number of matrix channels.
 Examples
 samples/cpp/pca.cpp.
◆ checkVector()
int cv::Mat::checkVector  (  int  elemChannels, 
int  depth = 1 , 

bool  requireContinuous = true 

)  const 
 Parameters

elemChannels Number of channels or number of columns the matrix should have. For a 2D matrix, when the matrix has only 1 column, then it should have elemChannels channels; When the matrix has only 1 channel, then it should have elemChannels columns. For a 3D matrix, it should have only one channel. Furthermore, if the number of planes is not one, then the number of rows within every plane has to be 1; if the number of rows within every plane is not 1, then the number of planes has to be 1. depth The depth the matrix should have. Set it to 1 when any depth is fine. requireContinuous Set it to true to require the matrix to be continuous
 Returns
 1 if the requirement is not satisfied. Otherwise, it returns the number of elements in the matrix. Note that an element may have multiple channels.
The following code demonstrates its usage for a 2d matrix:
The following code demonstrates its usage for a 3d matrix:
◆ clone()
CV_NODISCARD_STD Mat cv::Mat::clone  (  )  const 
Creates a full copy of the array and the underlying data.
The method creates a full copy of the array. The original step[] is not taken into account. So, the array copy is a continuous array occupying total()*elemSize() bytes.
 Examples
 samples/cpp/create_mask.cpp, samples/cpp/facedetect.cpp, samples/cpp/pca.cpp, samples/cpp/stitching_detailed.cpp, samples/cpp/train_HOG.cpp, samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp, samples/cpp/tutorial_code/ImgTrans/houghlines.cpp, samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp, samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp, samples/cpp/warpPerspective_demo.cpp, and samples/dnn/text_detection.cpp.
◆ col()
Mat cv::Mat::col  (  int  x  )  const 
Creates a matrix header for the specified matrix column.
The method makes a new header for the specified matrix column and returns it. This is an O(1) operation, regardless of the matrix size. The underlying data of the new matrix is shared with the original matrix. See also the Mat::row description.
 Parameters

x A 0based column index.
◆ colRange() [1/2]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

r Range structure containing both the start and the end indices.
◆ colRange() [2/2]
Mat cv::Mat::colRange  (  int  startcol, 
int  endcol  
)  const 
Creates a matrix header for the specified column span.
The method makes a new header for the specified column span of the matrix. Similarly to Mat::row and Mat::col , this is an O(1) operation.
 Parameters

startcol An inclusive 0based start index of the column span. endcol An exclusive 0based ending index of the column span.
 Examples
 samples/dnn/object_detection.cpp.
◆ convertTo()
void cv::Mat::convertTo  (  OutputArray  m, 
int  rtype,  
double  alpha = 1 , 

double  beta = 0 

)  const 
Converts an array to another data type with optional scaling.
The method converts source pixel values to the target data type. saturate_cast<> is applied at the end to avoid possible overflows:
\[m(x,y) = saturate \_ cast<rType>( \alpha (*this)(x,y) + \beta )\]
 Parameters

m output matrix; if it does not have a proper size or type before the operation, it is reallocated. rtype desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input. alpha optional scale factor. beta optional delta added to the scaled values.
◆ copySize()
void cv::Mat::copySize  (  const Mat &  m  ) 
internal use function; properly reallocates _size, _step arrays
◆ copyTo() [1/2]
void cv::Mat::copyTo  (  OutputArray  m  )  const 
Copies the matrix to another one.
The method copies the matrix data to another matrix. Before copying the data, the method invokes :
so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the function does not handle the case of a partial overlap between the source and the destination matrices.
When the operation mask is specified, if the Mat::create call shown above reallocates the matrix, the newly allocated matrix is initialized with all zeros before copying the data.
 Parameters

m Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.
◆ copyTo() [2/2]
void cv::Mat::copyTo  (  OutputArray  m, 
InputArray  mask  
)  const 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

m Destination matrix. If it does not have a proper size or type before the operation, it is reallocated. mask Operation mask of the same size as *this. Its nonzero elements indicate which matrix elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels.
◆ create() [1/4]
void cv::Mat::create  (  const std::vector< int > &  sizes, 
int  type  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

sizes Array of integers specifying a new array shape. type New matrix type.
◆ create() [2/4]
void cv::Mat::create  (  int  ndims, 
const int *  sizes,  
int  type  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

ndims New array dimensionality. sizes Array of integers specifying a new array shape. type New matrix type.
◆ create() [3/4]
void cv::Mat::create  (  int  rows, 
int  cols,  
int  type  
) 
Allocates new array data if needed.
This is one of the key Mat methods. Most newstyle OpenCV functions and methods that produce arrays call this method for each output array. The method uses the following algorithm:
 If the current array shape and the type match the new ones, return immediately. Otherwise, dereference the previous data by calling Mat::release.
 Initialize the new header.
 Allocate the new data of total()*elemSize() bytes.
 Allocate the new, associated with the data, reference counter and set it to 1.
Such a scheme makes the memory management robust and efficient at the same time and helps avoid extra typing for you. This means that usually there is no need to explicitly allocate output arrays. That is, instead of writing:
you can simply write:
because cvtColor, as well as the most of OpenCV functions, calls Mat::create() for the output array internally.
 Parameters

rows New number of rows. cols New number of columns. type New matrix type.
◆ create() [4/4]
void cv::Mat::create  (  Size  size, 
int  type  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

size Alternative new matrix size specification: Size(cols, rows) type New matrix type.
◆ cross()
Mat cv::Mat::cross  (  InputArray  m  )  const 
Computes a crossproduct of two 3element vectors.
The method computes a crossproduct of two 3element vectors. The vectors must be 3element floatingpoint vectors of the same shape and size. The result is another 3element vector of the same shape and type as operands.
 Parameters

m Another crossproduct operand.
◆ deallocate()
void cv::Mat::deallocate  (  ) 
internal use function, consider to use 'release' method instead; deallocates the matrix data
◆ depth()
int cv::Mat::depth  (  )  const 
Returns the depth of a matrix element.
The method returns the identifier of the matrix element depth (the type of each individual channel). For example, for a 16bit signed element array, the method returns CV_16S . A complete list of matrix types contains the following values:
 CV_8U  8bit unsigned integers ( 0..255 )
 CV_8S  8bit signed integers ( 128..127 )
 CV_16U  16bit unsigned integers ( 0..65535 )
 CV_16S  16bit signed integers ( 32768..32767 )
 CV_32S  32bit signed integers ( 2147483648..2147483647 )
 CV_32F  32bit floatingpoint numbers ( FLT_MAX..FLT_MAX, INF, NAN )
 CV_64F  64bit floatingpoint numbers ( DBL_MAX..DBL_MAX, INF, NAN )
 Examples
 samples/cpp/camshiftdemo.cpp.
◆ diag() [1/2]

static 
creates a diagonal matrix
The method creates a square diagonal matrix from specified main diagonal.
 Parameters

d Onedimensional matrix that represents the main diagonal.
◆ diag() [2/2]
Mat cv::Mat::diag  (  int  d = 0  )  const 
Extracts a diagonal from a matrix.
The method makes a new header for the specified matrix diagonal. The new matrix is represented as a singlecolumn matrix. Similarly to Mat::row and Mat::col, this is an O(1) operation.
 Parameters

d index of the diagonal, with the following values: d=0
is the main diagonal.d<0
is a diagonal from the lower half. For example, d=1 means the diagonal is set immediately below the main one.d>0
is a diagonal from the upper half. For example, d=1 means the diagonal is set immediately above the main one. For example:1,2,3,4,5,6,7,8,9);d0 =[1;5;9]d1 =[2;6]d_1 =[4;8]
◆ dot()
double cv::Mat::dot  (  InputArray  m  )  const 
Computes a dotproduct of two vectors.
The method computes a dotproduct of two matrices. If the matrices are not singlecolumn or singlerow vectors, the toptobottom lefttoright scan ordering is used to treat them as 1D vectors. The vectors must have the same size and type. If the matrices have more than one channel, the dot products from all the channels are summed together.
 Parameters

m another dotproduct operand.
◆ elemSize()
size_t cv::Mat::elemSize  (  )  const 
Returns the matrix element size in bytes.
The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 , the method returns 3*sizeof(short) or 6.
◆ elemSize1()
size_t cv::Mat::elemSize1  (  )  const 
Returns the size of each matrix element channel in bytes.
The method returns the matrix element channel size in bytes, that is, it ignores the number of channels. For example, if the matrix type is CV_16SC3 , the method returns sizeof(short) or 2.
◆ empty()
bool cv::Mat::empty  (  )  const 
Returns true if the array has no elements.
The method returns true if Mat::total() is 0 or if Mat::data is NULL. Because of pop_back() and resize() methods M.total() == 0
does not imply that M.data == NULL
.
 Examples
 fld_lines.cpp, samples/cpp/facedetect.cpp, samples/cpp/fitellipse.cpp, samples/cpp/grabcut.cpp, samples/cpp/image_alignment.cpp, samples/cpp/laplace.cpp, samples/cpp/lkdemo.cpp, samples/cpp/segment_objects.cpp, samples/cpp/squares.cpp, samples/cpp/stitching.cpp, samples/cpp/stitching_detailed.cpp, samples/cpp/train_HOG.cpp, samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp, samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp, samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp, samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp, samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp, samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp, samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp, samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp, samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp, samples/cpp/tutorial_code/ImgTrans/houghlines.cpp, samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp, samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp, samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp, samples/cpp/videowriter_basic.cpp, samples/cpp/watershed.cpp, samples/dnn/colorization.cpp, samples/dnn/object_detection.cpp, samples/dnn/openpose.cpp, and samples/dnn/segmentation.cpp.
◆ end() [1/2]
MatIterator_< _Tp > cv::Mat::end  (  ) 
Returns the matrix iterator and sets it to the afterlast matrix element.
The methods return the matrix readonly or readwrite iterators, set to the point following the last matrix element.
 Examples
 samples/dnn/classification.cpp.
◆ end() [2/2]
MatConstIterator_< _Tp > cv::Mat::end  (  )  const 
◆ eye() [1/2]

static 
Returns an identity matrix of the specified size and type.
The method returns a Matlabstyle identity matrix initializer, similarly to Mat::zeros. Similarly to Mat::ones, you can use a scale operation to create a scaled identity matrix efficiently:
 Note
 In case of multichannels type, identity matrix will be initialized only for the first channel, the others will be set to 0's
 Parameters

rows Number of rows. cols Number of columns. type Created matrix type.
◆ eye() [2/2]

static 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

size Alternative matrix size specification as Size(cols, rows) . type Created matrix type.
◆ forEach() [1/2]
void cv::Mat::forEach  (  const Functor &  operation  ) 
Runs the given functor over all matrix elements in parallel.
The operation passed as argument has to be a function pointer, a function object or a lambda(C++11).
Example 1. All of the operations below put 0xFF the first channel of all matrix elements:
Example 2. Using the pixel's position:
◆ forEach() [2/2]
void cv::Mat::forEach  (  const Functor &  operation  )  const 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ getDefaultAllocator()

static 
◆ getStdAllocator()

static 
and the standard allocator
◆ getUMat()
UMat cv::Mat::getUMat  (  AccessFlag  accessFlags, 
UMatUsageFlags  usageFlags = USAGE_DEFAULT 

)  const 
◆ inv()
Inverses a matrix.
The method performs a matrix inversion by means of matrix expressions. This means that a temporary matrix inversion object is returned by the method and can be used further as a part of more complex matrix expressions or can be assigned to a matrix.
 Parameters

method Matrix inversion method. One of cv::DecompTypes
◆ isContinuous()
bool cv::Mat::isContinuous  (  )  const 
Reports whether the matrix is continuous or not.
The method returns true if the matrix elements are stored continuously without gaps at the end of each row. Otherwise, it returns false. Obviously, 1x1 or 1xN matrices are always continuous. Matrices created with Mat::create are always continuous. But if you extract a part of the matrix using Mat::col, Mat::diag, and so on, or constructed a matrix header for externally allocated data, such matrices may no longer have this property.
The continuity flag is stored as a bit in the Mat::flags field and is computed automatically when you construct a matrix header. Thus, the continuity check is a very fast operation, though theoretically it could be done as follows:
The method is used in quite a few of OpenCV functions. The point is that elementwise operations (such as arithmetic and logical operations, math functions, alpha blending, color space transformations, and others) do not depend on the image geometry. Thus, if all the input and output arrays are continuous, the functions can process them as very long singlerow vectors. The example below illustrates how an alphablending function can be implemented:
This approach, while being very simple, can boost the performance of a simple elementoperation by 1020 percents, especially if the image is rather small and the operation is quite simple.
Another OpenCV idiom in this function, a call of Mat::create for the destination array, that allocates the destination array unless it already has the proper size and type. And while the newly allocated arrays are always continuous, you still need to check the destination array because Mat::create does not always allocate a new matrix.
◆ isSubmatrix()
bool cv::Mat::isSubmatrix  (  )  const 
returns true if the matrix is a submatrix of another matrix
◆ locateROI()
Locates the matrix header within a parent matrix.
After you extracted a submatrix from a matrix using Mat::row, Mat::col, Mat::rowRange, Mat::colRange, and others, the resultant submatrix points just to the part of the original big matrix. However, each submatrix contains information (represented by datastart and dataend fields) that helps reconstruct the original matrix size and the position of the extracted submatrix within the original matrix. The method locateROI does exactly that.
 Parameters

wholeSize Output parameter that contains the size of the whole matrix containing this as a part. ofs Output parameter that contains an offset of this inside the whole matrix.
◆ mul()
MatExpr cv::Mat::mul  (  InputArray  m, 
double  scale = 1 

)  const 
Performs an elementwise multiplication or division of the two matrices.
The method returns a temporary object encoding perelement array multiplication, with optional scale. Note that this is not a matrix multiplication that corresponds to a simpler "\*" operator.
Example:
 Parameters

m Another array of the same type and the same size as *this, or a matrix expression. scale Optional scale factor.
◆ ones() [1/3]

static 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

ndims Array dimensionality. sz Array of integers specifying the array shape. type Created matrix type.
◆ ones() [2/3]

static 
Returns an array of all 1's of the specified size and type.
The method returns a Matlabstyle 1's array initializer, similarly to Mat::zeros. Note that using this method you can initialize an array with an arbitrary value, using the following Matlab idiom:
The above operation does not form a 100x100 matrix of 1's and then multiply it by 3. Instead, it just remembers the scale factor (3 in this case) and use it when actually invoking the matrix initializer.
 Note
 In case of multichannels type, only the first channel will be initialized with 1's, the others will be set to 0's.
 Parameters

rows Number of rows. cols Number of columns. type Created matrix type.
◆ ones() [3/3]

static 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

size Alternative to the matrix size specification Size(cols, rows) . type Created matrix type.
◆ operator Matx< _Tp, m, n >()
◆ operator std::array< _Tp, _Nm >()
◆ operator std::vector< _Tp >()
◆ operator Vec< _Tp, n >()
◆ operator()() [1/4]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

ranges Array of selected ranges along each array dimension.
◆ operator()() [2/4]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

roi Extracted submatrix specified as a rectangle.
◆ operator()() [3/4]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

ranges Array of selected ranges along each array dimension.
◆ operator()() [4/4]
Extracts a rectangular submatrix.
The operators make a new header for the specified subarray of *this . They are the most generalized forms of Mat::row, Mat::col, Mat::rowRange, and Mat::colRange . For example, A(Range(0, 10), Range::all())
is equivalent to A.rowRange(0, 10)
. Similarly to all of the above, the operators are O(1) operations, that is, no matrix data is copied.
 Parameters

rowRange Start and end row of the extracted submatrix. The upper boundary is not included. To select all the rows, use Range::all(). colRange Start and end column of the extracted submatrix. The upper boundary is not included. To select all the columns, use Range::all().
◆ operator=() [1/4]
assignment operators
These are available assignment operators. Since they all are very different, make sure to read the operator parameters description.
 Parameters

m Assigned, righthandside matrix. Matrix assignment is an O(1) operation. This means that no data is copied but the data is shared and the reference counter, if any, is incremented. Before assigning new data, the old data is dereferenced via Mat::release .
◆ operator=() [2/4]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

expr Assigned matrix expression object. As opposite to the first form of the assignment operation, the second form can reuse already allocated matrix if it has the right size and type to fit the matrix expression result. It is automatically handled by the real function that the matrix expressions is expanded to. For example, C=A+B is expanded to add(A, B, C), and add takes care of automatic C reallocation.
◆ operator=() [3/4]
Sets all or some of the array elements to the specified value.
 Parameters

s Assigned scalar converted to the actual array type.
◆ operator=() [4/4]
◆ pop_back()
void cv::Mat::pop_back  (  size_t  nelems = 1  ) 
Removes elements from the bottom of the matrix.
The method removes one or more rows from the bottom of the matrix.
 Parameters

nelems Number of removed rows. If it is greater than the total number of rows, an exception is thrown.
◆ ptr() [1/20]
uchar * cv::Mat::ptr  (  const int *  idx  ) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [2/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [3/20]
const uchar * cv::Mat::ptr  (  const int *  idx  )  const 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [4/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [5/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [6/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [7/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [8/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [9/20]
uchar * cv::Mat::ptr  (  int  i0, 
int  i1,  
int  i2  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [10/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [11/20]
const uchar * cv::Mat::ptr  (  int  i0, 
int  i1,  
int  i2  
)  const 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [12/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [13/20]
uchar * cv::Mat::ptr  (  int  i0 = 0  ) 
Returns a pointer to the specified matrix row.
The methods return uchar*
or typed pointer to the specified matrix row. See the sample in Mat::isContinuous to know how to use these methods.
 Parameters

i0 A 0based row index.
◆ ptr() [14/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [15/20]
const uchar * cv::Mat::ptr  (  int  i0 = 0  )  const 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [16/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
◆ ptr() [17/20]
uchar * cv::Mat::ptr  (  int  row, 
int  col  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

row Index along the dimension 0 col Index along the dimension 1
◆ ptr() [18/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

row Index along the dimension 0 col Index along the dimension 1
◆ ptr() [19/20]
const uchar * cv::Mat::ptr  (  int  row, 
int  col  
)  const 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

row Index along the dimension 0 col Index along the dimension 1
◆ ptr() [20/20]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

row Index along the dimension 0 col Index along the dimension 1
◆ push_back() [1/4]
Adds elements to the bottom of the matrix.
The methods add one or more elements to the bottom of the matrix. They emulate the corresponding method of the STL vector class. When elem is Mat , its type and the number of columns must be the same as in the container matrix.
 Parameters

elem Added element(s).
 Examples
 samples/cpp/train_HOG.cpp.
◆ push_back() [2/4]
void cv::Mat::push_back  (  const Mat &  m  ) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

m Added line(s).
◆ push_back() [3/4]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

elem Added element(s).
◆ push_back() [4/4]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

elem Added element(s).
◆ push_back_()
void cv::Mat::push_back_  (  const void *  elem  ) 
internal function
◆ rbegin() [1/2]
std::reverse_iterator< MatIterator_< _Tp > > cv::Mat::rbegin  (  ) 
Same as begin() but for inverse traversal.
◆ rbegin() [2/2]
std::reverse_iterator< MatConstIterator_< _Tp > > cv::Mat::rbegin  (  )  const 
◆ release()
void cv::Mat::release  (  ) 
Decrements the reference counter and deallocates the matrix if needed.
The method decrements the reference counter associated with the matrix data. When the reference counter reaches 0, the matrix data is deallocated and the data and the reference counter pointers are set to NULL's. If the matrix header points to an external data set (see Mat::Mat ), the reference counter is NULL, and the method has no effect in this case.
This method can be called manually to force the matrix data deallocation. But since this method is automatically called in the destructor, or by any other method that changes the data pointer, it is usually not needed. The reference counter decrement and check for 0 is an atomic operation on the platforms that support it. Thus, it is safe to operate on the same matrices asynchronously in different threads.
 Examples
 samples/cpp/stitching_detailed.cpp.
◆ rend() [1/2]
std::reverse_iterator< MatIterator_< _Tp > > cv::Mat::rend  (  ) 
Same as end() but for inverse traversal.
◆ rend() [2/2]
std::reverse_iterator< MatConstIterator_< _Tp > > cv::Mat::rend  (  )  const 
◆ reserve()
void cv::Mat::reserve  (  size_t  sz  ) 
Reserves space for the certain number of rows.
The method reserves space for sz rows. If the matrix already has enough space to store sz rows, nothing happens. If the matrix is reallocated, the first Mat::rows rows are preserved. The method emulates the corresponding method of the STL vector class.
 Parameters

sz Number of rows.
◆ reserveBuffer()
void cv::Mat::reserveBuffer  (  size_t  sz  ) 
Reserves space for the certain number of bytes.
The method reserves space for sz bytes. If the matrix already has enough space to store sz bytes, nothing happens. If matrix has to be reallocated its previous content could be lost.
 Parameters

sz Number of bytes.
◆ reshape() [1/3]
Mat cv::Mat::reshape  (  int  cn, 
const std::vector< int > &  newshape  
)  const 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

cn New number of channels. If the parameter is 0, the number of channels remains the same. newshape Vector with new matrix size by all dimentions. If some sizes are zero, the original sizes in those dimensions are presumed.
◆ reshape() [2/3]
Mat cv::Mat::reshape  (  int  cn, 
int  newndims,  
const int *  newsz  
)  const 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

cn New number of channels. If the parameter is 0, the number of channels remains the same. newndims New number of dimentions. newsz Array with new matrix size by all dimentions. If some sizes are zero, the original sizes in those dimensions are presumed.
◆ reshape() [3/3]
Mat cv::Mat::reshape  (  int  cn, 
int  rows = 0 

)  const 
Changes the shape and/or the number of channels of a 2D matrix without copying the data.
The method makes a new matrix header for *this elements. The new matrix may have a different size and/or different number of channels. Any combination is possible if:
 No extra elements are included into the new matrix and no elements are excluded. Consequently, the product rows*cols*channels() must stay the same after the transformation.
 No data is copied. That is, this is an O(1) operation. Consequently, if you change the number of rows, or the operation changes the indices of elements row in some other way, the matrix must be continuous. See Mat::isContinuous .
For example, if there is a set of 3D points stored as an STL vector, and you want to represent the points as a 3xN matrix, do the following:
3channel 2x2 matrix reshaped to 1channel 4x3 matrix, each column has values from one of original channels:
or:
 Parameters

cn New number of channels. If the parameter is 0, the number of channels remains the same. rows New number of rows. If the parameter is 0, the number of rows remains the same.
 Examples
 samples/cpp/pca.cpp, and samples/dnn/classification.cpp.
◆ resize() [1/2]
void cv::Mat::resize  (  size_t  sz  ) 
Changes the number of matrix rows.
The methods change the number of matrix rows. If the matrix is reallocated, the first min(Mat::rows, sz) rows are preserved. The methods emulate the corresponding methods of the STL vector class.
 Parameters

sz New number of rows.
◆ resize() [2/2]
void cv::Mat::resize  (  size_t  sz, 
const Scalar &  s  
) 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

sz New number of rows. s Value assigned to the newly added elements.
◆ row()
Mat cv::Mat::row  (  int  y  )  const 
Creates a matrix header for the specified matrix row.
The method makes a new header for the specified matrix row and returns it. This is an O(1) operation, regardless of the matrix size. The underlying data of the new matrix is shared with the original matrix. Here is the example of one of the classical basic matrix processing operations, axpy, used by LU and many other algorithms:
 Note
 In the current implementation, the following code does not work as expected: This happens because A.row(i) forms a temporary header that is further assigned to another header. Remember that each of these operations is O(1), that is, no data is copied. Thus, the above assignment is not true if you may have expected the jth row to be copied to the ith row. To achieve that, you should either turn this simple assignment into an expression or use the Mat::copyTo method:
 Parameters

y A 0based row index.
◆ rowRange() [1/2]
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

r Range structure containing both the start and the end indices.
◆ rowRange() [2/2]
Mat cv::Mat::rowRange  (  int  startrow, 
int  endrow  
)  const 
Creates a matrix header for the specified row span.
The method makes a new header for the specified row span of the matrix. Similarly to Mat::row and Mat::col , this is an O(1) operation.
 Parameters

startrow An inclusive 0based start index of the row span. endrow An exclusive 0based ending index of the row span.
 Examples
 samples/cpp/kmeans.cpp, and samples/dnn/segmentation.cpp.
◆ setDefaultAllocator()

static 
◆ setTo()
Mat & cv::Mat::setTo  (  InputArray  value, 
InputArray  mask = noArray() 

) 
Sets all or some of the array elements to the specified value.
This is an advanced variant of the Mat::operator=(const Scalar& s) operator.
 Parameters

value Assigned scalar converted to the actual array type. mask Operation mask of the same size as *this. Its nonzero elements indicate which matrix elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels
 Examples
 samples/dnn/segmentation.cpp.
◆ step1()
size_t cv::Mat::step1  (  int  i = 0  )  const 
Returns a normalized step.
The method returns a matrix step divided by Mat::elemSize1() . It can be useful to quickly access an arbitrary matrix element.
◆ t()
MatExpr cv::Mat::t  (  )  const 
Transposes a matrix.
The method performs matrix transposition by means of matrix expressions. It does not perform the actual transposition but returns a temporary matrix transposition object that can be further used as a part of more complex matrix expressions or can be assigned to a matrix:
◆ total() [1/2]
size_t cv::Mat::total  (  )  const 
Returns the total number of array elements.
The method returns the number of array elements (a number of pixels if the array represents an image).
 Examples
 samples/cpp/train_HOG.cpp.
◆ total() [2/2]
size_t cv::Mat::total  (  int  startDim, 
int  endDim = INT_MAX 

)  const 
Returns the total number of array elements.
The method returns the number of elements within a certain subarray slice with startDim <= dim < endDim
◆ type()
int cv::Mat::type  (  )  const 
Returns the type of a matrix element.
The method returns a matrix element type. This is an identifier compatible with the CvMat type system, like CV_16SC3 or 16bit signed 3channel array, and so on.
◆ updateContinuityFlag()
void cv::Mat::updateContinuityFlag  (  ) 
internal use method: updates the continuity flag
◆ zeros() [1/3]

static 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

ndims Array dimensionality. sz Array of integers specifying the array shape. type Created matrix type.
◆ zeros() [2/3]

static 
Returns a zero array of the specified size and type.
The method returns a Matlabstyle zero array initializer. It can be used to quickly form a constant array as a function parameter, part of a matrix expression, or as a matrix initializer:
In the example above, a new matrix is allocated only if A is not a 3x3 floatingpoint matrix. Otherwise, the existing matrix A is filled with zeros.
 Parameters

rows Number of rows. cols Number of columns. type Created matrix type.
 Examples
 samples/cpp/fitellipse.cpp.
◆ zeros() [3/3]

static 
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 Parameters

size Alternative to the matrix size specification Size(cols, rows) . type Created matrix type.
Member Data Documentation
◆ allocator
MatAllocator* cv::Mat::allocator 
custom allocator
◆ cols
int cv::Mat::cols 
 Examples
 samples/cpp/camshiftdemo.cpp, samples/cpp/connected_components.cpp, samples/cpp/demhist.cpp, samples/cpp/facedetect.cpp, samples/cpp/falsecolor.cpp, samples/cpp/fitellipse.cpp, samples/cpp/grabcut.cpp, samples/cpp/image_alignment.cpp, samples/cpp/kmeans.cpp, samples/cpp/polar_transforms.cpp, samples/cpp/squares.cpp, samples/cpp/stitching.cpp, samples/cpp/train_HOG.cpp, samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp, samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp, samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp, samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp, samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp, samples/cpp/warpPerspective_demo.cpp, samples/cpp/watershed.cpp, samples/dnn/object_detection.cpp, and samples/dnn/openpose.cpp.
◆ data
uchar* cv::Mat::data 
pointer to the data
 Examples
 samples/dnn/segmentation.cpp.
◆ dataend
const uchar* cv::Mat::dataend 
◆ datalimit
const uchar* cv::Mat::datalimit 
◆ datastart
const uchar* cv::Mat::datastart 
helper fields used in locateROI and adjustROI
◆ dims
int cv::Mat::dims 
the matrix dimensionality, >= 2
◆ flags
int cv::Mat::flags 
includes several bitfields:
 the magic signature
 continuity flag
 depth
 number of channels
◆ rows
int cv::Mat::rows 
the number of rows and columns or (1, 1) when the matrix has more than 2 dimensions
 Examples
 samples/cpp/camshiftdemo.cpp, samples/cpp/connected_components.cpp, samples/cpp/demhist.cpp, samples/cpp/falsecolor.cpp, samples/cpp/fitellipse.cpp, samples/cpp/grabcut.cpp, samples/cpp/image_alignment.cpp, samples/cpp/kmeans.cpp, samples/cpp/polar_transforms.cpp, samples/cpp/squares.cpp, samples/cpp/stitching.cpp, samples/cpp/train_HOG.cpp, samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp, samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp, samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp, samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp, samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp, samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp, samples/cpp/warpPerspective_demo.cpp, samples/cpp/watershed.cpp, samples/dnn/object_detection.cpp, and samples/dnn/openpose.cpp.
◆ size
MatSize cv::Mat::size 
 Examples
 fld_lines.cpp, samples/cpp/camshiftdemo.cpp, samples/cpp/connected_components.cpp, samples/cpp/create_mask.cpp, samples/cpp/grabcut.cpp, samples/cpp/image_alignment.cpp, samples/cpp/polar_transforms.cpp, samples/cpp/segment_objects.cpp, samples/cpp/squares.cpp, samples/cpp/stitching_detailed.cpp, samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp, samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp, samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp, samples/cpp/videowriter_basic.cpp, samples/cpp/watershed.cpp, samples/dnn/colorization.cpp, samples/dnn/openpose.cpp, and samples/dnn/segmentation.cpp.
◆ step
MatStep cv::Mat::step 
◆ u
The documentation for this class was generated from the following files:
 opencv2/core/mat.hpp
 opencv2/core/utility.hpp