Mat类型可以被认为是OpenCV库的核心。 OpenCV库中绝大多数的函数都是Mat类的成员,以Mat作为参数,或者Mat作为返回值。

Mat类用于表示任意维数的密集数组。即使对于数组中的该条目为零,也存在与该条目相对应的数据值。大多数图像都以密集阵列的形式存储。在稀疏数组的情况下,通常只存储非零条目。如果许多条目都是零,那么可以节省大量的存储空间。使用稀疏数组而不是密集数组的常见情况是直方图。对于许多直方图,大多数条目都是零,并且存储所有这些零不是必需的。对于稀疏数组的情况,OpenCV有另一种数据结构,SparseMat。

如果你熟悉OpenCV库的C接口(2.1之前的版本),您将会记住IplImage和CvMat的数据类型。 你也可能记得CvArr。 在C ++实现中,所有这些都消失了,用Mat代替。Mat类可以用于任何维数的数组。数据被存储在阵列中,被认为是“光栅扫描顺序”的n维数字。这意味着在一维数组中,元素是顺序的。在二维数组中,数据按行组织,每行依次出现。对于三维阵列,每个平面都是逐行填充的。

每个Mat都包含一个标志元素,指示数组内容,一个dims元素指示维数,rows和cols元素指示行数和列数,指向数据指针的位置数组数据被存储,一个类似于Ptr <>的的引用计数器。数据数组被布置成使得其索引由(i0,ii,...,iNd-1)给出的元素的地址是:

在二维数组的简单情况下,这可以简化为:

&(mtxi, j)= mtx.data +mtx.step 0 *i +mtx.step 1 *j

Mat中每个数据元素本身可以是单个数字,也可以是多个数字。在多个数字的情况下,这就是多通道数组。一个数组可能被认为是一个32位浮点数的二维三通道数组;在这种情况下,数组的元素是三个32位浮点数,大小为12个字节。在内存中布局时,数组的行可能不是绝对顺序的;在下一个之前可能会有小的间隙缓冲每一行。一个n维单通道阵列和一个(n-1)维多通道阵列之间的区别在于,这个填充将始终发生在整行的末尾,即元素中的通道将始终是连续的)。

可以简单地通过实例化一个类型为Mat的变量来创建一个数组。以这种方式创建的数组没有大小和数据类型。但是,可以使用create()等成员函数分配数据。 create()的一个变体将多个行,多个列和一个类型作为参数,并将该数组表示为一个二维对象。数组的类型决定了它具有哪种元素以及通道的数量。所有这些类型都在库中定义,并具有CV_ {8U,16S,16U,32S,32F,64F} C {1,2,3}的格式。例如,CV_32FC3意味着一个32位浮点三通道阵列。

也可以在首次分配矩阵时指定这些内容。Mat有许多构造函数,其中一个与create()具有相同的参数。例如:

cv::Mat m;

// 创建3行10列3通道32位浮点型数据

m.create( 3, 10, CV_32FC3 );

//设置第一个通道为1.0,第二个通道为0.0,第三个通道为1.0

m.setTo( cv::Scalar( 1.0f, 0.0f, 1.0f ) );

//上面的定义与下面的语句等价

Mat m( 3, 10, CV_32FC3, cv::Scalar( 1.0f, 0.0f, 1.0f ) );

Mat对象实际上是数据区域的头,原则上它是一个完全独立的东西。 例如,可以将一个矩阵n分配给另一个矩阵m(即,m = n)。 在这种情况下,m中的数据指针将被改变为指向与n相同的数据。 先前由m的数据元素指向的数据将被释放。同时,它们现在共享的数据区域的引用计数器将递增。同时将更新m成员的数据(如行,列和标志),以准确描述m中数据指向的数据。

表1是Mat的构造函数的完整列表。但事实上,大多数时候可能使用其中的一小部分。

表1 Mat的构造函数

构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据
构造函数 说明
Mat 缺省构造函数
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(
cv::Size sz, int type )
指定类型和大小的二维数组
Mat(cv::Size
sz,
int
type, const Scalar& s)
指定类型、大小和初始值的二维数组
Mat(cv::Size
sz, int type,
void*
data, size_t step=AUTO_STEP)
指定类型和大小的二维数组,具有预先存在的数据
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,size_t step=AUTO_STEP)
指定类型和大小的多维数组,具有预先存在的数据

表1列出了Mat对象的构造函数。除了默认的构造函数之外,它们分为三个基本类别:有些需要多行和多列来创建二维数组的类,有些使用Size对象创建,有些构造n维数组并要求指定维数并传入指定每个维的大小的整数数组的指针。此外,其中一些允许初始化数据,或者通过Scalar提供初始化值(这时整个数组将被初始化为该值),或者通过提供指向数据块的指针来指定。在后一种情况下,只是为现有数据创建一个数据头,不复制数据;将数据成员设置为指向由数据参数指示的数据)。

表2的复制构造函数显示了如何从另一个数组创建一个数组。除了基本的复制构造函数外,还有三种方法用于从现有数组的子区域构建数组,以及使用某个矩阵表达式的结果初始化新矩阵的构造函数。

表2 复制构造函数

构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数
构造函数 说明
Mat(
const Mat& mat )
复制构造函数
Mat(const
Mat& mat,
const
cv::Range& rows,
const
cv::Range& cols)
复制指定行列的构造函数
Mat(const
Mat& mat,
const
cv::Rect& roi)
复制指定矩形区域的构造函数
Mat(const
Mat& mat,
const
cv::Range* ranges)
从n维数组中选择范围构造数组
Mat(
const cv::MatExpr& expr )
使用其他矩阵的代数表达式的结果初始化复制构造函数

也可以从OpenCV2.1版之前的CvMat或IplImage结构创建新的C ++风格的Mat结构。在这种情况下,可以采用下面表3这种方式转换。

表3 从旧的数据类型构造数组

构造函数 说明
Mat(const
CvMat* old,bool copyData=false)
从旧的CvMat构造新对象的函数
Mat(const
IplImage* old,bool copyData=false)
从旧的IplImage构造新对象的函数
构造函数 说明
Mat(const
CvMat* old,bool copyData=false)
从旧的CvMat构造新对象的函数
Mat(const
IplImage* old,bool copyData=false)
从旧的IplImage构造新对象的函数
构造函数 说明
Mat(const
CvMat* old,bool copyData=false)
从旧的CvMat构造新对象的函数
Mat(const
IplImage* old,bool copyData=false)
从旧的IplImage构造新对象的函数
构造函数 说明
Mat(const
CvMat* old,bool copyData=false)
从旧的CvMat构造新对象的函数
Mat(const
IplImage* old,bool copyData=false)
从旧的IplImage构造新对象的函数
构造函数 说明
Mat(const
CvMat* old,bool copyData=false)
从旧的CvMat构造新对象的函数
Mat(const
IplImage* old,bool copyData=false)
从旧的IplImage构造新对象的函数
构造函数 说明
Mat(const
CvMat* old,bool copyData=false)
从旧的CvMat构造新对象的函数
Mat(const
IplImage* old,bool copyData=false)
从旧的IplImage构造新对象的函数
构造函数 说明
Mat(const
CvMat* old,bool copyData=false)
从旧的CvMat构造新对象的函数
Mat(const
IplImage* old,bool copyData=false)
从旧的IplImage构造新对象的函数
构造函数 说明
Mat(const
CvMat* old,bool copyData=false)
从旧的CvMat构造新对象的函数
Mat(const
IplImage* old,bool copyData=false)
从旧的IplImage构造新对象的函数
构造函数 说明
Mat(const
CvMat* old,bool copyData=false)
从旧的CvMat构造新对象的函数
Mat(const
IplImage* old,bool copyData=false)
从旧的IplImage构造新对象的函数

这些构造函数可能比你刚开始认识OpenCV的时候要多得多。还有一种构造函数是模板构造函数。 这些被称为模板构造函数是因为它们从本身就是模板的东西构建了Mat的实例。 这些构造函数允许使用任意Vec <>或Matx <>来创建具有相应维数和类型的Mat数组,或者使用任意类型的STL向量<>对象来构造一个相同类型的数组。表4是这种构造方式。

表4 从Vec等类型构造数组

构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组
构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组
构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组
构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组
构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组
构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组
构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组
构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组
构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组
构造函数 说明
Mat(const
cv::Vec<T,n>& vec,bool copyData=true)
从Vec构造类型为T且大小为n的一维数组
Mat(const
cv::Matx<T,m,n>& vec,bool copyData=true)
从Matx构造一个类型为T且大小为m×n的二维数组
Mat(const std::vector<T>&
vec,bool copyData=true)
从STL构造类型T的一维数组

Mat类还提供了许多静态成员函数来创建特定类型的常用数组(表4-5)。 这些函数包括zero(),ones()和eye()等函数,它们分别构造一个全是零的矩阵,一个全是1矩阵的矩阵和一个单位矩阵。表5是这种构造方式

表5 几种特殊的矩阵构造方式

构造函数 说明
Mat::zeros(
rows, cols, type );
全是0的矩阵
Mat::ones(
rows, cols, type );
全是1的矩阵
Mat::eye(
rows, cols, type );
单位阵
构造函数 说明
Mat::zeros(
rows, cols, type );
全是0的矩阵
Mat::ones(
rows, cols, type );
全是1的矩阵
Mat::eye(
rows, cols, type );
单位阵
构造函数 说明
Mat::zeros(
rows, cols, type );
全是0的矩阵
Mat::ones(
rows, cols, type );
全是1的矩阵
Mat::eye(
rows, cols, type );
单位阵
构造函数 说明
Mat::zeros(
rows, cols, type );
全是0的矩阵
Mat::ones(
rows, cols, type );
全是1的矩阵
Mat::eye(
rows, cols, type );
单位阵
构造函数 说明
Mat::zeros(
rows, cols, type );
全是0的矩阵
Mat::ones(
rows, cols, type );
全是1的矩阵
Mat::eye(
rows, cols, type );
单位阵
构造函数 说明
Mat::zeros(
rows, cols, type );
全是0的矩阵
Mat::ones(
rows, cols, type );
全是1的矩阵
Mat::eye(
rows, cols, type );
单位阵
构造函数 说明
Mat::zeros(
rows, cols, type );
全是0的矩阵
Mat::ones(
rows, cols, type );
全是1的矩阵
Mat::eye(
rows, cols, type );
单位阵
构造函数 说明
Mat::zeros(
rows, cols, type );
全是0的矩阵
Mat::ones(
rows, cols, type );
全是1的矩阵
Mat::eye(
rows, cols, type );
单位阵
构造函数 说明
Mat::zeros(
rows, cols, type );
全是0的矩阵
Mat::ones(
rows, cols, type );
全是1的矩阵
Mat::eye(
rows, cols, type );
单位阵

对于Mat中的数据访问方式可以参考第6部分的说明。

有时候我们需要访问数组中的某一块元素,可能是选择一行或一列,或原始数组的任何子区域。有很多方法可以做到这一点,表6是Mat类的成员函数,并返回调用它们的数组的子部分。

表6 Mat的成员函数

成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组
成员函数 说明
m.row(
i );
对应于m的第i行的数组
m.col(
j );
对应于m的第j列的数组
m.rowRange(
i0, i1 );
对应于矩阵m的第i0至i1-1行的数组
m.rowRange(
cv::Range( i0, i1 ) );
对应于矩阵m的第i0至i1-1行的数组
m.colRange(
j0, j1 );
对应于矩阵m的列j0至j1-1的数组
m.colRange(
cv::Range( j0, j1 ) );
对应于矩阵m的列j0至j1-1的数组
m.diag(
d );
对应于矩阵m的d对角线的数组
m(
cv::Range(i0,i1), cv::Range(j0,j1) )
对应于矩阵m的子矩形(i0,j0)和(i1-1,j1-1)对应的数组
m(
cv::Rect(i0,i1,w,h) );
对应于矩阵m的子矩形i0,j0和高宽w-1,
h-1对应的数组
m(
ranges );
对应于m中提取range [0]- [ndim-1]给出的范围的数组

这些方法中最简单的方法是row()和col()。与row()和col()紧密相关的是rowRange()和colRange()。这些函数基本上是一样的,只不过他们会提取一个具有多个连续行(或列)的数组。可以通过以下两种方式之一调用这两个函数:指定一个整数开始和结束行(或列),或者通过传递一个行(或列)的Range对象。范围包括开始索引但不包括结束索引。

除了从m.diag()返回的数组引用矩阵的对角线元素之外,成员函数diag()与row()或col()的作用相同。 m.diag()需要一个整数参数,用于指示要提取哪个对角线。如果该参数为零,那么它将是主对角线。如果是正数,则它将从阵列上半部分的主对角线偏移该距离。如果它是负数,那么它将来自阵列的下半部分。

提取子矩阵的最后一种方法是使用operator()。使用这个运算符,你可以传递一对范围(行的Range和列的Range)或者从Rect指定你想要的区域。

opencv mat用数组初始化_10、OpenCV中图像和Mat类型(一)相关推荐

  1. OpenCV中图像以Mat类型保存时各通道数据在内存中的组织形式及python代码访问各通道数据的简要方式...

    OpenCV中图像以Mat类型保存时各通道数据在内存中的组织形式及python代码访问各通道数据的简要方式 以最简单的4 x 5三通道图像为例,其在内存中Mat类型的数据组织形式如下: 每一行的每一列 ...

  2. java 数组 初始化 个数_Java中数组的初始化

    一.什么是初始化 在Java程序开发中,使用数组之前都会对其进行初始化,这是因为数组是引用类型,声明数组只是声明一个引用类型的变量,并不是数组对象本身,只要让数组变量指向有效的数组对象,程序中就可使用 ...

  3. Mat的初始化以及Mat与数组的相互转化

    Mat类型数据的初始化方法可以有以下两种: 1.直接初始化 Mat_<float> T_L = (Mat_<float>(3, 1) << -518.97666, ...

  4. OpenCv案例(一):OpenCvSharp识别图像中物体个数

    需求:识别下图中零件的个数,包括其中有粘连部分:同理,可以识别零件以及其他产线样品数量;(如果不知如何使用OpenCvSharp,参考该文章(OpenCvSharp安装)中第一部分内容) 识别图像: ...

  5. Linux Kernel代码艺术——数组初始化

    前几天看内核中系统调用代码,在系统调用向量表初始化中,有下面这段代码写的让我有点摸不着头脑: const sys_call_ptr_t sys_call_table[__NR_syscall_max+ ...

  6. java如何给数组初始化?

    关于java数组的文章早已是非常多了,本文是对我个人过往学习java,理解及应用java数组的一个总结.此文内容涉及java数组的基本概念,以及java如何给数组初始化?初始化的几种方式?希望对大家有 ...

  7. OpenCV中IplImage/CvMat/Mat转化关系

    原文链接:http://www.cnblogs.com/summerRQ/articles/2406109.html 如对内容和版权有何疑问,请拜访原作者或者通知本人. opencv中常见的与图像操作 ...

  8. OpenCV中基本数据类型Mat类使用简析

    Mat 类是OpenCV中的一个基本数据类型,它是一个n维密集数组类 Mat 类表示一个 n 维密集数值单通道或多通道数组.它可用于存储实数或复值向量和矩阵.灰度或彩色图像.体素体积.向量场.点云.张 ...

  9. OpenCV中图像Mat,二维指针和CxImage类之间的转换

    在做图像处理中,常用的函数接口有Opencv中的Mat图像类,有时候需要直接用二维指针开辟内存直接存储图像数据,有时候需要用到CxImage类存储图像.本文主要是总结下这三类存储方式之间的图像数据的转 ...

最新文章

  1. python批量爬取文档
  2. js.map error
  3. ICA处理后,如何判断眼电、心电等成分?
  4. 中科元素精准饮食 功能性农业-李喜贵:电视荧屏广州地铁线展示
  5. 信息系统项目管理师论文考试汇总(2010~2021年)
  6. 什么是Ext(ExtJs)【转载】
  7. day7——集合,深浅copy
  8. python标签控件是_Python 图形用户界面编程
  9. 关于HTTP协议的学习
  10. Unable to cast object of type ‘Newtonsoft.Json.Linq.JArray‘ to type ‘Newtonsoft.Json.Linq.JObject‘.
  11. 算法导论第三版 21.2-3习题答案
  12. 毕业设计 STM32单片机的GPS定位系统 - 物联网
  13. 基于EDA技术的频率计系统设计
  14. POS机31个基础知识你了解多少?
  15. 阿里P7架构师浅谈Java 的年薪 40W 是什么水平?
  16. 网络信息安全期末复习要点
  17. 基于5g的交通运输_一种基于5G的智慧交通基础服务平台
  18. 移动支付这回真的逆天了!什么才是真正的资本运作?让微信春晚来告诉你!...
  19. 在材料技术方面的进步使游戏改变了MLCC的性能
  20. 非常漂亮的放焰火效果的Applet程序

热门文章

  1. 538. Convert BST to Greater Tree
  2. php5.6 和apache2.2的相互配置
  3. sonarQube安装及本机扫描C#项目
  4. 【转】VMware虚拟机中CentOS设置固定IP
  5. 一次使用 Eclipse Memory Analyzer 分析 Tomcat 内存溢出
  6. python操作mongodb数据库
  7. 使用Vitamio打造自己的Android万能播放器(2)—— 手势控制亮度、音量、缩放
  8. 精华:软件架构模式的7种武器
  9. 源码解读Dubbo分层设计思想
  10. Java 运行时数据区域,哪些是线程隔离的?哪些又是公有的?