Mat和IplImage相互转换

来源:互联网 发布:java招聘信息从哪找 编辑:程序博客网 时间:2024/06/03 21:30

Mat OpenCVC++的接口矩阵类,ImlImageOpenCVC语言的接口的结构体,但是C++程序有时候时候还是要用到ImlImage,例如在MFC中的Picture Control显示图片。

下面总结了针对OpenCV3.0以上版本的Mat和IplImage相互转换方法:

[cpp] view plain copy
  1. //IplImage—>Mat  
  2. //EXAMPLE:  
  3. //浅拷贝:  
  4. IplImage* pBinary=cvLoadImage("c://temp.jpg",0);  
  5. Mat Img;  
  6. Img=cvarrToMat(pBinary);  
  7. //深拷贝只需要再在Mat里创建一个新的Mat对象,然后进行数据的复制,再用上述的函数进行数据头的复制(浅拷贝):  
  8. IplImage* pBinary=cvLoadImage("c://temp.jpg", 0);  
  9. Mat ImgTemp;  
  10. Img=cvarrToMat(pBinary);  
  11. Mat Img = ImgTemp.clone();  
  12.   
  13.   
  14. //Mat—>IplImage  
  15. //EXAMPLE:  
  16. //浅拷贝:  
  17. Mat Img=imread("1.jpg");  
  18. IplImage* pBinary = &IplImage(Img);  
  19. //深拷贝只要再加一次复制数据:  
  20. IplImage *input = cvCloneImage(pBinary);  
附:http://blog.csdn.net/lijiayu2015/article/details/52438160