IplImage 结构体中char *imageData的理解

 

////////////////////////////////////////////////////////////////////////
//
// 该程序从文件中读入一幅图像,将之反色,然后显示出来. 
//
////////////////////////////////////////////////////////////////////////
#include 
#include 
#include 
#include 
#include  
 
int main(int argc, char *argv[])
{
  IplImage* img = 0; 
  int height,width,step,channels;
  uchar *data;
  int i,j,k; 
 
  if(argc<2){
    printf("Usage: main \n\7");
    exit(0);
  } 
 
  // load an image  
  img=cvLoadImage(argv[1]);
  if(!img){
    printf("Could not load image file: %s\n",argv[1]);
    exit(0);
  } 
 
  // get the image data
  height    = img->height;
  width     = img->width;
  step      = img->widthStep;
  channels  = img->nChannels;
  data      = (uchar *)img->imageData;
  printf("Processing a %dx%d image with %d channels\n",height,width,channels); 
 
  // create a window
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  cvMoveWindow("mainWin", 100, 100); 
 
  // invert the image
  for(i=0;i

 

     在上述的程序中,假如我们读取了一副大小为100*100的3Channels图像,则每一个像素点可以由3个char来表示。也就是说,这幅图像就可以看成是100*100*3个char字符组成。而我们知道,每个char占8bit,也就是0~255之间的某个数。

     在invert图像的时候,使用i*step+j*channels+k的含义也就十分明确了!

你可能感兴趣的:(IplImage 结构体中char *imageData的理解)