Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
cv::Mat Class Reference

The n-dimensional matrix class. More...

#include <core.hpp>

Inherited by cv::Mat_< _Tp >, cv::Mat_< double >, cv::Mat_< float >, cv::Mat_< int >, cv::Mat_< uchar >, and cv::Mat_< unsigned int >.

Classes

struct  MSize
 
struct  MStep
 

Public Types

enum  { MAGIC_VAL =0x42FF0000, AUTO_STEP =0, CONTINUOUS_FLAG =CV_MAT_CONT_FLAG, SUBMATRIX_FLAG =CV_SUBMAT_FLAG }
 

Public Member Functions

 Mat ()
 default constructor More...
 
 Mat (int rows, int cols, int type)
 constructs 2D matrix of the specified size and type More...
 
 Mat (Size size, int type)
 
 Mat (int rows, int cols, int type, const Scalar &s)
 constucts 2D matrix and fills it with the specified value _s. More...
 
 Mat (Size size, int type, const Scalar &s)
 
 Mat (int ndims, const int *sizes, int type)
 constructs n-dimensional matrix More...
 
 Mat (int ndims, const int *sizes, int type, const Scalar &s)
 
 Mat (const Mat &m)
 copy constructor More...
 
 Mat (int rows, int cols, int type, void *data, size_t step=AUTO_STEP)
 constructor for matrix headers pointing to user-allocated data More...
 
 Mat (Size size, int type, void *data, size_t step=AUTO_STEP)
 
 Mat (int ndims, const int *sizes, int type, void *data, const size_t *steps=0)
 
 Mat (const Mat &m, const Range &rowRange, const Range &colRange=Range::all())
 creates a matrix header for a part of the bigger matrix More...
 
 Mat (const Mat &m, const Rect &roi)
 
 Mat (const Mat &m, const Range *ranges)
 
 Mat (const CvMat *m, bool copyData=false)
 converts old-style CvMat to the new matrix; the data is not copied by default More...
 
 Mat (const CvMatND *m, bool copyData=false)
 converts old-style CvMatND to the new matrix; the data is not copied by default More...
 
 Mat (const IplImage *img, bool copyData=false)
 converts old-style IplImage to the new matrix; the data is not copied by default More...
 
template<typename _Tp >
 Mat (const vector< _Tp > &vec, bool copyData=false)
 builds matrix from std::vector with or without copying the data More...
 
template<typename _Tp , int n>
 Mat (const Vec< _Tp, n > &vec, bool copyData=true)
 builds matrix from cv::Vec; the data is copied by default More...
 
template<typename _Tp , int m, int n>
 Mat (const Matx< _Tp, m, n > &mtx, bool copyData=true)
 builds matrix from cv::Matx; the data is copied by default More...
 
template<typename _Tp >
 Mat (const Point_< _Tp > &pt, bool copyData=true)
 builds matrix from a 2D point More...
 
template<typename _Tp >
 Mat (const Point3_< _Tp > &pt, bool copyData=true)
 builds matrix from a 3D point More...
 
template<typename _Tp >
 Mat (const MatCommaInitializer_< _Tp > &commaInitializer)
 builds matrix from comma initializer More...
 
 Mat (const gpu::GpuMat &m)
 download data from GpuMat More...
 
 ~Mat ()
 destructor - calls release() More...
 
Matoperator= (const Mat &m)
 assignment operators More...
 
Matoperator= (const MatExpr &expr)
 
Mat row (int y) const
 returns a new matrix header for the specified row More...
 
Mat col (int x) const
 returns a new matrix header for the specified column More...
 
Mat rowRange (int startrow, int endrow) const
 ... for the specified row span More...
 
Mat rowRange (const Range &r) const
 
Mat colRange (int startcol, int endcol) const
 ... for the specified column span More...
 
Mat colRange (const Range &r) const
 
Mat diag (int d=0) const
 ... for the specified diagonal More...
 
Mat clone () const
 returns deep copy of the matrix, i.e. the data is copied More...
 
void copyTo (OutputArray m) const
 copies the matrix content to "m". More...
 
void copyTo (OutputArray m, InputArray mask) const
 copies those matrix elements to "m" that are marked with non-zero mask elements. More...
 
void convertTo (OutputArray m, int rtype, double alpha=1, double beta=0) const
 converts matrix to another datatype with optional scalng. See cvConvertScale. More...
 
void assignTo (Mat &m, int type=-1) const
 
Matoperator= (const Scalar &s)
 sets every matrix element to s More...
 
MatsetTo (InputArray value, InputArray mask=noArray())
 sets some of the matrix elements to s, according to the mask More...
 
Mat reshape (int cn, int rows=0) const
 creates alternative matrix header for the same data, with different More...
 
Mat reshape (int cn, int newndims, const int *newsz) const
 
MatExpr t () const
 matrix transposition by means of matrix expressions More...
 
MatExpr inv (int method=DECOMP_LU) const
 matrix inversion by means of matrix expressions More...
 
MatExpr mul (InputArray m, double scale=1) const
 per-element matrix multiplication by means of matrix expressions More...
 
Mat cross (InputArray m) const
 computes cross-product of 2 3D vectors More...
 
double dot (InputArray m) const
 computes dot-product More...
 
void create (int rows, int cols, int type)
 allocates new matrix data unless the matrix already has specified size and type. More...
 
void create (Size size, int type)
 
void create (int ndims, const int *sizes, int type)
 
void addref ()
 increases the reference counter; use with care to avoid memleaks More...
 
void release ()
 decreases reference counter; More...
 
void deallocate ()
 deallocates the matrix data More...
 
void copySize (const Mat &m)
 internal use function; properly re-allocates _size, _step arrays More...
 
void reserve (size_t sz)
 reserves enough space to fit sz hyper-planes More...
 
void resize (size_t sz)
 resizes matrix to the specified number of hyper-planes More...
 
void resize (size_t sz, const Scalar &s)
 resizes matrix to the specified number of hyper-planes; initializes the newly added elements More...
 
void push_back_ (const void *elem)
 internal function More...
 
template<typename _Tp >
void push_back (const _Tp &elem)
 adds element to the end of 1d matrix (or possibly multiple elements when _Tp=Mat) More...
 
template<typename _Tp >
void push_back (const Mat_< _Tp > &elem)
 
void push_back (const Mat &m)
 
void pop_back (size_t nelems=1)
 removes several hyper-planes from bottom of the matrix More...
 
void locateROI (Size &wholeSize, Point &ofs) const
 locates matrix header within a parent matrix. See below More...
 
MatadjustROI (int dtop, int dbottom, int dleft, int dright)
 moves/resizes the current matrix ROI inside the parent matrix. More...
 
Mat operator() (Range rowRange, Range colRange) const
 extracts a rectangular sub-matrix More...
 
Mat operator() (const Rect &roi) const
 
Mat operator() (const Range *ranges) const
 
 operator CvMat () const
 converts header to CvMat; no data is copied More...
 
 operator CvMatND () const
 converts header to CvMatND; no data is copied More...
 
 operator IplImage () const
 converts header to IplImage; no data is copied More...
 
template<typename _Tp >
 operator vector< _Tp > () const
 
template<typename _Tp , int n>
 operator Vec< _Tp, n > () const
 
template<typename _Tp , int m, int n>
 operator Matx< _Tp, m, n > () const
 
bool isContinuous () const
 returns true iff the matrix data is continuous More...
 
bool isSubmatrix () const
 returns true if the matrix is a submatrix of another matrix More...
 
size_t elemSize () const
 returns element size in bytes, More...
 
size_t elemSize1 () const
 returns the size of element channel in bytes. More...
 
int type () const
 returns element type, similar to CV_MAT_TYPE(cvmat->type) More...
 
int depth () const
 returns element type, similar to CV_MAT_DEPTH(cvmat->type) More...
 
int channels () const
 returns element type, similar to CV_MAT_CN(cvmat->type) More...
 
size_t step1 (int i=0) const
 returns step/elemSize1() More...
 
bool empty () const
 returns true if matrix data is NULL More...
 
size_t total () const
 returns the total number of matrix elements More...
 
int checkVector (int elemChannels, int depth=-1, bool requireContinuous=true) const
 returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise More...
 
ucharptr (int i0=0)
 returns pointer to i0-th submatrix along the dimension #0 More...
 
const ucharptr (int i0=0) const
 
ucharptr (int i0, int i1)
 returns pointer to (i0,i1) submatrix along the dimensions #0 and #1 More...
 
const ucharptr (int i0, int i1) const
 
ucharptr (int i0, int i1, int i2)
 returns pointer to (i0,i1,i3) submatrix along the dimensions #0, #1, #2 More...
 
const ucharptr (int i0, int i1, int i2) const
 
ucharptr (const int *idx)
 returns pointer to the matrix element More...
 
const ucharptr (const int *idx) const
 returns read-only pointer to the matrix element More...
 
template<int n>
ucharptr (const Vec< int, n > &idx)
 
template<int n>
const ucharptr (const Vec< int, n > &idx) const
 
template<typename _Tp >
_Tp * ptr (int i0=0)
 template version of the above method More...
 
template<typename _Tp >
const _Tp * ptr (int i0=0) const
 
template<typename _Tp >
_Tp * ptr (int i0, int i1)
 
template<typename _Tp >
const _Tp * ptr (int i0, int i1) const
 
template<typename _Tp >
_Tp * ptr (int i0, int i1, int i2)
 
template<typename _Tp >
const _Tp * ptr (int i0, int i1, int i2) const
 
template<typename _Tp >
_Tp * ptr (const int *idx)
 
template<typename _Tp >
const _Tp * ptr (const int *idx) const
 
template<typename _Tp , int n>
_Tp * ptr (const Vec< int, n > &idx)
 
template<typename _Tp , int n>
const _Tp * ptr (const Vec< int, n > &idx) const
 
template<typename _Tp >
_Tp & at (int i0=0)
 the same as above, with the pointer dereferencing More...
 
template<typename _Tp >
const _Tp & at (int i0=0) const
 
template<typename _Tp >
_Tp & at (int i0, int i1)
 
template<typename _Tp >
const _Tp & at (int i0, int i1) 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 (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 (Point pt)
 special versions for 2D arrays (especially convenient for referencing image pixels) More...
 
template<typename _Tp >
const _Tp & at (Point pt) const
 
template<typename _Tp >
MatIterator_< _Tp > begin ()
 template methods for iteration over matrix elements. More...
 
template<typename _Tp >
MatIterator_< _Tp > end ()
 
template<typename _Tp >
MatConstIterator_< _Tp > begin () const
 
template<typename _Tp >
MatConstIterator_< _Tp > end () const
 

Static Public Member Functions

static Mat diag (const Mat &d)
 constructs a square diagonal matrix which main diagonal is vector "d" More...
 
static MatExpr zeros (int rows, int cols, int type)
 Matlab-style matrix initialization. More...
 
static MatExpr zeros (Size size, int type)
 
static MatExpr zeros (int ndims, const int *sz, int type)
 
static MatExpr ones (int rows, int cols, int type)
 
static MatExpr ones (Size size, int type)
 
static MatExpr ones (int ndims, const int *sz, int type)
 
static MatExpr eye (int rows, int cols, int type)
 
static MatExpr eye (Size size, int type)
 

Public Attributes

int flags
 includes several bit-fields: More...
 
int dims
 the matrix dimensionality, >= 2 More...
 
int rows
 the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions More...
 
int cols
 
uchardata
 pointer to the data More...
 
intrefcount
 pointer to the reference counter; More...
 
uchardatastart
 helper fields used in locateROI and adjustROI More...
 
uchardataend
 
uchardatalimit
 
MatAllocatorallocator
 custom allocator More...
 
MSize size
 
MStep step
 

Protected Member Functions

void initEmpty ()
 

Detailed Description

The n-dimensional matrix class.

The class represents an n-dimensional dense numerical array that can act as a matrix, image, optical flow map, 3-focal tensor etc. It is very similar to CvMat and CvMatND types from earlier versions of OpenCV, and similarly to those types, the matrix can be multi-channel. It also fully supports ROI mechanism.

There are many different ways to create cv::Mat object. Here are the some popular ones:

Once matrix is created, it will be automatically managed by using reference-counting mechanism (unless the matrix header is built on top of user-allocated data, in which case you should handle the data by yourself). The matrix data will be deallocated when no one points to it; if you want to release the data pointed by a matrix header before the matrix destructor is called, use cv::Mat::release().

The next important thing to learn about the matrix class is element access. Here is how the matrix is stored. The elements are stored in row-major order (row by row). The cv::Mat::data member points to the first element of the first row, cv::Mat::rows contains the number of matrix rows and cv::Mat::cols - the number of matrix columns. There is yet another member, cv::Mat::step that is used to actually compute address of a matrix element. cv::Mat::step is needed because the matrix can be a part of another matrix or because there can some padding space in the end of each row for a proper alignment.

roi.png

Given these parameters, address of the matrix element M_{ij} is computed as following:

addr(M_{ij})=M.data + M.step*i + j*M.elemSize()

if you know the matrix element type, e.g. it is float, then you can use cv::Mat::at() method:

addr(M_{ij})=&M.at<float>(i,j)

(where & is used to convert the reference returned by cv::Mat::at() to a pointer). if you need to process a whole row of matrix, the most efficient way is to get the pointer to the row first, and then just use plain C operator []:

// compute sum of positive matrix elements
// (assuming that M is double-precision matrix)
double sum=0;
for(int i = 0; i < M.rows; i++)
{
const double* Mi = M.ptr<double>(i);
for(int j = 0; j < M.cols; j++)
sum += std::max(Mi[j], 0.);
}

Some operations, like the above one, do not actually depend on the matrix shape, they just process elements of a matrix one by one (or elements from multiple matrices that are sitting in the same place, e.g. matrix addition). Such operations are called element-wise and it makes sense to check whether all the input/output matrices are continuous, i.e. have no gaps in the end of each row, and if yes, process them as a single long row:

// compute sum of positive matrix elements, optimized variant
double sum=0;
int cols = M.cols, rows = M.rows;
if(M.isContinuous())
{
cols *= rows;
rows = 1;
}
for(int i = 0; i < rows; i++)
{
const double* Mi = M.ptr<double>(i);
for(int j = 0; j < cols; j++)
sum += std::max(Mi[j], 0.);
}

in the case of continuous matrix the outer loop body will be executed just once, so the overhead will be smaller, which will be especially noticeable in the case of small matrices.

Finally, there are STL-style iterators that are smart enough to skip gaps between successive rows:

// compute sum of positive matrix elements, iterator-based variant
double sum=0;
MatConstIterator_<double> it = M.begin<double>(), it_end = M.end<double>();
for(; it != it_end; ++it)
sum += std::max(*it, 0.);

The matrix iterators are random-access iterators, so they can be passed to any STL algorithm, including std::sort().

Member Enumeration Documentation

anonymous enum
Enumerator
MAGIC_VAL 
AUTO_STEP 
CONTINUOUS_FLAG 
SUBMATRIX_FLAG 

Constructor & Destructor Documentation

cv::Mat::Mat ( )

default constructor

cv::Mat::Mat ( int  rows,
int  cols,
int  type 
)

constructs 2D matrix of the specified size and type

cv::Mat::Mat ( Size  size,
int  type 
)
cv::Mat::Mat ( int  rows,
int  cols,
int  type,
const Scalar s 
)

constucts 2D matrix and fills it with the specified value _s.

cv::Mat::Mat ( Size  size,
int  type,
const Scalar s 
)
cv::Mat::Mat ( int  ndims,
const int sizes,
int  type 
)

constructs n-dimensional matrix

cv::Mat::Mat ( int  ndims,
const int sizes,
int  type,
const Scalar s 
)
cv::Mat::Mat ( const Mat m)

copy constructor

cv::Mat::Mat ( int  rows,
int  cols,
int  type,
void data,
size_t  step = AUTO_STEP 
)

constructor for matrix headers pointing to user-allocated data

cv::Mat::Mat ( Size  size,
int  type,
void data,
size_t  step = AUTO_STEP 
)
cv::Mat::Mat ( int  ndims,
const int sizes,
int  type,
void data,
const size_t *  steps = 0 
)
cv::Mat::Mat ( const Mat m,
const Range rowRange,
const Range colRange = Range::all() 
)

creates a matrix header for a part of the bigger matrix

cv::Mat::Mat ( const Mat m,
const Rect roi 
)
cv::Mat::Mat ( const Mat m,
const Range ranges 
)
cv::Mat::Mat ( const CvMat m,
bool  copyData = false 
)

converts old-style CvMat to the new matrix; the data is not copied by default

cv::Mat::Mat ( const CvMatND m,
bool  copyData = false 
)

converts old-style CvMatND to the new matrix; the data is not copied by default

cv::Mat::Mat ( const IplImage img,
bool  copyData = false 
)

converts old-style IplImage to the new matrix; the data is not copied by default

template<typename _Tp >
cv::Mat::Mat ( const vector< _Tp > &  vec,
bool  copyData = false 
)
explicit

builds matrix from std::vector with or without copying the data

template<typename _Tp , int n>
cv::Mat::Mat ( const Vec< _Tp, n > &  vec,
bool  copyData = true 
)
explicit

builds matrix from cv::Vec; the data is copied by default

template<typename _Tp , int m, int n>
cv::Mat::Mat ( const Matx< _Tp, m, n > &  mtx,
bool  copyData = true 
)
explicit

builds matrix from cv::Matx; the data is copied by default

template<typename _Tp >
cv::Mat::Mat ( const Point_< _Tp > &  pt,
bool  copyData = true 
)
explicit

builds matrix from a 2D point

template<typename _Tp >
cv::Mat::Mat ( const Point3_< _Tp > &  pt,
bool  copyData = true 
)
explicit

builds matrix from a 3D point

template<typename _Tp >
cv::Mat::Mat ( const MatCommaInitializer_< _Tp > &  commaInitializer)
explicit

builds matrix from comma initializer

cv::Mat::Mat ( const gpu::GpuMat m)
explicit

download data from GpuMat

cv::Mat::~Mat ( )

destructor - calls release()

Member Function Documentation

Mat & cv::Mat::operator= ( const Mat m)

assignment operators

Mat & cv::Mat::operator= ( const MatExpr expr)
Mat cv::Mat::row ( int  y) const

returns a new matrix header for the specified row

Mat cv::Mat::col ( int  x) const

returns a new matrix header for the specified column

Mat cv::Mat::rowRange ( int  startrow,
int  endrow 
) const

... for the specified row span

Mat cv::Mat::rowRange ( const Range r) const
Mat cv::Mat::colRange ( int  startcol,
int  endcol 
) const

... for the specified column span

Mat cv::Mat::colRange ( const Range r) const
Mat cv::Mat::diag ( int  d = 0) const

... for the specified diagonal

Mat cv::Mat::diag ( const Mat d)
static

constructs a square diagonal matrix which main diagonal is vector "d"

Mat cv::Mat::clone ( ) const

returns deep copy of the matrix, i.e. the data is copied

void cv::Mat::copyTo ( OutputArray  m) const

copies the matrix content to "m".

void cv::Mat::copyTo ( OutputArray  m,
InputArray  mask 
) const

copies those matrix elements to "m" that are marked with non-zero mask elements.

void cv::Mat::convertTo ( OutputArray  m,
int  rtype,
double  alpha = 1,
double  beta = 0 
) const

converts matrix to another datatype with optional scalng. See cvConvertScale.

void cv::Mat::assignTo ( Mat m,
int  type = -1 
) const
Mat& cv::Mat::operator= ( const Scalar s)

sets every matrix element to s

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

sets some of the matrix elements to s, according to the mask

Mat cv::Mat::reshape ( int  cn,
int  rows = 0 
) const

creates alternative matrix header for the same data, with different

Mat cv::Mat::reshape ( int  cn,
int  newndims,
const int newsz 
) const
MatExpr cv::Mat::t ( ) const

matrix transposition by means of matrix expressions

MatExpr cv::Mat::inv ( int  method = DECOMP_LU) const

matrix inversion by means of matrix expressions

MatExpr cv::Mat::mul ( InputArray  m,
double  scale = 1 
) const

per-element matrix multiplication by means of matrix expressions

Mat cv::Mat::cross ( InputArray  m) const

computes cross-product of 2 3D vectors

double cv::Mat::dot ( InputArray  m) const

computes dot-product

static MatExpr cv::Mat::zeros ( int  rows,
int  cols,
int  type 
)
static

Matlab-style matrix initialization.

static MatExpr cv::Mat::zeros ( Size  size,
int  type 
)
static
static MatExpr cv::Mat::zeros ( int  ndims,
const int sz,
int  type 
)
static
static MatExpr cv::Mat::ones ( int  rows,
int  cols,
int  type 
)
static
static MatExpr cv::Mat::ones ( Size  size,
int  type 
)
static
static MatExpr cv::Mat::ones ( int  ndims,
const int sz,
int  type 
)
static
static MatExpr cv::Mat::eye ( int  rows,
int  cols,
int  type 
)
static
static MatExpr cv::Mat::eye ( Size  size,
int  type 
)
static
void cv::Mat::create ( int  rows,
int  cols,
int  type 
)

allocates new matrix data unless the matrix already has specified size and type.

void cv::Mat::create ( Size  size,
int  type 
)
void cv::Mat::create ( int  ndims,
const int sizes,
int  type 
)
void cv::Mat::addref ( )

increases the reference counter; use with care to avoid memleaks

void cv::Mat::release ( )

decreases reference counter;

void cv::Mat::deallocate ( )

deallocates the matrix data

void cv::Mat::copySize ( const Mat m)

internal use function; properly re-allocates _size, _step arrays

void cv::Mat::reserve ( size_t  sz)

reserves enough space to fit sz hyper-planes

void cv::Mat::resize ( size_t  sz)

resizes matrix to the specified number of hyper-planes

void cv::Mat::resize ( size_t  sz,
const Scalar s 
)

resizes matrix to the specified number of hyper-planes; initializes the newly added elements

void cv::Mat::push_back_ ( const void elem)

internal function

template<typename _Tp >
void cv::Mat::push_back ( const _Tp &  elem)

adds element to the end of 1d matrix (or possibly multiple elements when _Tp=Mat)

template<typename _Tp >
void cv::Mat::push_back ( const Mat_< _Tp > &  elem)
void cv::Mat::push_back ( const Mat m)
void cv::Mat::pop_back ( size_t  nelems = 1)

removes several hyper-planes from bottom of the matrix

void cv::Mat::locateROI ( Size wholeSize,
Point ofs 
) const

locates matrix header within a parent matrix. See below

Mat& cv::Mat::adjustROI ( int  dtop,
int  dbottom,
int  dleft,
int  dright 
)

moves/resizes the current matrix ROI inside the parent matrix.

Mat cv::Mat::operator() ( Range  rowRange,
Range  colRange 
) const

extracts a rectangular sub-matrix

Mat cv::Mat::operator() ( const Rect roi) const
Mat cv::Mat::operator() ( const Range ranges) const
cv::Mat::operator CvMat ( ) const

converts header to CvMat; no data is copied

cv::Mat::operator CvMatND ( ) const

converts header to CvMatND; no data is copied

cv::Mat::operator IplImage ( ) const

converts header to IplImage; no data is copied

template<typename _Tp >
cv::Mat::operator vector< _Tp > ( ) const
template<typename _Tp , int n>
cv::Mat::operator Vec< _Tp, n > ( ) const
template<typename _Tp , int m, int n>
cv::Mat::operator Matx< _Tp, m, n > ( ) const
bool cv::Mat::isContinuous ( ) const

returns true iff the matrix data is continuous

bool cv::Mat::isSubmatrix ( ) const

returns true if the matrix is a submatrix of another matrix

size_t cv::Mat::elemSize ( ) const

returns element size in bytes,

size_t cv::Mat::elemSize1 ( ) const

returns the size of element channel in bytes.

int cv::Mat::type ( ) const

returns element type, similar to CV_MAT_TYPE(cvmat->type)

int cv::Mat::depth ( ) const

returns element type, similar to CV_MAT_DEPTH(cvmat->type)

int cv::Mat::channels ( ) const

returns element type, similar to CV_MAT_CN(cvmat->type)

size_t cv::Mat::step1 ( int  i = 0) const

returns step/elemSize1()

bool cv::Mat::empty ( ) const

returns true if matrix data is NULL

size_t cv::Mat::total ( ) const

returns the total number of matrix elements

int cv::Mat::checkVector ( int  elemChannels,
int  depth = -1,
bool  requireContinuous = true 
) const

returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise

uchar * cv::Mat::ptr ( int  i0 = 0)

returns pointer to i0-th submatrix along the dimension #0

const uchar * cv::Mat::ptr ( int  i0 = 0) const
uchar * cv::Mat::ptr ( int  i0,
int  i1 
)

returns pointer to (i0,i1) submatrix along the dimensions #0 and #1

const uchar * cv::Mat::ptr ( int  i0,
int  i1 
) const
uchar * cv::Mat::ptr ( int  i0,
int  i1,
int  i2 
)

returns pointer to (i0,i1,i3) submatrix along the dimensions #0, #1, #2

const uchar * cv::Mat::ptr ( int  i0,
int  i1,
int  i2 
) const
uchar * cv::Mat::ptr ( const int idx)

returns pointer to the matrix element

const uchar * cv::Mat::ptr ( const int idx) const

returns read-only pointer to the matrix element

template<int n>
uchar* cv::Mat::ptr ( const Vec< int, n > &  idx)
template<int n>
const uchar* cv::Mat::ptr ( const Vec< int, n > &  idx) const
template<typename _Tp>
_Tp * cv::Mat::ptr ( int  i0 = 0)

template version of the above method

template<typename _Tp>
const _Tp * cv::Mat::ptr ( int  i0 = 0) const
template<typename _Tp>
_Tp * cv::Mat::ptr ( int  i0,
int  i1 
)
template<typename _Tp>
const _Tp * cv::Mat::ptr ( int  i0,
int  i1 
) const
template<typename _Tp>
_Tp * cv::Mat::ptr ( int  i0,
int  i1,
int  i2 
)
template<typename _Tp>
const _Tp * cv::Mat::ptr ( int  i0,
int  i1,
int  i2 
) const
template<typename _Tp >
_Tp* cv::Mat::ptr ( const int idx)
template<typename _Tp >
const _Tp* cv::Mat::ptr ( const int idx) const
template<typename _Tp , int n>
_Tp* cv::Mat::ptr ( const Vec< int, n > &  idx)
template<typename _Tp , int n>
const _Tp* cv::Mat::ptr ( const Vec< int, n > &  idx) const
template<typename _Tp >
_Tp & cv::Mat::at ( int  i0 = 0)

the same as above, with the pointer dereferencing

template<typename _Tp >
const _Tp & cv::Mat::at ( int  i0 = 0) const
template<typename _Tp >
_Tp & cv::Mat::at ( int  i0,
int  i1 
)
template<typename _Tp >
const _Tp & cv::Mat::at ( int  i0,
int  i1 
) const
template<typename _Tp >
_Tp & cv::Mat::at ( int  i0,
int  i1,
int  i2 
)
template<typename _Tp >
const _Tp & cv::Mat::at ( int  i0,
int  i1,
int  i2 
) const
template<typename _Tp >
_Tp & cv::Mat::at ( const int idx)
template<typename _Tp >
const _Tp & cv::Mat::at ( const int idx) const
template<typename _Tp , int n>
_Tp & cv::Mat::at ( const Vec< int, n > &  idx)
template<typename _Tp , int n>
const _Tp & cv::Mat::at ( const Vec< int, n > &  idx) const
template<typename _Tp >
_Tp & cv::Mat::at ( Point  pt)

special versions for 2D arrays (especially convenient for referencing image pixels)

template<typename _Tp >
const _Tp & cv::Mat::at ( Point  pt) const
template<typename _Tp >
MatIterator_< _Tp > cv::Mat::begin ( )

template methods for iteration over matrix elements.

template<typename _Tp >
MatIterator_< _Tp > cv::Mat::end ( )
template<typename _Tp >
MatConstIterator_< _Tp > cv::Mat::begin ( ) const
template<typename _Tp >
MatConstIterator_< _Tp > cv::Mat::end ( ) const
void cv::Mat::initEmpty ( )
protected

Member Data Documentation

int cv::Mat::flags

includes several bit-fields:

  • the magic signature
  • continuity flag
  • depth
  • number of channels
int cv::Mat::dims

the matrix dimensionality, >= 2

int cv::Mat::rows

the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions

int cv::Mat::cols
uchar* cv::Mat::data

pointer to the data

int* cv::Mat::refcount

pointer to the reference counter;

uchar* cv::Mat::datastart

helper fields used in locateROI and adjustROI

uchar* cv::Mat::dataend
uchar* cv::Mat::datalimit
MatAllocator* cv::Mat::allocator

custom allocator

MSize cv::Mat::size
MStep cv::Mat::step

The documentation for this class was generated from the following files: