請問如何將c#的Bitmap或Image物件轉換為Emgu.cv.mat型別,謝謝!(QQ:18700104)
uj5u.com熱心網友回復:
//將資源視圖轉換為emgu.cn.Mat型別Image img = Properties.Resources.Form3_PIC_00; //只能是system.drawing.image能讀入,Mat和emgu的image讀不了
Bitmap bmpImage = new Bitmap(img); //這是關鍵,國外網站看到的
Emgu.CV.Image<Bgr, Byte> currentFrame = new Emgu.CV.Image<Bgr, Byte>(bmpImage); //只能這么轉
Mat invert = new Mat();
CvInvoke.BitwiseAnd(currentFrame, currentFrame, invert); //這是官網上的方法,變通用。沒看到提供其它方法直接轉換的。
這段代碼會讓許多人受益的,國外網站也查到這種轉換。呵呵。打通了emgu.cv.image向emgu.cn.mat的轉換,mat轉image的倒是很常見。
3.0推出了Mat,已經不推薦image類了。但是,一些時候,還需要從c#的型別向Mat上轉,如上面的C例子,必須通過BitMap轉換一下。
uj5u.com熱心網友回復:
CvInvoke.BitwiseAnd(currentFrame, currentFrame, invert); //這是官網上的方法,變通用。沒看到提供其它方法直接轉換的。發現了其屬性里的一個用法。Mat Get the Mat header that represent this CvArr
(Inherited from CvArray<TDepth>.) 。
invert=currentFrame,Mat。效率應該更高一些,直接將記憶體里的結構的頭部變換一下即可。
uj5u.com熱心網友回復:
Bitmap轉不了啊uj5u.com熱心網友回復:
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/36405.html
標籤:C#
