网上查阅得到:
Mat Mat::reshape(int cn, int rows=0) const
opencv手册上的解释为:Changes the shape and/or the number of channels of a 2D matrix without copying the data.
参数cn:新的通道数;如果cn值为0表示变换前后通道数不变
参数rows:新的行数;如果rows值为0表示变换后矩阵的行数不变
该函数会为当前矩阵创建一个新的矩阵头(指针),新的矩阵拥有不同的尺寸或者不同的通道数,其优点在于运算复杂度为O(1),不用复制矩阵数据.正是因为不用复制数据,所以在转变过程中要保证原数据矩阵在数据上的连续性(这里的连续性是相对于原矩阵来说)为了更好的说明,举个例子:
std::vector<Point3f> vec;//一个3D数据点的集合
...
Mat pointMat = Mat(vec). // 将这个三维向量集合转换为矩阵,复制度为O(1);实际上形成的矩阵为一个N*1的3通道图像阵
reshape(1). // 用reshape方法将其映射为N*3的1通道图像阵,同样运算复杂度为O(1)
实际中我们测试如下:
xgv=[1,2,3];
Mat mm;
mm=xgv.reshape(1,1);
cerr<<mm<<endl;
repeat(xgv.reshape(1,1),ygv.total(),1,X);
repeat(ygv.reshape(1,1).t(), 1, xgv.total(), Y);
mm=[1 2 3];
ex2:
Mat mm;
mm=xgv.reshape(1,3);
cerr<<mm<<endl;
repeat(xgv.reshape(1,1),ygv.total(),1,X);
repeat(ygv.reshape(1,1).t(), 1, xgv.total(), Y);
mm=[1;2;3];
ex3:
Mat mm;
mm=xgv.reshape(3,1);
cerr<<mm<<endl;
repeat(xgv.reshape(1,1),ygv.total(),1,X);
repeat(ygv.reshape(1,1).t(), 1, xgv.total(), Y);
mm=[1,2,3]
现在明白了吧
repeat很简单。网上的教程很多,我就不说哦。