Mat, vector<point2f>,Iplimage等等常见类型转换

在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 :直接赋值 

[cpp]  view plain copy
  1. Mat img;  
  2. Iplimage myImg = img;  


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

[cpp]  view plain copy
  1. CvvImage cImg;  
  2. Iplimage myimg;  
  3. cImg.Copyof(myimg, -1);  


数据类

3. Mat  ---> vector<Point2f> or vector<Point3f> :用“Mat_<Point2f>“ ,“Mat_<Point3f>”

[cpp]  view plain copy
  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”

[cpp]  view plain copy
  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

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


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

[cpp]  view plain copy
  1. vector<Point3f> p;  
  2. Mat m = Mat(p);  
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值