从图中可以看出,利用IplImage* pImage=cvLoadImage(filename)来创建的IplImage型指针变量:pImage的地址是:0x017bfb60
需要注意的几个变量:
colorModel:内存中的地址是:0x17bfb74
通过IDE查看内存内容如下:
channelSeq(交叉存储RGB顺序相反):内存中的地址是:0x17bfb78
通过IDE查看内存内容如下:
imageSize:257232=276*932(=height(行数)*widthStep(列的字节数,不一定等于width))
注:widthStep的大小一般是等于width*nChannels,但是往往因为字节填充的问题,也不完全相等,例如本例子中,width=310,nChannels=3,932不等于310*3
origin:代表图像的实际元素在内存中的开始位置:0——左上角;1——左下角(BMP格式)
imageData:这个是图像的真实数据的存储地址。利用IDE工具查看如下:
注:内存的显示格式选择为:(一个字节,不带符号显示(十进制))
u Mat(C++ API)与IplImage:
实现二者转换的代码:
IplImage* pImage=cvLoadImage(filename);
Mat mMat(pImage);
里面几个重要的成员变量:(截图中使用十进制显示)
dims:表示矩阵的维度数(平面图像都是二维的,即行X列)
rows:对应于IplImage中的height
cols:对应于IplImage中的width
data – Pointer to the user data. Matrix constructors that take data and step parameters
do not allocate matrix data. Instead, they just initialize the matrix header that points to
the specified data, which means that no data is copied. This operation is very efficient and
can be used to process external data using OpenCV functions. The external data is not
automatically deallocated, so you should take care of it.
注意:这部分数据(225 105 69……)与IplImage中的imageData相同(225 105 69……)
step – Number of bytes each matrix row occupies. The value should include the padding(填充字节)
bytes at the end of each row, if any. If the parameter is missing (set to AUTO_STEP
), no padding is assumed and the actual step is calculated as cols*elemSize() . See
Mat::elemSize() .
steps – Array of ndims-1 steps in case of a multi-dimensional array (the last step is always
set to the element size). If not specified, the matrix is assumed to be continuous.
u CvMat(C API)与IplImage:
实现二者转换的代码:
CvMat mCvMatHeader;
CvMat* mCvMat=cvGetMat(pImage,&mCvMatHeader);
几个重要的成员变量:
data:
rows:
height:
cols:
width:
CvMat的结构跟CvMatHeader一样
注意:
这是cvGetMat的函数原型,它的作用就是提供方便的途径来同时处理IplImage和CvMat两种数据类型(还可以联系cvGetImage()函数)。
(C API) CvMat* cvGetMat(const CvArr* arr, CvMat* header, int* coi=NULL, int allowND=0)
Parameters
arr – Input array
header – Pointer to CvMat structure used as a temporary buffer
coi – Optional output parameter for storing COI
allowND – If non-zero, the function accepts multi-dimensional dense arrays (CvMatND*)
and returns 2D matrix (if CvMatND has two dimensions) or 1D matrix (when CvMatND
has 1 dimension or more than 2 dimensions). The CvMatND array must be continuous.
但是,如果我们这样来调用cvGetMat,
CvMat* mCvMat;
mCvMat=cvGetMat(pImage,mCvMat);出现错误。