Can anyone tell me why EMGU throws an exception when trying to write out a greyscale image? Here is what I do:
gCam.StartAcquisition(); Debug.WriteLine("recording...");
//Bitmap safeImage = new Bitmap(xiImageWidth, xiImageHeight,
//System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
Bitmap safeImage = new Bitmap(xiImageWidth, xiImageHeight,
System.Drawing.Imaging.PixelFormat.Format16bppGrayScale );
//Emgu.CV.Image<Gray, Byte> currentFrame;
Emgu.CV.Image<Gray, UInt16> currentFrame;
gCam.GetImage(safeImage, XI_CAPTURE_TIMEOUT);
//currentFrame = new Image<Gray, Byte>(safeImage);
currentFrame = new Image<Gray, UInt16>(safeImage);
currentFrame.Save("testImage.bmp");
startTime = DateTime.Now;
if (emguVideoWriter.Ptr != IntPtr.Zero)
{
emguVideoWriter.WriteFrame(currentFrame);
}
When I use MONO8 and Image I have no problem, but if I try to go 16-bit I get this exception:
A first chance exception of type 'System.ArgumentException' occurred in System.Drawing.dll
exception caught while recording a frame! ex=System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap.GetPixel(Int32 x, Int32 y)
at Emgu.CV.Image`2.set_Bitmap(Bitmap value) in C:\Emgu\emgucv-windows-x64 2.4.0.1717\Emgu.CV\Image.cs:line 2866
at Emgu.CV.Image`2..ctor(Bitmap bmp) in C:\Emgu\emgucv-windows-x64 2.4.0.1717\Emgu.CV\Image.cs:line 213
This has been driving me crazy as I don't see why I cannot write out 16-bit images. I was hoping VideoWriter would make my life easier but instead it is just complicating matters. I almost feel like just writing out the raw bytes myself at this point!
I think I may have found the answer. Line 2669 of Image.cs (EMGU source code) says this:
/*
//PixelFormat.Format16bppGrayScale is not supported in .NET
else if (typeof(TColor) == typeof(Gray) && typeof(TDepth) == typeof(UInt16))
{
return new Bitmap(
size.width,
size.height,
step,
PixelFormat.Format16bppGrayScale;
scan0);
}*/
Not supported! I wish the exception said this!