opencv2学习(五)——reshape函数的使用

来源:互联网 发布:岗位优化人员优化方案 编辑:程序博客网 时间:2024/05/21 19:30

reshape不需要内存拷贝或者重新分配就能改变矩阵的维度

Mat reshape(int cn, int rows=0) const;

cn:表示通道数channels,如果设为0,则表示保持通道数不变,否则则变为设置的通道数

rows;表示矩阵函数,如果设为0,则表示所有函数不变,否则则变为设置的函数

Mat reshape(int cn, int newndims, const int* newsz) const;提供方便的重载函数,和上面的函数只有输入参数不同。

程序代码:

int main(void){Mat Image = imread("F:\\1\\yellow_lane\\0.png", 1);cout<<"channel:"<<Image.channels()<<endl;cout<<"rows:"<<Image.rows<<endl;cout<<"cols:"<<Image.cols<<endl;cout<<endl;Mat dst = Image.reshape(1, Image.cols*Image.channels()*Image.rows);cout<<"channel:"<<dst.channels()<<endl;cout<<"rows:"<<dst.rows<<endl;cout<<"cols:"<<dst.cols<<endl;return 0;}

需要注意的是,如果程序这样写:
Image.reshape(1, Image.cols*Image.channels()*Image.rows);
Image的行列变换是不会显现出有改变的

1 0
原创粉丝点击