2

我知道对于单通道字节图像,您可以:

((uchar *)(img->imageData + i*img->widthStep))[j]

对于单通道浮动图像,您可以:

((float*)(img->imageData + i*img->widthStep))[j]

但是对于 16 位签名图像(IPL_DEPTH_16S)怎么样,我试过了:

((short*)(img->imageData + i*img->widthStep))[j]

((signed int*)(img->imageData + i*img->widthStep))[j]

无济于事。

谢谢,

4

2 回答 2

1

实际上,如果您采用 widthStep/2,则短片效果很好...

于 2011-03-31T17:38:32.573 回答
0

答案是 :

 (((short*)(img->imageData)) + i*img->widthStep)[j]

这个例子解释了原因:

#include <stdio.h>

int main(){
    char * pointer;

    printf("%zu \n", sizeof(char));
    printf("%zu \n", sizeof(signed short));
    printf("%zu \n", sizeof(signed int));
    printf("%zu \n", sizeof(float));

    printf("%p \n",((char*)(pointer) + 10 * 5));
    printf("%p \n",((signed short*)(pointer)) + 10 * 5);
    printf("%p\n",(((signed int*)(pointer)) + 10 * 5));
    printf("%p\n",((float*)(pointer)) + 10 * 5);
}

1 
2 
4 
4 
0x7fff5fc01084 
0x7fff5fc010b6 
0x7fff5fc0111a
0x7fff5fc0111a
于 2011-04-01T08:40:05.500 回答