Mat,Iplimage,vector,vector_vector_Point2f等类型之间的相互转换

在mfc c++ 以及opencv 编写程序当中,很多常用的类型转换,现在总结一下。(注意加相应的头文件,这里不罗嗦)

提纲:

1. Mat ---> Iplimage

2. Iplimage  --->  CvvImage

3. Mat  ---> vector or vector

4. vector or vector  --->  vector> or vector>

5. vector> or vector>  ---> Mat

6. vector or vector  --->  Mat

 

图像类

1. Mat ---> Iplimage :直接赋值 


   
   
   
   
  1. Mat img;
  2. Iplimage myImg = img;


2. Iplimage  --->  CvvImage :用“Copyof ”


   
   
   
   
  1. CvvImage cImg;
  2. Iplimage myimg;
  3. cImg.Copyof(myimg, -1);


数据类

3. Mat  ---> vector or vector :用“Mat_“ ,“Mat_


   
   
   
   
  1. Mat m;
  2. vector p;
  3. p = Mat_(m);


4. vector or vector  --->  vector> or vector> :用“pushback”


   
   
   
   
  1. vector p1,p2,p3;
  2. vector< vector> pp;
  3. pp.pushback(p1);
  4. pp.pushback(p2);
  5. pp.pushback(p3);


5. vector> or vector>  ---> Mat


   
   
   
   
  1. vector< vector> p;
  2. Mat pm((int)p.size(), p[0].size(), CV_32FC3);
  3. for( int i = 0; i < ( int)p.size(); i++ )
  4. {
  5. Mat r = pm.row(i).reshape( 3, pm.cols);
  6. Mat pm1(p[i]);
  7. pm1.copyTo(r);
  8. }


6. vector or vector  --->  Mat :用“Mat(Point3f)"


   
   
   
   
  1. vector p;
  2. Mat m = Mat(p);
[转](https://blog.csdn.net/foreverhehe716/article/details/6749175)

你可能感兴趣的:(opencv,C++)