Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


C#
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++;

      }



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

C#
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;


here is the output image when i use webcam
https://www.dropbox.com/s/k04b0ng8ez0zmvr/emgucv.jpg[^]
Posted
Updated 23-Jun-13 18:08pm
v3
Comments
ArunRajendra 24-Jun-13 0:12am    
Looking at exception seems to be issue with mommory allocation.

1 solution

The error is exactly what it says, you are trying to load an image that is 562-ish MB, which the framework can't load. What is the size of your images in the frames folder?

[Edit]

On second look, looks like you are creating a new Foreground Detector on each tick, which you should not do. Create it once as a member of your class and update it with each frame. Its probably holding references to each one you create, and after it hits a certain point, it can't allocate any more memory.
 
Share this answer
 
v2
Comments
vishnulalr 24-Jun-13 0:18am    
its of 47 kb to 74 kb size please help me can show an example for this . im beginner in this field

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900