opencv中mat的step与elemSize

文章介绍了OpenCV中的矩阵元素大小计算方法(elemSize和elemSize1),以及如何计算矩阵行的占用字节数(step和step1),强调了数据在内存中的有效布局对于内存效率的影响。特别提到一个具体例子,如100x100的三通道short矩阵,展示了如何计算每个像素和通道的字节数以及行内值的数量。
摘要由CSDN通过智能技术生成

    /** @brief Returns the matrix element size in bytes.

    The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 ,the method returns 3*sizeof(short) or 6.*/

    size_t elemSize() const;

    /** @brief Returns the size of each matrix element channel in bytes.

    The method returns the matrix element channel size in bytes, that is, it ignores the number of  channels. For example, if the matrix type is CV_16SC3 , the method returns sizeof(short) or 2. */

size_t elemSize1() const;

elemSize是一个像素的字节数,elemSize1是一个像素点的一个通道(也就是一个值)的字节数

step Number of bytes each matrix row occupies. The value should include the padding bytes at the end of each row, if any.

step[0]为一行的字节数(因为可能有字节对齐所以并不一定等于cols*elemSize()),step[1]为一个像素点的字节数

    /** @brief Returns a normalized step.

    The method returns a matrix step divided by Mat::elemSize1() . It can be useful to quickly access anarbitrary matrix element.*/

size_t step1(int i=0) const;

step1(0)为一行的值个数,step1(1)为一个像素点的值个数,也就是通道数,从注释中可以看出step1(i)=step[i]/elemSize1(),也就是计数单位从step的字节变成step1值

设置一个行列为100,值类型为short(2字节长),三通道,每行1000字节的矩阵

每个像素的字节数为3*2=6

每个通道的字节数为2

每行最多可容纳1000/6=166个像素

每行1000字节(实际有400字节的浪费)

每个像素6字节

每行可容纳step[0]/elemSize1()=500个值

每个像素可容纳step[1]/elemSize1()=3个值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值