C# 如何从emgu cv中的网络摄像头获取视频流?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18727747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 13:01:51  来源:igfitidea点击:

How to get video stream from webcam in emgu cv?

c#webcamemgucv

提问by TBT

I'm using emgu cv in c#.

我在 c# 中使用 emgu cv。

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

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

采纳答案by Shiva

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

回答by jlew

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)

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