如何视频采集设备停止正常

问题描述:

我与C#项目。所以在这里我使用了emguCV图像处理库。这是我访问网络摄像头的示例代码并停止。此代码有效,但是当我停止视频设备时,它不能正常停止。如何视频采集设备停止正常

private void btnStart_Click(object sender, EventArgs e) 
    { 
     if(capture==null){ 
      try 
      {      
       capture = new Capture(); 
      } 
      catch(NullReferenceException ex){ 
       MessageBox.Show(ex.Message); 
      } 
     } 

     if(capture!=null){ 
      if (captureInProgress) 
      { 
       btnStart.Text = "!Start"; 
       Application.Idle -= ProcessFrame; 
      } 
      else { 
       btnStart.Text = "Stop"; 
       Application.Idle += ProcessFrame; 
      } 
     } 
     captureInProgress = !captureInProgress; 
    } 

我在这里错过了什么。请帮帮我。

+0

嗨,你究竟是什么意思,它不正确地停止?如果你想释放设备,你将不得不处置捕获变量本身。 capture.Dispose();欢呼声 – Chris

+0

我添加了dispose(),但之后它显示异常。请你能证明使用代码的事情。@克里斯 – mssb

+0

居然在这里我试图访问使用Afroge库停止上述任务后,同一网络摄像头(这里我用emguCV库)。就是这个描述不够清楚?请给我一个解决方案@克里斯 – mssb

private void btnStart_Click(object sender, EventArgs e) 
    { 
     if(capture==null){ 
      try 
     {      
      capture = new Capture(); 
     } 
     catch(NullReferenceException ex){ 
      MessageBox.Show(ex.Message); 
     } 
    } 

    if(capture!=null){ 
     if (captureInProgress) 
     { 
      btnStart.Text = "!Start"; 
      capture.Stop(); //you miss this 
      Application.Idle -= ProcessFrame; 
     } 
     else { 
      btnStart.Text = "Stop"; 
      capture.Start(); //you miss this 
      Application.Idle += ProcessFrame; 
     } 
    } 
    captureInProgress = !captureInProgress; 
} 
+1

答案会更好,如果你只是提到的代码行,在那里它属于更重要的是,*为什么*这是必要的。 –

+0

看,他写的注释行//你错过这个 – gonzobrains

+0

我使用stop()方法和删除ProcessFrame事件处理程序,但我仍然得到一个异常抛出。 – gonzobrains