OpenCv学习之:利用vs2008的IDE工具对IplImage、Mat、CvMat结构进行解析解析

从图中可以看出,利用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=310nChannels=3932不等于310*3

origin:代表图像的实际元素在内存中的开始位置:0——左上角;1——左下角(BMP格式)

imageData这个是图像的真实数据的存储地址。利用IDE工具查看如下:

注:内存的显示格式选择为:(一个字节,不带符号显示(十进制))

u MatC++ 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 CvMatC API)与IplImage

实现二者转换的代码:

CvMat mCvMatHeader;

CvMat* mCvMat=cvGetMat(pImage,&mCvMatHeader);

几个重要的成员变量:

data

rows

height

cols

width

CvMat的结构跟CvMatHeader一样

注意:

这是cvGetMat的函数原型,它的作用就是提供方便的途径来同时处理IplImageCvMat两种数据类型(还可以联系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);出现错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zssure

己欲立而立人,己欲达而达人

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值