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())
{
if (_forgroundDetector == null)
{
_forgroundDetector = new FGDetector<Bgr>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
}
_forgroundDetector.Update(image);
imageBox1.Image = image;
_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
using (Image<Bgr, Byte> image = _capture.RetrieveBgrFrame())
using (MemStorage storage = new MemStorage())
{
if (_forgroundDetector == null)
{
_forgroundDetector = new FGDetector<Bgr>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
}
_forgroundDetector.Update(image);
capturedImageBox.Image = image;
_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[
^]