Why is EmguCV throwing this StackOverFlowException when capturing?

时间:2015-07-28 17:06:17

标签: c# exception dll emgucv capture

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;

namespace WebcamTest
{
    public partial class Form1 : Form
    {

        private Capture c;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            c = new Capture();
            c.ImageGrabbed += ProcessFrame;
            c.Start();

        }

        public void ProcessFrame(object sender, EventArgs e)
        {

            Image<Bgr, byte> image = c.QueryFrame();

            c.ImageGrabbed -= ProcessFrame;
            c.Stop();
            c.Dispose();

        }

    }
}

So I have this really simple code to grab a webcam image and store it, just one time. It does nothing else currently, but I'm having a weird issue. In my file, one line seems to cause the issue:

Image<Bgr, byte> image = c.QueryFrame();

EDIT: I have tried changing this line to this as the wiki suggests:

Image<Bgr, byte> image = new Image<Bgr, byte>(c.RetreiveBgrFrame().ToBitmap());

This one always gives a null reference exception the first time; afterwards it acts the same as the other line. Every pixel's combined values are 0's after the first run.

Then I go a bit deeper into the problem, I found that I keep getting a StackOverflowException in the Emgu.CV.dll itself. It continously says it is line 240 in this file: Capture.cs

The line is this:

bool grabbed = CvInvoke.cvGrabFrame(_ptr);

I have ran through their examples before and actually had them working before. I have never really had this issue before since it's coming from inside their dll. Why would this line keep causing this error? Is the pointer way off point for some unknown reason? The only thing I could think was that it was trying to access a memory location outside the actual bounds. It's always the very first run it does this. Then when it crashes, the camera stays on and so next time it runs. Though the image pixels are all 0's every time after that.

0 个答案:

没有答案