Opencv2.X以上Mat類型與IplImage*的轉換

來源:互聯網
上載者:User

       在Opencv2.X以上的處理中,大部分處理都是以Mat為主,而對於習慣了1.X的童鞋來說,有時候會帶來不便,希望能採用1.X的形式來處理。經過實驗,介紹一種簡單的Mat與IplImage*類型間的轉換:

範例程式碼是需要mat轉換為img:

      Mat mat,mat1; // mat1是臨時變數

      IplImage * img;

      mat1=mat.clone();// 包括資料的深度複製,以防對mat資料的更改

      img=cvCreateImage(cvSize(mat.cols,mat.rows),8,3); //根據實際進行初始化

      img.imageData=(char*)mat1.data;

如此,Img就擁有了與mat一樣的資料,在需要IplImage*類型的資料時,使用img

 

另外還有一種方式,沒經過實驗,放在下面:

   IplImage *frame;

   Mat frmImg;

   frame=&IplImage(frmImg);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.