Convert WriteableBitmap to Bitmap for use in EmguCV

In my code, I get WriteableBitmaps from an array of bytes (in turn, from Kinect), and I would like to turn them into bitmaps for use with EmguCV. This is currently the code that I have:

// 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)); 

I got the bottom half of the code here . The compilation of the code is all, but it freezes when I try to run the program (it needs to perform some operations with the image, and then convert it to a format that can be represented as an image.) By pausing my code and then using IntelliTrace in VS 2013, I I get the following exception when Image<Gray, Byte> img = new Image<Gray, Byte>(b); "Fixed System.ArgumentException: URI format is not supported." Using alternative code, from where I go directly from bytes to a bitmap, gives me the same error. ( The code can be found here. )

Has anyone got any tips on how to resolve this error, or alternative ways to cast to bitmaps? I am new to C # and EmguCV, and I would really appreciate it.

+7
c # bitmap kinect emgucv writeablebitmap
source share
2 answers

Turns off all code in order. I'm not too sure about the technical details of the error, but the error was received while trying to write a Gray16 image to WriteableBitmap (which should be converted to an Emgu image). Bgr565 or other formats are supported, and I believe Gray16 was not fully implemented by MS. If the application is WinForms, Format16bppGray will also give the same error.

I decided to use the Gray Emgu image when recording Bitmap as Bgr555, which is much more noisy, but better than nothing.

0
source share

I had the same problem. An exception with URI formats is not supported, it has nothing to do with a raster image, but with loading the required opensv libraries. I just copied the x86 and x64 folders, including opencv_core290.dll and others, into my executable directory.

0
source share

All Articles