IplImage yes OpenCV in CxCore Partial basic data structure , Used to represent images , among Ipl yes Intel Image Processing Library Short for .

OpenCV2.1 Use before version IplImage* Data structure to represent the image ,2.1 Later versions use image containers Mat To store .IplImage The structure is shown below .
typedef struct _IplImage { int nSize; /* IplImage size */ int ID; /* edition (=0)*/
int nChannels; /* majority OPENCV Function support 1,2,3 or 4 Channels */ int alphaChannel; /* cover OpenCV ignore
*/ int depth; /* The bit depth of the pixel : IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16U,
IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F Supported */ char
colorModel[4]; /* cover OpenCV ignore */ char channelSeq[4]; /* ditto */ int dataOrder; /* 0
- Cross access color channel , 1 - Separate color channels . cvCreateImage Only cross access images can be created */ int origin; /* 0 - top — Left structure , 1
- bottom — Left structure (Windows bitmaps style ) */ int align; /* Image row arrangement (4 or 8). OpenCV Ignore it , use
widthStep replace */ int width; /* Image width prime number */ int height; /* Image high pixel number */ struct _IplROI
*roi;/* Image region of interest . When the value is not null, only the region is processed */ struct _IplImage *maskROI; /* stay
OpenCV Must be set in NULL */ void *imageId; /* ditto */ struct _IplTileInfo *tileInfo; /* ditto */
int imageSize; /*
Image data size ( In cross access format imageSize=image->height*image->widthStep), Unit byte */ char
*imageData; /* Image data pointing to permutation */ int widthStep; /* Row size of images arranged , In bytes */ int
BorderMode[4]; /* Marginal ending pattern , cover OpenCV ignore */ int BorderConst[4]; /* ditto */ char
*imageDataOrigin; /* The pointer points to a different image data structure ( It doesn't have to be arranged ), Is prepared to correct image memory allocation */ } IplImage;
Allocate and release image space :
// Allocate image space IplImage* cvCreateImage(CvSize size, int depth, int channels); size:
cvSize(width,height); depth: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16U,
IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F, IPL_DEPTH_64F channels: 1, 2, 3 or
4. // Note that the data is cross access . The data of color image is arranged as b0 g0 r0 b1 g1 r1 ... // Assign a single channel byte image IplImage*
img1=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1); // Assign a three channel floating point image IplImage*
img2=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3); // Free up image space IplImage*
img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1); cvReleaseImage(&img);  
// Copy image IplImage* img1=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1); IplImage*
img2; img2=cvCloneImage(img1);   // set up / Get region of interest : void cvSetImageROI(IplImage*
image, CvRect rect); void cvResetImageROI(IplImage* image); vRect
cvGetImageROI(const IplImage* image); // set up / Access to interest channels : void cvSetImageCOI(IplImage*
image, int coi); // 0=all int cvGetImageCOI(const IplImage* image);
Read stored image :
// Loading images from a file : IplImage* img=0; img=cvLoadImage(fileName); if(!img) printf("Could
not load image file: %s/n",fileName); Supported image formats: BMP, DIB, JPEG,
JPG, JPE, PNG, PBM, PGM, PPM, SR, RAS, TIFF, TIF // Loading image is converted to 3 Channel color image .
If not , It needs to be added flag: img=cvLoadImage(fileName,flag); //flag: >0 Load image to three channel color image =0
Load image to single channel gray image <0 Load images are not converted ( The number of channels is the same as the image file ).   // Images are stored as image files :
if(!cvSaveImage(outFileName,img)) printf("Could not save: %s/n",outFileName);
// The input file format is determined by the file extension .
Accessing image elements :
// Suppose you need to read the i That's ok j The order of the image points k passageway . among , Number of rows i The range of [0, height-1], Number of columns j The range of [0, width-1],
passageway k The range of [0, nchannels-1].   /* Indirect access : ( More general , But it's inefficient , Any type of image data can be read )*/   // For single channel byte image :
IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1); CvScalar s;
s=cvGet2D(img,i,j); // get the (i,j) pixel value
printf("intensity=%f/n",s.val[0]); s.val[0]=111; cvSet2D(img,i,j,s); // set the
(i,j) pixel value   // For multichannel floating point or byte images : IplImage*
img=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3); CvScalar s;
s=cvGet2D(img,i,j); // get the (i,j) pixel value printf("B=%f, G=%f,
R=%f/n",s.val[0],s.val[1],s.val[2]); s.val[0]=111; s.val[1]=111; s.val[2]=111;
cvSet2D(img,i,j,s); // set the (i,j) pixel value   /* Direct access : ( efficient , But it's easy to make mistakes )*/  
// For single channel byte image : IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
((uchar *)(img->imageData + i*img->widthStep))[j]=111;   // For multichannel byte images : IplImage*
img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3); ((uchar *)(img->imageData +
i*img->widthStep))[j*img->nChannels + 0]=111; // B ((uchar *)(img->imageData +
i*img->widthStep))[j*img->nChannels + 1]=112; // G ((uchar *)(img->imageData +
i*img->widthStep))[j*img->nChannels + 2]=113; // R   // For multichannel floating point images : IplImage*
img=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3); ((float *)(img->imageData +
i*img->widthStep))[j*img->nChannels + 0]=111; // B ((float *)(img->imageData +
i*img->widthStep))[j*img->nChannels + 1]=112; // G ((float *)(img->imageData +
i*img->widthStep))[j*img->nChannels + 2]=113; // R   /* Direct access with pointer : ( Simple and efficient in some cases )*/
  // For single channel byte image : IplImage* img = cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
int height = img->height; int width = img->width; int step =
img->widthStep/sizeof(uchar); uchar* data = (uchar *)img->imageData;
data[i*step+j] = 111;   // For multichannel byte images : IplImage* img =
cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3); int height = img->height; int
width = img->width; int step = img->widthStep/sizeof(uchar); int channels =
img->nChannels; uchar* data = (uchar *)img->imageData;
data[i*step+j*channels+k] = 111;   // For single channel floating point images ( Hypothetical 4 Byte adjustment ): IplImage* img =
cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3); int height = img->height; int
width = img->width; int step = img->widthStep/sizeof(float); int channels =
img->nChannels; float * data = (float *)img->imageData;
data[i*step+j*channels+k] = 111;     /* use c++ wrapper Direct access : ( Simple and efficient )*/  
// Check list / Multi channel byte image , Multi channel floating point image definition  c++ wrapper: template<class T> class Image { private:
IplImage* imgp; public: Image(IplImage* img=0) {imgp=img;} ~Image(){imgp=0;}
void operator=(IplImage* img) {imgp=img;} inline T* operator[](const int
rowIndx) { return ((T *)(imgp->imageData + rowIndx*imgp->widthStep));} };
typedef struct{ unsigned char b,g,r; } RgbPixel; typedef struct{ float b,g,r; }
RgbPixelFloat; typedef Image<RgbPixel> RgbImage; typedef Image<RgbPixelFloat>
RgbImageFloat; typedef Image<unsigned char> BwImage; typedef Image<float>
BwImageFloat;   // Single channel byte image : IplImage*
img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1); BwImage imgA(img);
imgA[i][j] = 111;   // Multi channel byte image : IplImage*
img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3); RgbImage imgA(img);
imgA[i][j].b = 111; imgA[i][j].g = 111; imgA[i][j].r = 111;   // Multi channel floating point image :
IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3); RgbImageFloat
imgA(img); imgA[i][j].b = 111; imgA[i][j].g = 111; imgA[i][j].r = 111;

In essence ,IplImage It's a CvMat object , but CvMat Medium data and IplImage Medium imageData There is a difference ,imageData The pointer is a byte type pointer , So the data that points to is uchar Type . therefore , When pointer operation is performed on the image , You can simply add widthStep.

Here's another variable ROI
( Areas of interest ) The story of , It's actually a IPL/IPP structure IplROI An example of .IplROI contain xOffset,yOffset,height,width and coi( Channels of interest ) Member variable .

ROI The idea is : Once set ROI, Usually, the function that acts on the whole image will only ROI The sub image represented by is operated . provided that IplImage Variable set ROI, Then all OpenCV The function will use the ROI variable .

ROI It plays an important role in practical work , In many cases , It can improve the execution speed of computer vision code . If you want to set ROI, Using functions cvSetImageROI(), And pass it a
     Image pointer and rectangle . cancel ROI, You just need to be a function cvResetImageROI(), Pass an image pointer .

and CvMat It needs to be understood in detail in another article .

The revolution has not yet succeeded , Comrades still need to work hard .

Technology