C++ 从 IplImage* 到 cv::MAT 的转换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15925084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Conversion from IplImage* to cv::MAT
提问by Moeen MH
I searched to convert an IplImage* to Mat, but all answers were about the conversion to cvMat.
我搜索将 IplImage* 转换为 Mat,但所有答案都是关于转换为 cvMat。
How, can I do it? and what is the difference between Mat and cvMat?
我该怎么做?Mat 和 cvMat 有什么区别?
Thanks in advance
提前致谢
采纳答案by Houssem Badri
here is a good solution
这是一个很好的解决方案
Mat(const IplImage* img, bool copyData=false);
回答by Moeen MH
For the records: taking a look at core/src/matrix.cpp it seems that, indeed, the constructor cv::Mat(IplImage*)
has disappeared.
作为记录:查看 core/src/matrix.cpp 似乎确实,构造函数cv::Mat(IplImage*)
已经消失了。
But I found this alternative:
但我找到了这个替代方案:
IplImage * ipl = ...;
cv::Mat m = cv::cvarrToMat(ipl); // default additional arguments: don't copy data.
回答by Andrey Kamaev
The recommended way is the cv::cvarrToMat
function
推荐的方式是cv::cvarrToMat
函数
cv::Mat
- is base data structure for OpenCV 2.x
cv::Mat
- 是 OpenCV 2.x 的基本数据结构
CvMat
- is old C analog of cv::Mat
CvMat
- 是旧的 C 模拟 cv::Mat
回答by Safir
Check out the Mat documentation.
查看Mat 文档。
// converts old-style IplImage to the new matrix; the data is not copied by default
Mat(const IplImage* img, bool copyData=false);
回答by Abc
cv::Mat or Mat, both are same.
Mat has a operator CvMat() so simple assignment works
cv::Mat 或 Mat,两者都是一样的。
Mat 有一个运算符 CvMat() 所以简单的赋值工作
Convert Mat to CvMat
将 Mat 转换为 CvMat
Mat mat = ---------;
CvMat cvmat = mat;
Convert CVMat to Mat
将 CVMat 转换为 Mat
Mat dst = Mat(cvmat, true);
Convert Mat to IplImage*
将 Mat 转换为 IplImage*
> For Single Channel
> 单通道
IplImage* image = cvCloneImage(&(IplImage)mat);
> For Three Channel
> 三通道
IplImage* image = cvCreateImage(cvSize(mat.cols, mat.rows), 8, 3);
IplImage ipltemp = mat;
cvCopy(&ipltemp, image);
Hope this helps you. Cheers :)
希望这对你有帮助。干杯:)