如何在OpenCV 2.0中将Mat变量类型转换为IplImage变量类型?
我正在尝试在 OpenCV 中旋转图像。
我使用了在 Stack Overflow 上找到的这段代码:
Mat source(img);
Point2f src_center(source.cols/2.0, source.rows/2.0);
Mat rot_mat = getRotationMatrix2D(src_center, 40.0, 1.0);
Mat dst;
warpAffine(source, dst, rot_mat, source.size());
一旦我填满了 dst
Mat
变量类型,我想将其放回 IplImage
变量类型,知道如何做到这一点吗?
I am trying to rotate an image in OpenCV.
I've used this code that I found here on Stack Overflow:
Mat source(img);
Point2f src_center(source.cols/2.0, source.rows/2.0);
Mat rot_mat = getRotationMatrix2D(src_center, 40.0, 1.0);
Mat dst;
warpAffine(source, dst, rot_mat, source.size());
Once I have my dst
Mat
variable type filled up I would like to put it back to an IplImage
variable type, any idea about how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在新的 OpenCV 2.0 C++ 接口中,实际上没有必要在
Mat
和IplImage
之间来回更改,但如果您愿意,可以使用IplImage< /code> 运算符:
请注意,仅创建 IplImage 标头并且将共享数据(像素)。有关详细信息,请参阅 OpenCV C++ 接口 或
图片
示例。OpenCV-2.0/samples/c
目录中的 .cppIn the new OpenCV 2.0 C++ interface it's not really necessary to change from back and forth between
Mat
andIplImage
, but if you want to you can use theIplImage
operator:Note that only the IplImage header is created and the data (pixels) will be shared. For more info see the OpenCV C++ interface or the
image.cpp
example in theOpenCV-2.0/samples/c
directory.为了拥有整个
IplImage
对象,我使用了以下代码:您还可以复制数据而不是指针:
For having the whole
IplImage
object, I've used this code:You can also copy the data instead of pointer:
Norman 在他的博客中描述了以下内容(虽然它不是 2.0,但它应该适用于您的问题。):
要从 CvMat 转换为 IplImage,请使用函数:
函数 cvGetImage 返回输入数组的图像头,该输入数组可以是矩阵 - CvMat* 或图像 - IplImage*。
对于图像,该函数仅返回输入指针。
在 CvMat* 的情况下,它使用输入矩阵的参数初始化 image_header 结构。
用法:
Norman in his blog describes the following (Although it is not 2.0, it should apply to your problem.):
To transform from CvMat to IplImage, Use function:
The function cvGetImage returns image header for the input array that can be matrix - CvMat*, or image - IplImage*.
In the case of image the function simply returns the input pointer.
In the case of CvMat* it initializes image_header structure with parameters of the input matrix.
Usage:
在OpenCV 2.4及以上版本中,我们可以简单地通过以下方式转换它
In later versions of OpenCV 2.4 and above, we can convert it simply by