2016-10-29 73 views
0

我需要的是Emgu.Cv.Mat。由於我有一個Bitmap我想將他的信息傳遞給這個Mat實例。當使用EmguCV構造Mat時System.AccessViolationException異常

這裏是我的代碼:

//the real file is not stored on the harddrive. this is for demonstration only. 
Bitmap fileBmp = new Bitmap(@"C:\Users\my\Desktop\file1.PNG"); 

//generating an Image from it works pretty fine as well. Even displaying it works great. 
Image<Bgr, Byte> image = new Image<Bgr, Byte>(fileBmp); 

//But I'm not able to generate a Mat with it. Not using the Bitmap 
Mat mat1 = new Mat(new int[] { fileBmp.Width, fileBmp.Height }, DepthType.Cv8S, fileBmp.GetHbitmap()); 

//... and not using the Image 
Mat mat2 = new Mat(new int[] { fileBmp.Width, fileBmp.Height }, DepthType.Cv8S, image.Bitmap.GetHbitmap()); 

我不斷收到

System.AccessViolationException

如果我讀要麼mat1.Bitmap財產或財產mat2.Bitmap(所有其他屬性看起來很不錯)。 error我的代碼有什麼問題?

任何建議如何使用EmguCv將「圖形信息」傳遞給Mat

再一次:使用new Mat(@"C:\Users\my\Desktop\file1.PNG")是不可能的,因爲位圖沒有存儲在硬盤上。

回答

2
Image<Bgr, Byte> image = new Image<Bgr, Byte>(fileBmp); 
Mat mat1 = image.Mat; 
0

還檢查以確保您正在編譯爲X64的,如果您正在使用EmguCV 3.1

相關問題