【问题标题】:EMGU crashes when trying to write out greyscale image to VideoWriterEMGU 在尝试将灰度图像写入 VideoWriter 时崩溃
【发布时间】:2013-08-13 09:10:04
【问题描述】:

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

【问题讨论】:

    标签: opencv video-capture emgucv opencvdotnet


    【解决方案1】:

    我想我可能已经找到了答案。 Image.cs(EMGU 源代码)的第 2669 行是这样说的:

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

    不支持!我希望例外是这样说的!

    【讨论】:

      猜你喜欢
      • 2013-06-25
      • 2012-11-18
      • 2018-05-21
      • 1970-01-01
      • 1970-01-01
      • 2013-12-13
      • 2014-09-12
      • 1970-01-01
      相关资源
      最近更新 更多