4

EmguCVのクラスCaptureを使用して WebCam から画像を取得しています。

クラスのドキュメント ( http://www.emgu.com/wiki/files/2.0.0.0/html/18b6eba7-f18b-fa87-8bf2-2acff68988cb.htm ) によると、Capture には 3 つのコンストラクターがあります。

デフォルトのカメラを使用public Capture()するはずであり、正常に動作します。

例の1つで見たように、

public Capture(string fileName) //takes a video file as the source for the captures.

最後のコンストラクタは

public Capture(int camIndex) //which is supposed to "Create a capture using the specific camera" 

この最後のコンストラクターを使用して、ユーザーが複数のカメラを持っている場合にデバイスを選択できるようにしようとしました (たとえば、ラップトップの内蔵カメラまたはプラグインされた USB カメラ)。

私の問題は、利用可能なデバイスのリストを取得する方法がわからないことです。0 から 99 までのインデックスでキャプチャを作成しようとし、例外を予期してフレームを取得しようとしましたが、100 のキャプチャで黒い画像しか取得しません。また、デフォルトのカメラを使用すると、彼のインデックスを取得する方法がわかりません。

何か助けはありますか?

編集:シヴァの回答の情報を使用して、これで動作するようになりました(将来の参考のために投稿します):

private void onLoad(object sender, RoutedEventArgs e)
{
    //Add the image processing to the dispatcher
    this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(dispatcherTimer_Tick);

    //Get the information about the installed cameras and add the combobox items 
    DsDevice[] _SystemCamereas = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
    Video_Device[] WebCams = new Video_Device[_SystemCamereas.Length];
    for (int i = 0; i < _SystemCamereas.Length; i++)
    {
        WebCams[i] = new Video_Device(i, _SystemCamereas[i].Name, _SystemCamereas[i].ClassID); //fill web cam array
        ComboBoxDevices.Items.Add(WebCams[i].ToString());
    }
}

private void dispatcherTimer_Tick(object sender, EventArgs e)
{
    if (capture != null)
    {
        //Capture an image
        Image<Bgr, byte> img = capture.QueryFrame();
        //Show the image in the window
        ImageOriginal.Source = ImageProcessor.ToBitmapSource(img);
    }
}

private void ComboBoxDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    //If there is already a capture, dispose it
    if (capture != null)
    {
        capture.Dispose();
    }
    //Get the selected camera
    int selectedDevice = ComboBoxDevices.SelectedIndex;
    try
    {
        //Create new capture with the selected camera
        capture = new Capture(selectedDevice);
    }
    catch (Exception excpt)
    {
        MessageBox.Show(excpt.Message);
    }
}
4

2 に答える 2

4

キャプチャ オブジェクトを使用して、次のコードを使用して静的ファイルを入力として指定できます。

 Capture grabber = new Emgu.CV.Capture(@".\..\..\file.avi");//can be relative path or absolute path of the video file.

接続されている Web カメラのリストを見つけるには、Direct Show (DirectShow.Net.dll) などをプロジェクトにインポートし、次のコードを使用して接続されている Web カメラのリストを取得する必要があります。

    DsDevice[] _SystemCamereas = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
    Video_Device[] WebCams = new Video_Device[_SystemCamereas.Length];
        for (int i = 0; i < _SystemCamereas.Length; i++)
        {
            WebCams[i] = new Video_Device(i, _SystemCamereas[i].Name, _SystemCamereas[i].ClassID); //fill web cam array
            Camera_Selection.Items.Add(WebCams[i].ToString());
        }

完全なコードについては、このリンクを確認して ください http://www.emgu.com/wiki/index.php?title=Camera_Capture

このリストはコンボ ボックスに入力でき、接続されている各デバイスを選択して、特定のデバイスからビデオ入力を取得できます。

例はここにあります: http://fewtutorials.bravesites.com/entries/emgu-cv-c/level-2---use-multiple-cameras-in-one-application .

最後の質問では、デフォルト カメラのインデックスは常に 0 です。デフォルト カメラでキャプチャ オブジェクトを初期化するには、次のコードを使用する必要があります。

Capture grabber = new Emgu.CV.Capture(0);
于 2013-06-21T19:44:46.477 に答える