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);
}
}