wpf 设置捕获设备 EmguCV
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17169430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set capture device EmguCV
提问by Evans
I′m using class Capturefrom EmguCV to take images from a WebCam.
我正在使用CaptureEmguCV 中的类从网络摄像头拍摄图像。
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.
根据类的文档(http://www.emgu.com/wiki/files/2.0.0.0/html/18b6eba7-f18b-fa87-8bf2-2acff68988cb.htm),Capture 有 3 个构造函数。
Using public Capture()its supposed to use the default camera and it works properly.
使用public Capture()它应该使用默认相机并且它可以正常工作。
As I saw in one of the examples, seems that
正如我在其中一个例子中看到的那样,似乎
public Capture(string fileName) //takes a video file as the source for the captures.
The last constructor is
最后一个构造函数是
public Capture(int camIndex) //which is supposed to "Create a capture using the specific camera"
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)
我尝试使用最后一个构造函数来允许用户选择设备,以防他有多个摄像头(例如,笔记本电脑中的集成摄像头或插入的 USB 摄像头)
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.
我的问题是我不知道如何获取可用设备的列表。尝试创建索引从 0 到 99 的捕获,并尝试抓取一个期望异常的帧,但它只使用 100 个捕获的黑色图像。另外,当我使用默认相机时,我不知道如何获取他的索引。
Any help?
有什么帮助吗?
Edit:With the info in the answer of ShivaI got it working with this (I post it for future references):
编辑:根据Shiva的回答中的信息,我得到了它的处理(我将其发布以供将来参考):
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);
}
}
采纳答案by Shiva
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.
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 .
要查找已连接的网络摄像头列表,需要将 Direct Show (DirectShow.Net.dll) 之类的内容导入项目,并使用以下代码检索已连接的网络摄像头列表。
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());
}
Check this link for the full code http://www.emgu.com/wiki/index.php?title=Camera_Capture
检查此链接以获取完整代码 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.
此列表可以填充到组合框中,并且可以选择每个连接的设备来检索来自特定设备的视频输入。
Example can be found here: http://fewtutorials.bravesites.com/entries/emgu-cv-c/level-2---use-multiple-cameras-in-one-application.
示例可以在这里找到:http: //fewtutorials.bravesites.com/entries/emgu-cv-c/level-2---use-multiple-cameras-in-one-application。
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
对于您的最后一个问题,默认相机的索引始终为 0。因此,要使用默认相机初始化捕获对象,您必须使用以下代码
Capture grabber = new Emgu.CV.Capture(0);
回答by Billy Mailman
Examining the EMGU CV sourceseems to indicate that it's just passing the index off to the underlying OpenCV library, as part of the cvCreateCameraCapture (int index) function. That function is... A bit of a mess of #ifdefs, but from what I can see (and from what the comments indicate), the index is used to specify both the camera you want, and the API it should be using.
检查EMGU CV 源似乎表明它只是将索引传递给底层 OpenCV 库,作为 cvCreateCameraCapture (int index) 函数的一部分。该函数是...... #ifdefs 有点混乱,但从我所看到的(以及从评论所表明的)来看,索引用于指定您想要的相机以及它应该使用的 API。
Try successively trying multiples of a hundred; each should use a different codec, attempting to use the first camera. It may be that you have one of the APIs listed compiled into your copy of OpenCV, but not working correctly on your system.
尝试连续尝试百的倍数;每个都应该使用不同的编解码器,尝试使用第一个摄像头。可能是您将列出的 API 之一编译到您的 OpenCV 副本中,但在您的系统上无法正常工作。
Edit:Drilling down further, it seems like it ends up at thisfunction call, which uses the MFEnumDeviceSourcesfunction to get the list. The device you wanted is then returned out of that list (see the getDevice function a few lines higher up). So, it looks to me like the dialog you mentioned in your comment is part of Windows' MediaFoundation stuff, in which case you might want to google the wording of the message, see if some people with more experience with MF can point you in the right direction.
编辑:进一步钻研,它似乎以这个函数调用结束,它使用MFEnumDeviceSources函数来获取列表。然后从该列表中返回您想要的设备(请参阅上面几行的getDevice 函数)。因此,在我看来,您在评论中提到的对话框是 Windows 的 MediaFoundation 内容的一部分,在这种情况下,您可能想用谷歌搜索消息的措辞,看看是否有一些对 MF 有更多经验的人可以为您指出正确的方向。

