(轉)Mat, vector ,Iplimage等等常見類型轉換


原文連接:http://blog.csdn.net/foreverhehe716/article/details/6749175

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

Mat img;  
Iplimage myImg = img;  

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

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

數據類

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

Mat m;  
vector<Point3f> p;  
p = Mat_<Point3f>(m);  

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

vector<Point3f> p1,p2,p3;
vector<vector<Point3f>> pp;
pp.pushback(p1);
pp.pushback(p2);
pp.pushback(p3);

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

vector<vector<Point3f>> p;
Mat pm((int)p.size(), p[0].size(), CV_32FC3);

for( int i = 0; i < (int)p.size(); i++ )
{
    Mat r = pm.row(i).reshape(3, pm.cols);
    Mat pm1(p[i]);
    pm1.copyTo(r);
}

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

vector<Point3f> p;
Mat m = Mat(p);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM