C++ 如何从 cv::Mat 转换为 CvArr?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10269742/
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
how to convert from cv::Mat to CvArr?
提问by chostDevil
i have passed a lot of time searching on how to convert from cv::Mat or CvMat to CvArr but with no gain ,please help me in that,thanks.
我已经花了很多时间搜索如何从 cv::Mat 或 CvMat 转换为 CvArr 但没有任何收获,请帮助我,谢谢。
回答by Clement Roblot
When I need to do that I just use :
当我需要这样做时,我只使用:
IplImage tmp = image;
With image a Mat variable.
使用图像 Mat 变量。
回答by Vivek Mahto
Mat img = imread("C:\MyPic.jpg",CV_LOAD_IMAGE_GRAYSCALE);
IplImage tmp=img;
cvErode(&tmp, &tmp, 0, 2);
Mat laser=&tmp;
imshow("Eroded",laser);
I converted cv::Mat
to CvArr
by this way. Instead of using tmp
directly use &tmp
.
我cv::Mat
就是CvArr
通过这种方式转换的。而不是tmp
直接使用使用&tmp
。
回答by lezebulon
If I recall correctly, CvMat IS a CvArr so you can just cast it into a CvArr, and the first bytes of the now CvArr tell the function that it is actually a CvMat: http://opencv.willowgarage.com/documentation/basic_structures.html#cvarr
如果我没记错的话,CvMat 是一个 CvArr,所以你可以把它转换成一个 CvArr,现在 CvArr 的第一个字节告诉函数它实际上是一个 CvMat:http://opencv.willowgarage.com/documentation/basic_structures .html#cvarr
回答by icl7126
Are you sure you want to convert it? sometimes there is equivalent function that use what you have. For example cvMorphologyEx
is using CvArr
but morphologyEx
is using cv::Mat
.
确定要转换吗?有时有等效的功能使用您拥有的功能。例如cvMorphologyEx
正在使用CvArr
但morphologyEx
正在使用cv::Mat
.
回答by jamk
convert first the image using the following:
首先使用以下方法转换图像:
IplImage* oldstyleimg = &matimg.operator IplImage()
I don t remember if it only create the header for the image or it makes a copy
我不记得它是只为图像创建标题还是复制