采用函数reshape
Changes the shape and/or the number of channels of a 2D matrix without copying the data.
-
Mat Mat::reshape(int cn, int rows=0) const
代码如下:
Mat mat(4,4,CV_8UC3);
Mat mat1=mat.reshape(3,16);
将4*4的3通道mat转换成1*16的单通道mat1;
注意: 第一个参数是通道的数目