网络摄像头捕捉

问题描述:

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

Screen shot showing devices

但由于某些原因,我似乎无法得到下面的代码工作(这是从另一个问题给出的link):

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

它死跟出来告诉我关于发生了什么事情(在我强制关闭窗口后)

+1

你是什么意思“它死了”?是否存在抛出的运行时错误?如果是这样,错误是什么? – 2011-11-22 03:23:22

您的代码看起来有问题,请查看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 
} 

你只需要一个变量添加到捕捉捕捉=新的捕捉()方法调用多个摄像头,或者如果从视频文件中

//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的)冲突不是AB的阅读le访问设备。

干杯,

克里斯

试试这个:

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

这对我的伟大工程。