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

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的行列变换是不会显现出有改变的

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值