Public Types | Public Member Functions | Static Public Member Functions

# cv::Mat_< _Tp > Class Template Reference

`#include <core.hpp>`

Inheritance diagram for cv::Mat_< _Tp >:

List of all members.

## Public Types
typedef DataType< _Tp > ::channel_type | channel_type
typedef MatConstIterator_< _Tp > | const_iterator
typedef MatIterator_< _Tp > | iterator
typedef _Tp | value_type
## Public Member Functions
Mat_ & | adjustROI (int dtop, int dbottom, int dleft, int dright)
| moves/resizes the current matrix ROI inside the parent matrix.
iterator | begin ()
| iterators; they are smart enough to skip gaps in the end of rows
const_iterator | begin () const
int | channels () const
| returns element type, similar to CV_MAT_CN(cvmat->type)
Mat_ | clone () const
| returns deep copy of the matrix, i.e. the data is copied
Mat_ | col (int x) const
| returns a new matrix header for the specified column
void | create (int _rows, int _cols)
| equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type)
void | create (Size _size)
| equivalent to Mat::create(_size, DataType<_Tp>::type)
void | create (int _ndims, const int *_sizes)
| equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type)
Mat_ | cross (const Mat_ &m) const
| cross-product
int | depth () const
| returns element type, similar to CV_MAT_DEPTH(cvmat->type)
Mat_ | diag (int d=0) const
| ... for the specified diagonal
size_t | elemSize () const
| overridden forms of Mat::elemSize() etc.
size_t | elemSize1 () const
| returns the size of element channel in bytes.
iterator | end ()
const_iterator | end () const
| Mat_ (Size _size)
| equivalent to Mat(_size, DataType<_Tp>::type)
template<int n>
| Mat_ (const Vec< typename DataType< _Tp >::channel_type, n > &vec, bool copyData=true)
| Mat_ (const Mat &m)
| copy/conversion contructor. If m is of different type, it's converted
template<int m, int n>
| Mat_ (const Matx< typename DataType< _Tp >::channel_type, m, n > &mtx, bool copyData=true)
| Mat_ (int _rows, int _cols)
| equivalent to Mat(_rows, _cols, DataType<_Tp>::type)
| Mat_ (const Point_< typename DataType< _Tp >::channel_type > &pt, bool copyData=true)
| Mat_ (const Mat_ &m)
| copy constructor
| Mat_ (const Point3_< typename DataType< _Tp >::channel_type > &pt, bool copyData=true)
| Mat_ (int _rows, int _cols, _Tp *_data, size_t _step=AUTO_STEP)
| constructs a matrix on top of user-allocated data. step is in bytes(!!!), regardless of the type
| Mat_ (const MatCommaInitializer_< _Tp > &commaInitializer)
| Mat_ (Size _size, const _Tp &value)
| constructor that sets each matrix element to specified value
| Mat_ (int _ndims, const int *_sizes, _Tp *_data, const size_t *_steps=0)
| constructs n-dim matrix on top of user-allocated data. steps are in bytes(!!!), regardless of the type
| Mat_ (int _rows, int _cols, const _Tp &value)
| constructor that sets each matrix element to specified value
| Mat_ (const Mat_ &m, const Range &rowRange, const Range &colRange=Range::all())
| selects a submatrix
| Mat_ (int _ndims, const int *_sizes)
| n-dim array constructor
| Mat_ (const Mat_ &m, const Rect &roi)
| selects a submatrix
| Mat_ ()
| default constructor
| Mat_ (const Mat_ &m, const Range *ranges)
| selects a submatrix, n-dim version
| Mat_ (int _ndims, const int *_sizes, const _Tp &value)
| n-dim array constructor that sets each matrix element to specified value
| Mat_ (const vector< _Tp > &vec, bool copyData=false)
| makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will have a single column
template<typename T2 >
| operator Mat_< T2 > () const
| data type conversion
template<int m, int n>
| operator Matx< typename DataType< _Tp >::channel_type, m, n > () const
| conversion to Matx
template<int n>
| operator Vec< typename DataType< _Tp >::channel_type, n > () const
| conversion to Vec
| operator vector< _Tp > () const
| conversion to vector.
const _Tp & | operator() (int idx0) const
| returns read-only reference to the specified element (1D case)
_Tp & | operator() (int idx0, int idx1)
| returns reference to the specified element (2D case)
template<int n>
const _Tp & | operator() (const Vec< int, n > &idx) const
| returns read-only reference to the specified element
template<int n>
_Tp & | operator() (const Vec< int, n > &idx)
| returns reference to the specified element
Mat_ | operator() (const Rect &roi) const
_Tp & | operator() (int idx0)
| returns reference to the specified element (1D case)
Mat_ | operator() (const Range &rowRange, const Range &colRange) const
const _Tp & | operator() (int idx0, int idx1, int idx2) const
| returns read-only reference to the specified element (3D case)
_Tp & | operator() (Point pt)
const _Tp & | operator() (Point pt) const
const _Tp & | operator() (const int *idx) const
| returns read-only reference to the specified element
_Tp & | operator() (const int *idx)
| returns reference to the specified element
_Tp & | operator() (int idx0, int idx1, int idx2)
| returns reference to the specified element (3D case)
Mat_ | operator() (const Range *ranges) const
const _Tp & | operator() (int idx0, int idx1) const
| returns read-only reference to the specified element (2D case)
Mat_ & | operator= (const _Tp &s)
| set all the elements to s.
Mat_ & | operator= (const Mat_ &m)
Mat_ & | operator= (const MatExpr &expr)
| to support complex matrix expressions
Mat_ & | operator= (const Mat &m)
| assignment operators
_Tp * | operator[] (int y)
| more convenient forms of row and element access operators
const _Tp * | operator[] (int y) const
Mat_ | reshape (int _rows) const
| some more overriden methods
Mat_ | row (int y) const
| overridden forms of Mat::row() etc.
size_t | step1 (int i=0) const
| returns step/elemSize1()
size_t | stepT (int i=0) const
| returns step()/sizeof(_Tp)
int | type () const
| returns element type, similar to CV_MAT_TYPE(cvmat->type)
## Static Public Member Functions
static MatExpr | eye (int rows, int cols)
static MatExpr | eye (Size size)
static MatExpr | ones (int _ndims, const int *_sizes)
static MatExpr | ones (Size size)
static MatExpr | ones (int rows, int cols)
static MatExpr | zeros (Size size)
static MatExpr | zeros (int rows, int cols)
| overridden forms of Mat::zeros() etc. Data type is omitted, of course
static MatExpr | zeros (int _ndims, const int *_sizes)

## Detailed Description

### template<typename _Tp>
class cv::Mat_< _Tp >

Template matrix class derived from Mat

The class Mat_ is a "thin" template wrapper on top of cv::Mat. It does not have any extra data fields, nor it or cv::Mat have any virtual methods and thus references or pointers to these two classes can be safely converted one to another. But do it with care, for example:

     // create 100x100 8-bit matrix
     Mat M(100,100,CV_8U);
     // this will compile fine. no any data conversion will be done.
     Mat_<float>& M1 = (Mat_<float>&)M;
     // the program will likely crash at the statement below
     M1(99,99) = 1.f;

While cv::Mat is sufficient in most cases, cv::Mat_ can be more convenient if you use a lot of element access operations and if you know matrix type at compile time. Note that cv::Mat::at<_Tp>(int y, int x) and cv::Mat_<_Tp>::operator ()(int y, int x) do absolutely the same thing and run at the same speed, but the latter is certainly shorter:

     Mat_<double> M(20,20);
     for(int i = 0; i < M.rows; i++)
        for(int j = 0; j < M.cols; j++)
           M(i,j) = 1./(i+j+1);
     Mat E, V;
     eigen(M,E,V);
     cout << E.at<double>(0,0)/E.at<double>(M.rows-1,0);

It is easy to use Mat_ for multi-channel images/matrices - just pass cv::Vec as cv::Mat_ template parameter:

     // allocate 320x240 color image and fill it with green (in RGB space)
     Mat_<Vec3b> img(240, 320, Vec3b(0,255,0));
     // now draw a diagonal white line
     for(int i = 0; i < 100; i++)
         img(i,i)=Vec3b(255,255,255);
     // and now modify the 2nd (red) channel of each pixel
     for(int i = 0; i < img.rows; i++)
        for(int j = 0; j < img.cols; j++)
           img(i,j)[2] ^= (uchar)(i ^ j); // img(y,x)[c] accesses c-th channel of the pixel (x,y)

## Member Typedef Documentation

template<typename _Tp>

typedef DataType<_Tp>::channel_type cv::Mat_< _Tp >::channel_type

template<typename _Tp>

typedef MatConstIterator_<_Tp> cv::Mat_< _Tp >::const_iterator

template<typename _Tp>

typedef MatIterator_<_Tp> cv::Mat_< _Tp >::iterator

template<typename _Tp>

typedef _Tp cv::Mat_< _Tp >::value_type

## Constructor & Destructor Documentation

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | ) | `[inline]`

default constructor

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | int | _rows,
|  | int | _cols
| ) |  | `[inline]`

equivalent to Mat(_rows, _cols, DataType<_Tp>::type)

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | int | _rows,
|  | int | _cols,
|  | const _Tp & | value
| ) |  | `[inline]`

constructor that sets each matrix element to specified value

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | Size | _size ) | `[inline, explicit]`

equivalent to Mat(_size, DataType<_Tp>::type)

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | Size | _size,
|  | const _Tp & | value
| ) |  | `[inline]`

constructor that sets each matrix element to specified value

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | int | _ndims,
|  | const int * | _sizes
| ) |  | `[inline]`

n-dim array constructor

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | int | _ndims,
|  | const int * | _sizes,
|  | const _Tp & | value
| ) |  | `[inline]`

n-dim array constructor that sets each matrix element to specified value

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | const Mat & | m ) | `[inline]`

copy/conversion contructor. If m is of different type, it's converted

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | const Mat_< _Tp > & | m ) | `[inline]`

copy constructor

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | int | _rows,
|  | int | _cols,
|  | _Tp * | _data,
|  | size_t | _step = `AUTO_STEP`
| ) |  | `[inline]`

constructs a matrix on top of user-allocated data. step is in bytes(!!!), regardless of the type

template<typename _Tp>

cv::Mat_< _Tp >::Mat_ | ( | int | _ndims,
|  | const int * | _sizes,
|  | _Tp * | _data,
|  | const size_t * | _steps = `0`
| ) |  |

constructs n-dim matrix on top of user-allocated data. steps are in bytes(!!!), regardless of the type

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | const Mat_< _Tp > & | m,
|  | const Range & | rowRange,
|  | const Range & | colRange = `Range::all()`
| ) |  | `[inline]`

selects a submatrix

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | const Mat_< _Tp > & | m,
|  | const Rect & | roi
| ) |  | `[inline]`

selects a submatrix

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | const Mat_< _Tp > & | m,
|  | const Range * | ranges
| ) |  | `[inline]`

selects a submatrix, n-dim version

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | const vector< _Tp > & | vec,
|  | bool | copyData = `false`
| ) |  | `[inline, explicit]`

makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will have a single column

template<typename _Tp >
template<int n>

cv::Mat_< _Tp >::Mat_ | ( | const Vec< typename DataType< _Tp >::channel_type, n > & | vec,
|  | bool | copyData = `true`
| ) |  | `[inline, explicit]`

template<typename _Tp >
template<int m, int n>

cv::Mat_< _Tp >::Mat_ | ( | const Matx< typename DataType< _Tp >::channel_type, m, n > & | mtx,
|  | bool | copyData = `true`
| ) |  | `[inline, explicit]`

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | const Point_< typename DataType< _Tp >::channel_type > & | pt,
|  | bool | copyData = `true`
| ) |  | `[inline, explicit]`

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | const Point3_< typename DataType< _Tp >::channel_type > & | pt,
|  | bool | copyData = `true`
| ) |  | `[inline, explicit]`

template<typename _Tp >

cv::Mat_< _Tp >::Mat_ | ( | const MatCommaInitializer_< _Tp > & | commaInitializer ) | `[inline, explicit]`

## Member Function Documentation

template<typename _Tp >

Mat_< _Tp > & cv::Mat_< _Tp >::adjustROI | ( | int | dtop,
|  | int | dbottom,
|  | int | dleft,
|  | int | dright
| ) |  | `[inline]`

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

Reimplemented from cv::Mat.

template<typename _Tp >

MatIterator_< _Tp > cv::Mat_< _Tp >::begin | ( | ) | `[inline]`

iterators; they are smart enough to skip gaps in the end of rows

Reimplemented from cv::Mat.

template<typename _Tp >

MatConstIterator_< _Tp > cv::Mat_< _Tp >::begin | ( | ) | const`[inline]`

Reimplemented from cv::Mat.

template<typename _Tp >

int cv::Mat_< _Tp >::channels | ( | ) | const`[inline]`

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

Reimplemented from cv::Mat.

template<typename _Tp >

Mat_< _Tp > cv::Mat_< _Tp >::clone | ( | ) | const`[inline]`

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

Reimplemented from cv::Mat.

template<typename _Tp >

Mat_< _Tp > cv::Mat_< _Tp >::col | ( | int | x ) | const`[inline]`

returns a new matrix header for the specified column

Reimplemented from cv::Mat.

template<typename _Tp >

void cv::Mat_< _Tp >::create | ( | int | _rows,
|  | int | _cols
| ) |  | `[inline]`

equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type)

template<typename _Tp >

void cv::Mat_< _Tp >::create | ( | Size | _size ) | `[inline]`

equivalent to Mat::create(_size, DataType<_Tp>::type)

template<typename _Tp >

void cv::Mat_< _Tp >::create | ( | int | _ndims,
|  | const int * | _sizes
| ) |  | `[inline]`

equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type)

template<typename _Tp >

Mat_< _Tp > cv::Mat_< _Tp >::cross | ( | const Mat_< _Tp > & | m ) | const`[inline]`

cross-product

template<typename _Tp >

int cv::Mat_< _Tp >::depth | ( | ) | const`[inline]`

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

Reimplemented from cv::Mat.

template<typename _Tp >

Mat_< _Tp > cv::Mat_< _Tp >::diag | ( | int | d = `0` ) | const`[inline]`

... for the specified diagonal

Reimplemented from cv::Mat.

template<typename _Tp >

size_t cv::Mat_< _Tp >::elemSize | ( | ) | const`[inline]`

overridden forms of Mat::elemSize() etc.

Reimplemented from cv::Mat.

template<typename _Tp >

size_t cv::Mat_< _Tp >::elemSize1 | ( | ) | const`[inline]`

returns the size of element channel in bytes.

Reimplemented from cv::Mat.

template<typename _Tp >

MatIterator_< _Tp > cv::Mat_< _Tp >::end | ( | ) | `[inline]`

Reimplemented from cv::Mat.

template<typename _Tp >

MatConstIterator_< _Tp > cv::Mat_< _Tp >::end | ( | ) | const`[inline]`

Reimplemented from cv::Mat.

template<typename _Tp >

MatExpr cv::Mat_< _Tp >::eye | ( | Size | size ) | `[inline, static]`

template<typename _Tp >

MatExpr cv::Mat_< _Tp >::eye | ( | int | rows,
|  | int | cols
| ) |  | `[inline, static]`

template<typename _Tp >

MatExpr cv::Mat_< _Tp >::ones | ( | int | rows,
|  | int | cols
| ) |  | `[inline, static]`

template<typename _Tp >

MatExpr cv::Mat_< _Tp >::ones | ( | Size | size ) | `[inline, static]`

template<typename _Tp>

static MatExpr cv::Mat_< _Tp >::ones | ( | int | _ndims,
|  | const int * | _sizes
| ) |  | `[static]`

template<typename _Tp >
template<typename T2 >

cv::Mat_< _Tp >::operator Mat_< T2 > | ( | ) | const`[inline]`

data type conversion

template<typename _Tp >
template<int m, int n>

cv::Mat_< _Tp >::operator Matx< typename DataType< _Tp >::channel_type, m, n > | ( | ) | const`[inline]`

conversion to Matx

template<typename _Tp >
template<int n>

cv::Mat_< _Tp >::operator Vec< typename DataType< _Tp >::channel_type, n > | ( | ) | const`[inline]`

conversion to Vec

template<typename _Tp >

cv::Mat_< _Tp >::operator vector< _Tp > | ( | ) | const`[inline]`

conversion to vector.

Reimplemented from cv::Mat.

template<typename _Tp >

const _Tp & cv::Mat_< _Tp >::operator() | ( | Point | pt ) | const`[inline]`

template<typename _Tp >

Mat_< _Tp > cv::Mat_< _Tp >::operator() | ( | const Range & | rowRange,
|  | const Range & | colRange
| ) |  | const`[inline]`

template<typename _Tp>
template<int n>

const _Tp& cv::Mat_< _Tp >::operator() | ( | const Vec< int, n > & | idx ) | const

returns read-only reference to the specified element

template<typename _Tp >

Mat_< _Tp > cv::Mat_< _Tp >::operator() | ( | const Rect & | roi ) | const`[inline]`

Reimplemented from cv::Mat.

template<typename _Tp >

const _Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0,
|  | int | idx1
| ) |  | const`[inline]`

returns read-only reference to the specified element (2D case)

template<typename _Tp >

_Tp & cv::Mat_< _Tp >::operator() | ( | const int * | idx ) | `[inline]`

returns reference to the specified element

template<typename _Tp >

const _Tp & cv::Mat_< _Tp >::operator() | ( | const int * | idx ) | const`[inline]`

returns read-only reference to the specified element

template<typename _Tp >

_Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0,
|  | int | idx1
| ) |  | `[inline]`

returns reference to the specified element (2D case)

template<typename _Tp>
template<int n>

_Tp& cv::Mat_< _Tp >::operator() | ( | const Vec< int, n > & | idx ) |

returns reference to the specified element

template<typename _Tp >

_Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0 ) | `[inline]`

returns reference to the specified element (1D case)

template<typename _Tp >

const _Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0 ) | const`[inline]`

returns read-only reference to the specified element (1D case)

template<typename _Tp >

_Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0,
|  | int | idx1,
|  | int | idx2
| ) |  | `[inline]`

returns reference to the specified element (3D case)

template<typename _Tp >

const _Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0,
|  | int | idx1,
|  | int | idx2
| ) |  | const`[inline]`

returns read-only reference to the specified element (3D case)

template<typename _Tp >

_Tp & cv::Mat_< _Tp >::operator() | ( | Point | pt ) | `[inline]`

template<typename _Tp >

Mat_< _Tp > cv::Mat_< _Tp >::operator() | ( | const Range * | ranges ) | const`[inline]`

Reimplemented from cv::Mat.

template<typename _Tp >

Mat_< _Tp > & cv::Mat_< _Tp >::operator= | ( | const MatExpr & | expr ) |

to support complex matrix expressions

Reimplemented from cv::Mat.

template<typename _Tp >

Mat_< _Tp > & cv::Mat_< _Tp >::operator= | ( | const Mat_< _Tp > & | m ) | `[inline]`

template<typename _Tp >

Mat_< _Tp > & cv::Mat_< _Tp >::operator= | ( | const Mat & | m ) | `[inline]`

assignment operators

Reimplemented from cv::Mat.

template<typename _Tp >

Mat_< _Tp > & cv::Mat_< _Tp >::operator= | ( | const _Tp & | s ) | `[inline]`

set all the elements to s.

template<typename _Tp >

_Tp * cv::Mat_< _Tp >::operator[] | ( | int | y ) | `[inline]`

more convenient forms of row and element access operators

template<typename _Tp >

const _Tp * cv::Mat_< _Tp >::operator[] | ( | int | y ) | const`[inline]`

template<typename _Tp >

Mat_< _Tp > cv::Mat_< _Tp >::reshape | ( | int | _rows ) | const`[inline]`

some more overriden methods

template<typename _Tp >

Mat_< _Tp > cv::Mat_< _Tp >::row | ( | int | y ) | const`[inline]`

overridden forms of Mat::row() etc.

Reimplemented from cv::Mat.

template<typename _Tp >

size_t cv::Mat_< _Tp >::step1 | ( | int | i = `0` ) | const`[inline]`

returns step/elemSize1()

Reimplemented from cv::Mat.

template<typename _Tp >

size_t cv::Mat_< _Tp >::stepT | ( | int | i = `0` ) | const`[inline]`

returns step()/sizeof(_Tp)

template<typename _Tp >

int cv::Mat_< _Tp >::type | ( | ) | const`[inline]`

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

Reimplemented from cv::Mat.

template<typename _Tp >

MatExpr cv::Mat_< _Tp >::zeros | ( | int | rows,
|  | int | cols
| ) |  | `[inline, static]`

overridden forms of Mat::zeros() etc. Data type is omitted, of course

template<typename _Tp>

static MatExpr cv::Mat_< _Tp >::zeros | ( | int | _ndims,
|  | const int * | _sizes
| ) |  | `[static]`

template<typename _Tp >

MatExpr cv::Mat_< _Tp >::zeros | ( | Size | size ) | `[inline, static]`

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

- C:/opt/OpenCV-2.2.0/modules/core/include/opencv2/core/core.hpp
- C:/opt/OpenCV-2.2.0/modules/core/include/opencv2/core/mat.hpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines