C# 网络摄像机捕获

C# 网络摄像机捕获,c#,webcam,emgucv,C#,Webcam,Emgucv,正如问题所述,我正试图用我的网络相机拍摄一幅图像。我正在运行Windows 7(训练营),并连接了一个摄像头,如下面的屏幕截图所示 但由于某些原因,我似乎无法让以下代码正常工作(它来自另一个问题中给出的代码): 它死了,没有告诉我发生了什么事(在我强制关闭窗口之后)你的代码看起来有问题看看EMGU提供的Cameracapture示例我现在不知道你从哪里获得CaptureType。任何来源,但你的代码应该是 Capture capture = new Capture(); viewer.Ima

正如问题所述,我正试图用我的网络相机拍摄一幅图像。我正在运行Windows 7(训练营),并连接了一个摄像头,如下面的屏幕截图所示

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


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

你的代码看起来有问题看看EMGU提供的Cameracapture示例我现在不知道你从哪里获得CaptureType。任何来源,但你的代码应该是

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
}
如果你不尝试使用USB摄像头,我希望这对你有所帮助,以确保它不会与EMGU(OpenCV)无法访问设备产生冲突

干杯

克里斯

试试这个:

_capture = new Capture(Emgu.CV.CvEnum.CaptureType.DSHOW);
这对我很有用。

你说的“它死了”是什么意思?是否存在引发的运行时错误?如果是,错误是什么?
//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"); 
_capture = new Capture(Emgu.CV.CvEnum.CaptureType.DSHOW);