Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get video stream from webcam in emgu cv?

Tags:

c#

webcam

emgucv

I'm using emgu cv in c#.

I need to know How I can get the video stream from my webcam(default webcam)in emgu cv?

like image 215
TBT Avatar asked Nov 18 '25 16:11

TBT


1 Answers

You can use the following code to make an app to capture and display video stream:

public class CameraCapture
{
    private Capture capture;  //takes images from camera as image frames
    private bool captureInProgress;

    private void ProcessFrame(object sender, EventArgs arg)
    {
        Image<Bgr, Byte> ImageFrame = capture.QueryFrame();  //line 1
        CamImageBox.Image = ImageFrame;  //line 2
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        if (capture == null)
        {
            try
            {
                capture = new Capture();
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }
        }

        if (capture != null)
        {
            if (captureInProgress)
            {  //if camera is getting frames then stop the capture and set button Text
                // "Start" for resuming capture
                btnStart.Text = "Start!"; //
                Application.Idle -= ProcessFrame;
            }
            else
            {
                //if camera is NOT getting frames then start the capture and set button
                // Text to "Stop" for pausing capture
                btnStart.Text = "Stop";
                Application.Idle += ProcessFrame;
            }
            captureInProgress = !captureInProgress;
        }
    }
}
like image 123
Shiva Avatar answered Nov 20 '25 07:11

Shiva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!