#include <core.hpp>
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. | |
const_iterator | begin () const |
iterator | begin () |
iterators; they are smart enough to skip gaps in the end of rows | |
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 _ndims, const int *_sizes) |
equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type) | |
void | create (Size _size) |
equivalent to Mat::create(_size, DataType<_Tp>::type) | |
void | create (int _rows, int _cols) |
equivalent to Mat::create(_rows, _cols, DataType<_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. | |
const_iterator | end () const |
iterator | end () |
Mat_ (const MatCommaInitializer_< _Tp > &commaInitializer) | |
Mat_ (const Point3_< typename DataType< _Tp >::channel_type > &pt, bool copyData=true) | |
Mat_ (const Point_< typename DataType< _Tp >::channel_type > &pt, bool copyData=true) | |
template<int m, int n> | |
Mat_ (const Matx< typename DataType< _Tp >::channel_type, m, n > &mtx, bool copyData=true) | |
template<int n> | |
Mat_ (const Vec< typename DataType< _Tp >::channel_type, n > &vec, bool copyData=true) | |
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 | |
Mat_ (const Mat_ &m, const Range *ranges) | |
selects a submatrix, n-dim version | |
Mat_ (const Mat_ &m, const Rect &roi) | |
selects a submatrix | |
Mat_ (const Mat_ &m, const Range &rowRange, const Range &colRange=Range::all()) | |
selects a submatrix | |
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, _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 Mat_ &m) | |
copy constructor | |
Mat_ (const Mat &m) | |
copy/conversion contructor. If m is of different type, it's converted | |
Mat_ (int _ndims, const int *_sizes, const _Tp &value) | |
n-dim array constructor that sets each matrix element to specified value | |
Mat_ (int _ndims, const int *_sizes) | |
n-dim array constructor | |
Mat_ (Size _size, const _Tp &value) | |
constructor that sets each matrix element to specified value | |
Mat_ (Size _size) | |
equivalent to Mat(_size, DataType<_Tp>::type) | |
Mat_ (int _rows, int _cols, const _Tp &value) | |
constructor that sets each matrix element to specified value | |
Mat_ (int _rows, int _cols) | |
equivalent to Mat(_rows, _cols, DataType<_Tp>::type) | |
Mat_ () | |
default constructor | |
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() (Point pt) const |
_Tp & | operator() (Point pt) |
const _Tp & | operator() (int idx0, int idx1, int idx2) const |
returns read-only reference to the specified element (3D case) | |
_Tp & | operator() (int idx0, int idx1, int idx2) |
returns reference to the specified element (3D case) | |
const _Tp & | operator() (int idx0, int idx1) const |
returns read-only reference to the specified element (2D case) | |
_Tp & | operator() (int idx0, int idx1) |
returns reference to the specified element (2D case) | |
const _Tp & | operator() (int idx0) const |
returns read-only reference to the specified element (1D case) | |
_Tp & | operator() (int idx0) |
returns reference to the specified element (1D 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 | |
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 | |
Mat_ | operator() (const Range *ranges) const |
Mat_ | operator() (const Rect &roi) const |
Mat_ | operator() (const Range &rowRange, const Range &colRange) const |
Mat_ & | operator= (const MatExpr &expr) |
to support complex matrix expressions | |
Mat_ & | operator= (const _Tp &s) |
set all the elements to s. | |
Mat_ & | operator= (const Mat_ &m) |
Mat_ & | operator= (const Mat &m) |
assignment operators | |
const _Tp * | operator[] (int y) const |
_Tp * | operator[] (int y) |
more convenient forms of row and element access operators | |
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 (Size size) |
static MatExpr | eye (int rows, int cols) |
static MatExpr | ones (int _ndims, const int *_sizes) |
static MatExpr | ones (Size size) |
static MatExpr | ones (int rows, int cols) |
static MatExpr | zeros (int _ndims, const int *_sizes) |
static MatExpr | zeros (Size size) |
static MatExpr | zeros (int rows, int cols) |
overridden forms of Mat::zeros() etc. Data type is omitted, of course |
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)
typedef DataType<_Tp>::channel_type cv::Mat_< _Tp >::channel_type |
typedef MatConstIterator_<_Tp> cv::Mat_< _Tp >::const_iterator |
typedef MatIterator_<_Tp> cv::Mat_< _Tp >::iterator |
typedef _Tp cv::Mat_< _Tp >::value_type |
equivalent to Mat(_rows, _cols, DataType<_Tp>::type)
constructor that sets each matrix element to specified value
equivalent to Mat(_size, DataType<_Tp>::type)
constructor that sets each matrix element to specified value
n-dim array constructor
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
copy/conversion contructor. If m is of different type, it's converted
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
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
cv::Mat_< _Tp >::Mat_ | ( | const Mat_< _Tp > & | m, | |
const Range & | rowRange, | |||
const Range & | colRange = Range::all() | |||
) | [inline] |
selects a submatrix
selects a submatrix
cv::Mat_< _Tp >::Mat_ | ( | const Mat_< _Tp > & | m, | |
const Range * | ranges | |||
) | [inline] |
selects a submatrix, n-dim version
cv::Mat_< _Tp >::Mat_ | ( | const Vec< typename DataType< _Tp >::channel_type, n > & | vec, | |
bool | copyData = true | |||
) | [inline, explicit] |
cv::Mat_< _Tp >::Mat_ | ( | const Matx< typename DataType< _Tp >::channel_type, m, n > & | mtx, | |
bool | copyData = true | |||
) | [inline, explicit] |
cv::Mat_< _Tp >::Mat_ | ( | const Point_< typename DataType< _Tp >::channel_type > & | pt, | |
bool | copyData = true | |||
) | [inline, explicit] |
cv::Mat_< _Tp >::Mat_ | ( | const Point3_< typename DataType< _Tp >::channel_type > & | pt, | |
bool | copyData = true | |||
) | [inline, explicit] |
cv::Mat_< _Tp >::Mat_ | ( | const MatCommaInitializer_< _Tp > & | commaInitializer | ) | [inline, explicit] |
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.
MatConstIterator_< _Tp > cv::Mat_< _Tp >::begin | ( | ) | const [inline] |
Reimplemented from cv::Mat.
MatIterator_< _Tp > cv::Mat_< _Tp >::begin | ( | ) | [inline] |
iterators; they are smart enough to skip gaps in the end of rows
Reimplemented from cv::Mat.
int cv::Mat_< _Tp >::channels | ( | ) | const [inline] |
returns element type, similar to CV_MAT_CN(cvmat->type)
Reimplemented from cv::Mat.
returns deep copy of the matrix, i.e. the data is copied
Reimplemented from cv::Mat.
returns a new matrix header for the specified column
Reimplemented from cv::Mat.
void cv::Mat_< _Tp >::create | ( | int | _ndims, | |
const int * | _sizes | |||
) | [inline] |
equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type)
equivalent to Mat::create(_size, DataType<_Tp>::type)
void cv::Mat_< _Tp >::create | ( | int | _rows, | |
int | _cols | |||
) | [inline] |
equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type)
cross-product
int cv::Mat_< _Tp >::depth | ( | ) | const [inline] |
returns element type, similar to CV_MAT_DEPTH(cvmat->type)
Reimplemented from cv::Mat.
... for the specified diagonal
Reimplemented from cv::Mat.
size_t cv::Mat_< _Tp >::elemSize | ( | ) | const [inline] |
overridden forms of Mat::elemSize() etc.
Reimplemented from cv::Mat.
size_t cv::Mat_< _Tp >::elemSize1 | ( | ) | const [inline] |
returns the size of element channel in bytes.
Reimplemented from cv::Mat.
MatConstIterator_< _Tp > cv::Mat_< _Tp >::end | ( | ) | const [inline] |
Reimplemented from cv::Mat.
MatIterator_< _Tp > cv::Mat_< _Tp >::end | ( | ) | [inline] |
Reimplemented from cv::Mat.
static MatExpr cv::Mat_< _Tp >::ones | ( | int | _ndims, | |
const int * | _sizes | |||
) | [static] |
cv::Mat_< _Tp >::operator Mat_< T2 > | ( | ) | const [inline] |
data type conversion
cv::Mat_< _Tp >::operator Matx< typename DataType< _Tp >::channel_type, m, n > | ( | ) | const [inline] |
conversion to Matx
cv::Mat_< _Tp >::operator Vec< typename DataType< _Tp >::channel_type, n > | ( | ) | const [inline] |
conversion to Vec
cv::Mat_< _Tp >::operator vector< _Tp > | ( | ) | const [inline] |
conversion to vector.
Reimplemented from cv::Mat.
const _Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0, | |
int | idx1, | |||
int | idx2 | |||
) | const [inline] |
returns read-only reference to the specified element (3D case)
_Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0, | |
int | idx1, | |||
int | idx2 | |||
) | [inline] |
returns reference to the specified element (3D case)
const _Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0, | |
int | idx1 | |||
) | const [inline] |
returns read-only reference to the specified element (2D case)
_Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0, | |
int | idx1 | |||
) | [inline] |
returns reference to the specified element (2D case)
const _Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0 | ) | const [inline] |
returns read-only reference to the specified element (1D case)
_Tp & cv::Mat_< _Tp >::operator() | ( | int | idx0 | ) | [inline] |
returns reference to the specified element (1D case)
const _Tp& cv::Mat_< _Tp >::operator() | ( | const Vec< int, n > & | idx | ) | const [inline] |
returns read-only reference to the specified element
_Tp& cv::Mat_< _Tp >::operator() | ( | const Vec< int, n > & | idx | ) | [inline] |
returns reference to the specified element
const _Tp & cv::Mat_< _Tp >::operator() | ( | const int * | idx | ) | const [inline] |
returns read-only reference to the specified element
_Tp & cv::Mat_< _Tp >::operator() | ( | const int * | idx | ) | [inline] |
returns reference to the specified element
Mat_< _Tp > cv::Mat_< _Tp >::operator() | ( | const Range * | ranges | ) | const [inline] |
Reimplemented from cv::Mat.
Reimplemented from cv::Mat.
Mat_< _Tp > cv::Mat_< _Tp >::operator() | ( | const Range & | rowRange, | |
const Range & | colRange | |||
) | const [inline] |
to support complex matrix expressions
Reimplemented from cv::Mat.
set all the elements to s.
assignment operators
Reimplemented from cv::Mat.
const _Tp * cv::Mat_< _Tp >::operator[] | ( | int | y | ) | const [inline] |
_Tp * cv::Mat_< _Tp >::operator[] | ( | int | y | ) | [inline] |
more convenient forms of row and element access operators
some more overriden methods
overridden forms of Mat::row() etc.
Reimplemented from cv::Mat.
size_t cv::Mat_< _Tp >::step1 | ( | int | i = 0 |
) | const [inline] |
returns step/elemSize1()
Reimplemented from cv::Mat.
size_t cv::Mat_< _Tp >::stepT | ( | int | i = 0 |
) | const [inline] |
returns step()/sizeof(_Tp)
int cv::Mat_< _Tp >::type | ( | ) | const [inline] |
returns element type, similar to CV_MAT_TYPE(cvmat->type)
Reimplemented from cv::Mat.
static MatExpr cv::Mat_< _Tp >::zeros | ( | int | _ndims, | |
const int * | _sizes | |||
) | [static] |
overridden forms of Mat::zeros() etc. Data type is omitted, of course