I wanna fill a black and white image and show it.
I can't understand what's the metter with this code:
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*)(imageOu开发者_如何学编程t->imageData + i*imageOut->widthStep))[j]= j;
}
}
cvShowImage("mappa", imageOut );
The correct procedure would be:
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
}
When accessing the pixel shouldn't your co-ords be swapped round?
So this line would read:
((unsigned char*)(imageOut->imageData + j*imageOut->widthStep))[i]= j;
精彩评论