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

來源:互聯網
上載者:User

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

[cpp] view
plaincopy

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

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

[cpp] view
plaincopy

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


資料類

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

[cpp] view
plaincopy

  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
plaincopy

  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
plaincopy

  1. vector<vector<Point3f>> p;  
  2. Mat pm((int)p.size(), p[0].size(), CV_32FC3);  
  3.   
  4. for( int 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
plaincopy

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.