IplImage简介
IplImage簡介
結構定義:
typedef struct _IplImage {int nSize; /* sizeof(IplImage) */int ID; /* version (=0)*/int nChannels; /* Most of OpenCV functions support 1,2,3 or 4 channels */int alphaChannel; /* Ignored by OpenCV */int depth; /* Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */char colorModel[4]; /* Ignored by OpenCV */char channelSeq[4]; /* ditto */int dataOrder; /* 0 - interleaved color channels, 1 - separate color channels.cvCreateImage can only create interleaved images */int origin; /* 0 - top-left origin,1 - bottom-left origin (Windows bitmaps style). */int align; /* Alignment of image rows (4 or 8).OpenCV ignores it and uses widthStep instead. */int width; /* Image width in pixels. */int height; /* Image height in pixels. */struct _IplROI *roi; /* Image ROI. If NULL, the whole image is selected. */struct _IplImage *maskROI; /* Must be NULL. */void *imageId; /* " " */struct _IplTileInfo *tileInfo; /* " " */int imageSize; /* Image data size in bytes(==image->height*image->widthStepin case of interleaved data)*/char *imageData; /* Pointer to aligned image data. */int widthStep; /* Size of aligned image row in bytes. */int BorderMode[4]; /* Ignored by OpenCV. */int BorderConst[4]; /* Ditto. */char *imageDataOrigin; /* Pointer to very origin of image data(not necessarily aligned) -needed for correct deallocation */ } IplImage;
The IplImage is taken from the Intel Image Processing Library, in which the format is native. OpenCV only supports a subset of possibleIplImage formats, as outlined in the parameter list above.
In addition to the above restrictions, OpenCV handles ROIs differently. OpenCV functions require that the image size or ROI size of all source and destination images match exactly. On the other hand, the Intel Image Processing Library processes the area of intersection between the source and destination images (or ROIs), allowing them to vary independently.
Member Function Documentation
| inline |
| IplImage::_IplImage | ( | const cv::Mat &? | m | ) | ? |
Member Data Documentation
| int IplImage::align |
Alignment of image rows (4 or 8). OpenCV ignores it and uses widthStep instead.
| int IplImage::alphaChannel |
Ignored by OpenCV
| int IplImage::BorderConst[4] |
Ditto.
| int IplImage::BorderMode[4] |
Ignored by OpenCV.
| char IplImage::channelSeq[4] |
ditto
| char IplImage::colorModel[4] |
Ignored by OpenCV
| int IplImage::dataOrder |
0 - interleaved color channels, 1 - separate color channels. cvCreateImage can only create interleaved images
| int IplImage::depth |
Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported.
| int IplImage::height |
Image height in pixels.
| int IplImage::ID |
version (=0)
| char* IplImage::imageData |
Pointer to aligned image data.
| char* IplImage::imageDataOrigin |
Pointer to very origin of image data (not necessarily aligned) - needed for correct deallocation
| void* IplImage::imageId |
" "
| int IplImage::imageSize |
Image data size in bytes (==image->height*image->widthStep in case of interleaved data)
| struct _IplImage* IplImage::maskROI |
Must be NULL.
| int IplImage::nChannels |
Most of OpenCV functions support 1,2,3 or 4 channels
| int IplImage::nSize |
sizeof(IplImage)
| int IplImage::origin |
0 - top-left origin, 1 - bottom-left origin (Windows bitmaps style).
| struct _IplROI* IplImage::roi |
Image ROI. If NULL, the whole image is selected.
| struct _IplTileInfo* IplImage::tileInfo |
" "
| int IplImage::width |
Image width in pixels.
| int IplImage::widthStep |
Size of aligned image row in bytes.
數據的訪問存取
下面看一個圖像數據存取的例子:
例子轉自:http://blog.csdn.net/to_utopia/article/details/4856171
1.直接存取: (效率高, 但容易出錯)
- 對單通道字節(jié)圖像: IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1); ((uchar *)(img->imageData + i*img->widthStep))[j]=111;
- 對多通道字節(jié)圖像: 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
- 對多通道浮點圖像: 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
2.用指針直接存取 : (在某些情況下簡單高效)
- 對單通道字節(jié)圖像:
- 對多通道字節(jié)圖像:
- 對多通道浮點圖像(假設用4字節(jié)調整):
3.使用 c++ wrapper 進行直接存取: (簡單高效)
?
- 對單/多通道字節(jié)圖像,多通道浮點圖像定義一個?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;
?
- 單通道字節(jié)圖像: IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,1);
BwImage imgA(img);
imgA[i][j] = 111;
?
- 多通道字節(jié)圖像: 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;
?
- 多通道浮點圖像: 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;
其他示例:
直接訪問:
對我們來說比較重要的兩個元素是:char *imageData以及widthStep。imageData存放圖像像素數據,而widStep類似CvMat中的step,表示以字節(jié)為單位的行數據長度。
一個m*n的單通道字節(jié)型圖像,其imageData排列如下:
如果我們要遍歷圖像中的元素,只需:
[cpp] view plaincopy這種直接訪問的方法速度快,但容易出錯,我們可以通過定義指針來訪問。即:
[cpp] view plaincopy而多通道(三通道)字節(jié)圖像中,imageData排列如下:
其中(Bi,Bj)(Gi,Gj)(Ri,Rj)表示圖像(i,j)處BGR分量的值。使用指針的遍歷方法如下:
[cpp] view plaincopy*如果要修改某像素值,則直接賦值。
使用cvGet2D()函數訪問:
cvGet*D系列函數可以用來返回特定位置的數組元素(一般使用cvGet2D),原型如下: [cpp] view plaincopy因此,單通道圖像像素訪問方式如下: [cpp] view plaincopy
參考文檔
http://blog.csdn.net/xiaowei_cqu/article/details/7557063#
總結
以上是生活随笔為你收集整理的IplImage简介的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OpenCV 3.x Lib 源码结构简
- 下一篇: OpenCV Mat 简介