设置捕获设备EmguCV [英] Set capture device EmguCV
问题描述
我正在使用EmguCV的 Capture
类从WebCam拍摄图像。
I´m using class Capture
from EmguCV to take images from a WebCam.
根据该类的文档( http://www.emgu.com/wiki/files/2.0.0.0/html/18b6eba7-f18b-fa87-8bf2-2acff68988cb.htm ),Capture有3个构造函数。
According to the documentation of the class (http://www.emgu.com/wiki/files/2.0.0.0/html/18b6eba7-f18b-fa87-8bf2-2acff68988cb.htm), Capture has 3 constructors.
使用 public Capture()
应该使用默认摄像头,并且可以正常工作。
Using public Capture()
its supposed to use the default camera and it works properly.
我在其中一个示例中看到的似乎是
As I saw in one of the examples, seems that
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摄像头)
I tried to use this last constructor to allow the user to choose the device in case he has more than one camera (for example, the integrated camera in a laptop or a USB cam pluged in)
我的问题是我不知道如何获取可用设备列表。尝试创建索引范围从0到99的捕获,并尝试捕获一个期望发生异常的帧,但捕获100个捕获仅拍摄黑色图像。另外,当我使用默认相机时,我不知道如何获取他的索引。
My problem is I don´t know how to get a list of available devices. Tried to create captures with index from 0 to 99 and try to grab a frame expecting an exception, but it just takes a black image with the 100 captures. Also, when I use the default camera, I don´t know how to get his index.
有帮助吗?
编辑:信息中包含 Shiva 我可以使用它(我将其发布以供将来参考):
With the info in the answer of Shiva I got it working with this (I post it for future references):
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);
}
}
推荐答案
捕获对象可用于使用以下代码将静态文件作为输入
The capture object can be used to give static files as input using the following code
Capture grabber = new Emgu.CV.Capture(@".\..\..\file.avi");//can be relative path or absolute path of the video file.
要查找连接的网络摄像头列表,需要导入诸如Direct Show(DirectShow.Net。 dll)插入到项目中,并使用以下代码来检索连接的网络摄像头列表。
For finding the list of connected web cams will need to import something like Direct Show (DirectShow.Net.dll) into the project and use the following code to retrieve the list of connected web cams .
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
Check this link for the full code http://www.emgu.com/wiki/index.php?title=Camera_Capture
此列表可以填充到组合框中,并且可以选择每个连接的设备来检索来自特定设备的视频输入。
This list can be populated into a combo box and each connected device can be chosen to retrieve the video input from the specific device.
示例可在此处找到:
http://fewtutorials.bravesites.com/entries/emgu-cv-c/level-2---use-multiple-相机在一个应用程序中。
对于最后一个问题,默认相机的索引始终为0。
用于初始化捕获带有默认摄像头的对象,您将必须使用以下代码
For your last question the Default Camera always has the index of 0. So for initializing the Capture Object with default camera you will have to use the following code
Capture grabber = new Emgu.CV.Capture(0);
这篇关于设置捕获设备EmguCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!