【转发】为什么opencv中widthStep不一定等于width*nChannels
opencv的图像属性widthStep属性有点奇怪,比width * nChannels稍大。 像3*3的3通道bmp图像那样,所有像素的RGB成分为97,输出如下。
图像详细参数
nSize: 112
imageSize: 36
nChannels: 3
height: 3
width: 3
widthstep: 12
979797979797979797000
979797979797979797000
979797979797979797000
可以看到在每一行之后补充了零。 将widthstep设置为4的倍数。 为什么会这样呢?
我们先来看看下面的例子。
类a
{
char a;
(;
类b
{
char a;
int b;
(;
int main () )
{
STD : cout ' sizeofa : ' sizeof (a ) std:endl;
STD : cout ' sizeofb : ' sizeof (b ) std:endl;
std:cin.get (;
返回0;
}
输出1 ) 8;
从这个例子可以看到,类中成员的内存是自动补充的,补充方式都是4的倍数。 我觉得opencv也是同样的理由。 (对齐内存)
从3http://blog.csdn.net/zhi rom/article/details/7487159转发