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

32 篇文章 7 订阅

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

提纲:

1. Mat ---> Iplimage

2. Iplimage  --->  CvvImage

3. Mat  ---> vector<Point2f> or vector<Point3f>

4. vector<Point2f> or vector<Point3f>  --->  vector<vector<Point2f>> or vector<vector<Point3f>>

5. vector<vector<Point2f>> or vector<vector<Point3f>>  ---> Mat

6. vector<Point2f> or vector<Point3f>  --->  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<Point2f> or vector<Point3f> :用“Mat_<Point2f>“ ,“Mat_<Point3f>”


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


4. vector<Point2f> or vector<Point3f>  --->  vector<vector<Point2f>> or vector<vector<Point3f>> :用“pushback”


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


5. vector<vector<Point2f>> or vector<vector<Point3f>>  ---> Mat


 
 
  1. vector< vector<Point3f>> 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<Point2f> or vector<Point3f>  --->  Mat :用“Mat(Point3f)"


 
 
  1. vector<Point3f> p;
  2. Mat m = Mat(p);
[转](https://blog.csdn.net/foreverhehe716/article/details/6749175)
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值