有人能告诉我为什么EMGU在尝试写出灰度图像时会抛出异常吗?这是我的工作:
gCam.StartAcquisition(); 的Debug.WriteLine( “记录...”);
//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);
}
当我使用MONO8和Image时我没有问题,但如果我尝试去16位,我会得到这个例外:
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
这让我发疯,因为我不明白为什么我不能写出16位图像。我希望VideoWriter能让我的生活变得更轻松,但这只会让事情复杂化。我几乎觉得自己刚刚写出了原始字节!
答案 0 :(得分:1)
我想我可能找到了答案。 Image.cs的第2669行(EMGU源代码)说明了这一点:
/*
//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);
}*/
不支持!我希望例外说这个!