【问题标题】:How to get video stream from webcam in emgu cv?如何从 emgu cv 中的网络摄像头获取视频流?
【发布时间】:2013-09-14 16:25:18
【问题描述】:

我在 c# 中使用 emgu cv。

我需要知道如何在 emgu cv 中从我的网络摄像头(默认网络摄像头)获取视频流?

【问题讨论】:

标签: c# webcam emgucv


【解决方案1】:

不确定你想对数据做什么,但这会让你从相机中得到一个单帧(并将其显示在 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();
        }
    }                         
}

【讨论】:

    【解决方案2】:

    您可以使用以下代码制作一个应用程序来捕获和显示视频流:

    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;
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      • 2011-02-01
      • 1970-01-01
      • 2011-03-01
      相关资源
      最近更新 更多