How to get video stream from webcam in emgu cv?

后端 未结 2 401
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 08:03

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?

相关标签:
2条回答
  • 2021-01-14 08:28

    Not sure what you want to do with the data, but this will get you a single frame from the camera (and display it in a pictureBox on a WinForm)

    private void Form1_Load(object sender, EventArgs e)
    {            
    
        var capture = new Emgu.CV.Capture();
    
        using (var nextFrame = capture.QueryFrame())
        {
            if (nextFrame != null)
            {                           
                pictureBox1.Image = nextFrame.ToBitmap();
            }
        }                         
    }
    
    0 讨论(0)
  • 2021-01-14 08:32

    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;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题