灰灰要坐冷板凳

关注机器学习,计算机视觉,深度学习

opencv (opencv3.X) IplImage相互转换mat

opencv3.x之前的版本,mat有构造函数 Mat(const IplImage* img, bool copyData=false);
IplImage转mat可以直接用由

extern  IplImage * plpliamge;//plpliamge已创建
 cv::Mat matImage( IplImage, 0  ): //第二个参数表示不进行像素数据copy;

实现IplImage转为mat

但是在opencv3.x中,Mat(const IplImage* img, bool copyData=false);构造函数取消了,所以只能另辟蹊径啦!下面是在3.x中可行办法:

1. IplImage to cv::Mat example program

 #include "opencv2/highgui/highgui.hpp"  
 #include <iostream>  
 #include <stdio.h>  
 using namespace std;  
 using namespace cv;  
 int main(int argc,  
    char *argv[]  
  )  
 {  
 ///Loading image to IplImage  
 IplImage *img=cvLoadImage(argv[1]);  
 cvShowImage("Ipl",img);  
 ///converting IplImage to cv::Mat  
 Mat image=cvarrToMat(img);  
 imshow("Mat",image);  
 waitKey();  
 return 0;  
 }  

2. cv::Mat to IplImage example program

 #include "opencv2/highgui/highgui.hpp"  
 #include <iostream>  
 #include <stdio.h>  
 using namespace std;  
 using namespace cv;  
 int main(int argc,  
  char *argv[]  
  )  
 {  
 ///Reading Image to cv::Mat  
 Mat image =imread(argv[1],1);  
 ///Converting Mat to IplImage  
 IplImage test = image;  
 ///showing image from mat  
 imshow("Mat",image);  
 ///showing image from IplImage  
 cvShowImage("Ipl",&test);  
 waitKey();  
 return 0;  
 }  
阅读更多
个人分类: opencv
上一篇C++中数据值为-1.#IND000000000000
下一篇typedef和#define的用法与区别
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭