有很多简单的方法可以找到连接的摄像头并从中记录,尽管它们都不起作用,因为使用的网络摄像头有点旧,我尝试使用Aforge和Ozeki Camera SDK,但它们都没有检测到摄像头,唯一的使用以下代码检测相机的方式:
首先是一个类来保存检测到的相机:
class USBDeviceInfo
{
public USBDeviceInfo(string deviceID, string pnpDeviceID, string description, string name)
{
this.DeviceID = deviceID;
this.PnpDeviceID = pnpDeviceID;
this.Description = description;
this.name = name;
}
public string DeviceID { get; private set; }
public string PnpDeviceID { get; private set; }
public string Description { get; private set; }
public string name { get; private set; }
}
然后使用以下方法检测它们:
using System.Management;
List<USBDeviceInfo> devices = new List<USBDeviceInfo>();
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')"))
collection = searcher.Get(); // gets all connected cameras devices
foreach (var device in collection)
{
devices.Add(new USBDeviceInfo(
(string)device.GetPropertyValue("DeviceID"),
(string)device.GetPropertyValue("PNPDeviceID"),
(string)device.GetPropertyValue("Description"),
(string)device.GetPropertyValue("Name")
));
}
现在检测到相机,我现在如何开始录制?
请注意,驱动程序已安装且摄像头工作正常