如何使用USB(网络摄像头)获取连接到我的电脑的所有相机设备的列表,以及笔记本电脑所具有的内置摄像头。
答案 0 :(得分:3)
之前我已经完成了这项工作 - 使用http://directshownet.sourceforge.net/为DirectShow提供了一个像样的.net接口,然后你可以使用以下代码:
DsDevice[] captureDevices;
// Get the set of directshow devices that are video inputs.
captureDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
for (int idx = 0; idx < captureDevices.Length; idx++)
{
// Do something with the device here...
}
答案 1 :(得分:2)
没有任何外部库的简单解决方案是使用WMI
。
添加using System.Management;
,然后:
public static List<string> GetAllConnectedCameras()
{
var cameraNames = new List<string>();
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')"))
{
foreach (var device in searcher.Get())
{
cameraNames.Add(device["Caption"].ToString());
}
}
return cameraNames;
}