【问题标题】:Web Camera Capture网络摄像头捕捉
【发布时间】:2011-11-22 03:21:12
【问题描述】:

作为hereStates 的问题,我正在尝试用我的网络摄像头捕捉图像。我正在运行 Windows 7 (bootcamp) 并连接了一个摄像头,如以下屏幕截图所示。

但由于某种原因,我似乎无法让以下代码工作(它来自另一个问题中给出的link):

Capture capture = new Capture(CaptureType.ANY); //fezzes on this line
viewer.Image = capture.QueryFrame();

它没有告诉我发生了什么就死了(在我强行关闭窗口之后)

【问题讨论】:

  • “它死了”是什么意思?是否有抛出运行时错误?如果是这样,错误是什么?

标签: c# webcam emgucv


【解决方案1】:

您的代码看起来有问题请查看随 EMGU 提供的 Cameracapture 示例,我现在不知道您从哪里获得 CaptureType.ANY,但您的代码应该是

Capture capture = new Capture(); 
viewer.Image = capture.QueryFrame();

虽然链接有效,但它已经过时(2009 年)。

这是您需要的示例中经过稍微编辑的代码:

private Capture _capture;

public YOUR_PROJECT()
{
    InitializeComponent();
    try
    {
        _capture = new Capture();
    }
    catch (NullReferenceException excpt)
    {
        MessageBox.Show(excpt.Message);
    }

    if (_capture != null)
    {
        Application.Idle += ProcessFrame;
    }
}


private void ProcessFrame(object sender, EventArgs arg)
{
    Image<Bgr, Byte> frame = _capture.QueryFrame();
    Picturebox1.Image = frame.ToBitmap(); //Display image in standard Picture Box
}

如果您有多个摄像头或从视频文件中读取,您只需向 Capture capture = new Capture() 方法调用添加一个变量

//For example if I had two video Cameras
Capture capture = new Capture(0); //CAM1
Capture capture = new Capture(1); //CAM2

//For a Video File
Capture capture = new Capture(@"C:/..../Myvideofile.avi"); 

如果不尝试使用 USB 摄像头,我希望这对您有所帮助,以确保它不会与 EMGU (OpenCV) 无法访问设备发生冲突。

干杯,

克里斯

【讨论】:

    【解决方案2】:

    试试这个:

    _capture = new Capture(Emgu.CV.CvEnum.CaptureType.DSHOW);
    

    这对我很有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-21
      • 2015-04-25
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      相关资源
      最近更新 更多