我使用EmguCV的Capture
類從WebCam中獲取圖像。設置捕獲設備EmguCV
根據該課程的文檔(http://www.emgu.com/wiki/files/2.0.0.0/html/18b6eba7-f18b-fa87-8bf2-2acff68988cb.htm),Capture擁有3個構造函數。
使用public Capture()
它應該使用默認的攝像頭,它的工作正常。
正如我在其中一個例子所看到的,似乎
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);
}
}
感謝您的回覆。檢查完這些例子後,我終於找到了它。 – Evans