2012-04-17 9 views
0

私はEmgu CVを使用してC#Webカメラアプリケーションを作成しています。私はpictureBoxのフレームキャプチャ中にユーザーがウェブカムを抜いたときに処理しようとしました。
Webカメラのプラグが抜かれている場合、アプリケーションはpictureBoxを再び更新できるようになるまで2秒ごとに新しいWebカム接続のスキャンを開始する必要があります。
次のタイマーコードは何も捕捉できませんでした。プログラムは最初にフレームをキャプチャし、カメラのプラグを抜き、プラグを差し込みましたが、カメラは再起動できません。Emgu CVチェックWebカム接続

private void timer1_Tick(object sender, EventArgs e) 
    { 

     if (cap == null) 
     { 
      try 
      { 
       cap = new Capture(0); 
       cap.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 320); 
       cap.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 240); 

       Console.WriteLine("Restarting Cam"); 
      } 
      catch (Exception ee){ 
       Console.WriteLine("null"); cap = null; return; 
      } 
     } 
     else 
     { 
      Console.WriteLine("NO null"); 
     } 

     try 
     { 
      Image<Bgr, byte> nextFrame = cap.QueryFrame(); 
     } 
     catch(Exception ee) 
     { 
      Console.WriteLine("Frame Capture fail"); 
      cap.Dispose(); 
      cap = null; 
      return; 
     } 
     using (Image<Bgr, byte> nextFrame = cap.QueryFrame()) 
     { 
      if (nextFrame != null) 
      { 
       Image<Gray, byte> grayframe = nextFrame.Convert<Gray, byte>(); 
       videoBox.Image = nextFrame.ToBitmap(); 
      } 
     } 
    } 

プログラムがカメラを抜いた後、印刷「ヌル」、20秒を維持していない、スレッド「」(0xb96c)をプリントアウト出力コンソールには、コード0(0x0の)で終了しました

+1

大丈夫に接続されている場合、あなたは確認することができます!そして.......... – Shoban

+0

あなたの質問は何ですか? –

答えて

0

かを確認することができますDirectShow libとの接続性。

DirectShowLib.DsDevice[] allCameras = DirectShowLib.DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice); 

あなたに選択したカメラ名のクラスのプロパティを追加最初に接続されているすべてのカメラの配列を取得し、カメラが

bool isConnected = DirectShowLib.DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice).Any(c => c.Name == selectedCameraName); 
関連する問題