1

我想填充黑白图像并显示它。

我不明白这段代码有什么意义:

IplImage * imageOut;
int window = 100;

cvNamedWindow("mappa", CV_WINDOW_AUTOSIZE );
imageOut = cvCreateImage(cvSize(window,window),8,1);

    for(int i=0; i<window; i++){  
        for(int j=0; j<window;j++){

            ((unsigned char*)(imageOut->imageData + i*imageOut->widthStep))[j]= j;
        }
    }

    cvShowImage("mappa", imageOut );
4

2 回答 2

0

访问像素时,您的坐标不应该交换吗?
所以这一行会写成:

((unsigned char*)(imageOut->imageData + j*imageOut->widthStep))[i]= j;
于 2011-04-01T10:06:47.117 回答
0

正确的程序是:

imageOut = cvCreateImage(cvSize(window,window),IPL_DEPTH_8U,1);
int width = imageOut->width; 
int height = imageOut->height;
int bpp = imageOut->nChannels; 
for (int i=0; i < width*height*bpp; i+=bpp) 
{    
   imageOut->imageData[i] = i & 0xff;  // some casting might be needed here
}
于 2011-04-01T13:54:11.443 回答