virtual bool isSubmatrix(int i=-1) const;
virtual bool empty() const;
virtual void copyTo(const _OutputArray& arr) const;
+ virtual void copyTo(const _OutputArray& arr, const _InputArray & mask) const;
virtual size_t offset(int i=-1) const;
virtual size_t step(int i=-1) const;
bool isMat() const;
{
enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2,
DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24,
- USER_ALLOCATED=32 };
+ USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64};
UMatData(const MatAllocator* allocator);
~UMatData();
bool hostCopyObsolete() const;
bool deviceCopyObsolete() const;
+ bool deviceMemMapped() const;
bool copyOnMap() const;
bool tempUMat() const;
bool tempCopiedUMat() const;
void markHostCopyObsolete(bool flag);
void markDeviceCopyObsolete(bool flag);
+ void markDeviceMemMapped(bool flag);
const MatAllocator* prevAllocator;
const MatAllocator* currAllocator;
struct CV_EXPORTS UMatDataAutoLock
{
- UMatDataAutoLock(UMatData* u);
+ explicit UMatDataAutoLock(UMatData* u);
~UMatDataAutoLock();
UMatData* u;
};
struct CV_EXPORTS MatSize
{
- MatSize(int* _p);
+ explicit MatSize(int* _p);
Size operator()() const;
const int& operator[](int i) const;
int& operator[](int i);
struct CV_EXPORTS MatStep
{
MatStep();
- MatStep(size_t s);
+ explicit MatStep(size_t s);
const size_t& operator[](int i) const;
size_t& operator[](int i);
operator size_t() const;
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.
- \image html 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()
template<typename _Tp> MatConstIterator_<_Tp> begin() const;
template<typename _Tp> MatConstIterator_<_Tp> end() const;
+ //! template methods for for operation over all matrix elements.
+ // the operations take care of skipping gaps in the end of rows (if any)
+ template<typename _Tp, typename Functor> void forEach(const Functor& operation);
+ template<typename _Tp, typename Functor> void forEach(const Functor& operation) const;
+
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 };
uchar* data;
//! helper fields used in locateROI and adjustROI
- uchar* datastart;
- uchar* dataend;
- uchar* datalimit;
+ const uchar* datastart;
+ const uchar* dataend;
+ const uchar* datalimit;
//! custom allocator
MatAllocator* allocator;
MatStep step;
protected:
+ template<typename _Tp, typename Functor> void forEach_impl(const Functor& operation);
};
\endcode
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:
+ access operations and if you know matrix type at compile time. Note that cv::Mat::at and
+ cv::Mat::operator() do absolutely the same thing and run at the same speed, but the latter is certainly shorter:
\code
Mat_<double> M(20,20);
const_iterator begin() const;
const_iterator end() const;
+ //! template methods for for operation over all matrix elements.
+ // the operations take care of skipping gaps in the end of rows (if any)
+ template<typename Functor> void forEach(const Functor& operation);
+ template<typename Functor> void forEach(const Functor& operation) const;
+
//! equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type)
void create(int _rows, int _cols);
//! equivalent to Mat::create(_size, DataType<_Tp>::type)
void convertTo( SparseMat& m, int rtype, double alpha=1 ) const;
//! converts sparse matrix to dense n-dim matrix with optional type conversion and scaling.
/*!
- \param rtype The output matrix data type. When it is =-1, the output array will have the same data type as (*this)
- \param alpha The scale factor
- \param beta The optional delta added to the scaled values before the conversion
+ @param [out] m - output matrix; if it does not have a proper size or type before the operation,
+ it is reallocated
+ @param [in] 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.
+ @param [in] alpha – optional scale factor
+ @param [in] beta – optional delta added to the scaled values
*/
void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const;
//! copy operator
MatConstIterator& operator = (const MatConstIterator& it);
//! returns the current matrix element
- uchar* operator *() const;
+ const uchar* operator *() const;
//! returns the i-th matrix element, relative to the current
- uchar* operator [](ptrdiff_t i) const;
+ const uchar* operator [](ptrdiff_t i) const;
//! shifts the iterator forward by the specified number of elements
MatConstIterator& operator += (ptrdiff_t ofs);
const Mat* m;
size_t elemSize;
- uchar* ptr;
- uchar* sliceStart;
- uchar* sliceEnd;
+ const uchar* ptr;
+ const uchar* sliceStart;
+ const uchar* sliceEnd;
};
//! constructor that sets the iterator to the specified element of the matrix
MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0);
//! constructor that sets the iterator to the specified element of the matrix
- MatIterator_(const Mat_<_Tp>* _m, Point _pt);
+ MatIterator_(Mat_<_Tp>* _m, Point _pt);
//! constructor that sets the iterator to the specified element of the matrix
- MatIterator_(const Mat_<_Tp>* _m, const int* _idx);
+ MatIterator_(Mat_<_Tp>* _m, const int* _idx);
//! copy constructor
MatIterator_(const MatIterator_& it);
//! copy operator