[英]Converting WriteableBitmap to Bitmap for use in EmguCV
在我的代碼中,我從字節數組(依次從Kinect)接收WriteableBitmaps,我想把它們變成用於EmguCV的位圖。 目前這是我的代碼:
// Copy the pixel data from the image to a temporary array
colorFrame.CopyPixelDataTo(this.colorPixels);
// Write the pixel data into our bitmap
this.colorBitmap.WritePixels(
new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
this.colorPixels,
this.colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
0);
BitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(colorBitmap));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
Bitmap b=new Bitmap(ms);
Image<Gray, Byte> img = new Image<Gray, Byte>(b);
img = img.ThresholdBinary(new Gray(200), new Gray(255));
我從這里得到了代碼的下半部分。代碼編譯和所有內容,但是在我嘗試運行程序時掛起(它應該對圖像執行一些操作然后將其轉換回可以呈現的格式作為一個圖像。)暫停我的代碼,然后在VS 2013中使用IntelliTrace,我在Image<Gray, Byte> img = new Image<Gray, Byte>(b);
“拋出了System.ArgumentException:不支持URI格式。” 使用替代代碼,從我直接從字節到位圖的位置給出了同樣的錯誤。 ( 代碼可以在這里找到。 )
任何人都有關於如何解決此錯誤或其他方法轉換為位圖的提示? 我是C#和EmguCV的新手,我非常感激。
結果證明所有代碼都沒問題。 我對錯誤的技術細節不太確定,但是當嘗試在WriteableBitmap中編寫Gray16圖像時會收到錯誤(將被轉換為Emgu圖像。)支持Bgr565或其他格式,我相信Gray沒有完全實現Gray16。 如果執行WinForms應用程序,Format16bppGray也會給出相同的錯誤。
我決定使用Grey Emgu圖像,同時將Bitmap寫為Bgr555,這是一個更嘈雜,但總比沒有好。
我遇到過同樣的問題。 “不支持URI格式”的例外與位圖無關,但需要加載opencv dll。 我剛剛將x86和x64文件夾(包括opencv_core290.dll和其他文件夾)復制到我的可執行文件目錄中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.