谁能告诉我为什么 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 能让我的生活更轻松,但它只是让事情变得复杂。在这一点上,我几乎想自己写出原始字节!