我知道对于单通道字节图像,您可以:
((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]
无济于事。
谢谢,
答案 0 :(得分:1)
实际上,如果你使用widthStep / 2 ...
,那么短句工作正常答案 1 :(得分: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