本文介绍了请帮我纠正下面的c#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我的目标是使用emgucv从文件夹中读取图像并检测其前景,但下面的代码不会显示任何事情给出异常





Here my aim to to use emgucv for reading images from a folder and detect its foreground but the below code will not show any thing give an exception


private void timer1_Tick(object sender, EventArgs e)
      {

          if (File.Exists(Application.StartupPath + "\\frames\\" + i + ".jpg"))
          {

              using (Image<Bgr, Byte> image = new Image<Bgr, byte>(Application.StartupPath + "\\frames\\" + i + ".jpg"))

              using (MemStorage storage = new MemStorage()) //create storage for motion components
              {
                  if (_forgroundDetector == null)
                  {
                      //_forgroundDetector = new BGCodeBookModel<Bgr>();
                      _forgroundDetector = new FGDetector<Bgr>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
                      //_forgroundDetector = new BGStatModel<Bgr>(image, Emgu.CV.CvEnum.BG_STAT_TYPE.FGD_STAT_MODEL);
                  }

                  _forgroundDetector.Update(image);

                 imageBox1.Image = image;

                  //update the motion history
                  _motionHistory.Update(_forgroundDetector.ForegroundMask);

                  imageBox2.Image = _forgroundDetector.ForegroundMask;

              }

              }

          i++;

      }







查看此消息的结尾有关调用

实时(JIT)调试而非此对话框的详细信息。



******* *******异常文本**************

Emgu.CV.Util.CvException:OpenCV:无法分配589824000字节
$ C $ b at Emgu.CV.CvInvoke.CvErrorHandler(Int32 status,String funcName,String errMsg,String fileName,Int32 line,IntPtr userData)in C:\ Emgu\emgucv-windows-universal-gpu 2.4.9.1847 \\ \\ emgu.CV \PInvoke \CvInvokeCore.cs:第132行

在Emgu.CV.CvInvoke.CvFGDetectorProcess(IntPtr探测器,IntPtr图像)

在Emgu.CV .VideoSurveillance.FGDetector`1.Update(图像`2图像)在C:\ Emgu \emgucv-windows-universal-gpu 2.4.9.1847 \Emgu.CV \ VideoSurveillance\FGDetector.cs:第65行

at testlucasimagebox.Form1.timer1_Tick(Object sender,EventArgs e)

在System.Windows.Forms。在System.Windows.Forms.Timer.TimerNativeWindow.WndProc上的Timer.OnTick(EventArgs e)

(消息& m)

在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)





但是当我使用网络摄像头的图像时,下面的代码工作正常






See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
Emgu.CV.Util.CvException: OpenCV: Failed to allocate 589824000 bytes
at Emgu.CV.CvInvoke.CvErrorHandler(Int32 status, String funcName, String errMsg, String fileName, Int32 line, IntPtr userData) in C:\Emgu\emgucv-windows-universal-gpu 2.4.9.1847\Emgu.CV\PInvoke\CvInvokeCore.cs:line 132
at Emgu.CV.CvInvoke.CvFGDetectorProcess(IntPtr detector, IntPtr image)
at Emgu.CV.VideoSurveillance.FGDetector`1.Update(Image`2 image) in C:\Emgu\emgucv-windows-universal-gpu 2.4.9.1847\Emgu.CV\VideoSurveillance\FGDetector.cs:line 65
at testlucasimagebox.Form1.timer1_Tick(Object sender, EventArgs e)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


but when i use images from a webcam the below code works fine

using (Image<Bgr, Byte> image = _capture.RetrieveBgrFrame())
          using (MemStorage storage = new MemStorage()) //create storage for motion components
          {
              if (_forgroundDetector == null)
              {
                  //_forgroundDetector = new BGCodeBookModel<Bgr>();
                  _forgroundDetector = new FGDetector<Bgr>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
                  //_forgroundDetector = new BGStatModel<Bgr>(image, Emgu.CV.CvEnum.BG_STAT_TYPE.FGD_STAT_MODEL);
              }

              _forgroundDetector.Update(image);

              capturedImageBox.Image = image;

              //update the motion history
              _motionHistory.Update(_forgroundDetector.ForegroundMask);

              forgroundImageBox.Image = _forgroundDetector.ForegroundMask;





这里是我使用网络摄像头时的输出图像/>
]

推荐答案


这篇关于请帮我纠正下面的c#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 11:01