Search code examples
c#image-processingemgucvframe-rate

How to increase frame rate of webcam's video input? Emgu CV


I'm using emgu CV & C# and getting low FPS (approx. 8fps) while capturing/displaying webcam video! so far this is what I have tried: I have to apply some filters as well, how can I make my code more efficient? is there any way to process these frames using GPU?

    private Capture _capture;
    private bool _captureInProgress;
    private Image<Bgr, Byte> frame;
    private void ProcessFrame(object sender, EventArgs arg)
    {
        frame = _capture.QueryFrame();
        captureImageBox.Image = frame;

    }

    private void startToolStripMenuItem_Click(object sender, EventArgs e)
    {
        #region if capture is not created, create it now
        if (_capture == null)
        {
            try
            {
                _capture = new Capture();
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }
        }
        #endregion

        Application.Idle += ProcessFrame;

        if (_capture != null)
        {
            if (_captureInProgress)
            {
                //stop the capture

                startToolStripMenuItem.Text = "Start";
                Application.Idle -= ProcessFrame;
            }
            else
            {
                //start the capture
                startToolStripMenuItem.Text = "Stop";
                Application.Idle += ProcessFrame;
            }

            _captureInProgress = !_captureInProgress;
        }
    }

Solution

  • The problem is you're processing frames on the Application.Idle callback, which is only invoked every so often. Replace this line

    Application.Idle += ProcessFrame

    with

    _capture.ImageGrabbed += ProcessFrame

    and it should work. This callback is invoked every time a frame is available.