yoko
yoko

Reputation: 513

Can't allocate enough memory while importing video to project

I am writing a program with EmguCv and C# to detect some pattern from a video stream. At first I am trying to import the video into the project, but after a few seconds, the program freezes and doesn't load any further.

I really don't know, but I think that it might be because I do something wrong while importing the video, most of all because the program uses 2 GB of RAM after 14 seconds

enter image description here

To import the video and display it to the GUI, I am using this code:

private void timer1_Tick(object sender, EventArgs e) 
{
     Orginal.Image = _capture.QueryFrame();         
}

private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
    _capture = new Capture(openFileDialog1.FileName.ToString());
}

private void button2_Click(object sender, EventArgs e)//Import-Button
{
    openFileDialog1.ShowDialog();
    string _FilePath = openFileDialog1.FileName.ToString();
    textBox1.Text = _FilePath;
}

private void button1_Click(object sender, EventArgs e) //Start-Button
{
    My_Time.Interval = 1000 / FPS;
    My_Time.Tick += new EventHandler(timer1_Tick);
    My_Time.Start();
    _capture = new Capture(openFileDialog1.FileName.ToString());
}

Is this the right way to import a video, or is there a better way?

The exception with it thrown reads the following :

Emgu.CV.Util.CvException in Emgu.CV.dll("OpenCV: Failed to allocate 6220800 bytes")

Upvotes: 0

Views: 383

Answers (1)

Luca Del Tongo
Luca Del Tongo

Reputation: 2702

You are having a memory leak for each image you are grabbing with

Orginal.Image = _capture.QueryFrame(); 

I don't know your timer tick milliseconds but if you are getting a 6MB image every 25ms you get 150MB every seconds and in 14 seconds you get 2GB of memory allocations.

Just Download one of the classical examples to play/record video files and perform patter detection as per your needs. http://www.emgu.com/wiki/index.php/Video_Files

Upvotes: 1

Related Questions