//不可以用USB延长器链接多个摄像头,否则只显示一个。
int selectedDeviceIndex = -1; //设备编号
foreach (Control control in this.panel1.Controls)
{
//USB
if (control is AForge.Controls.VideoSourcePlayer)
{
try
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
selectedDeviceIndex++;
if (selectedDeviceIndex == 0)
{
//连接摄像头0。
videoSource1 = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);
videoSource1.VideoResolution = videoSource1.VideoCapabilities[selectedDeviceIndex];
icImage10.VideoSource = videoSource1;
icImage10.Start();
}
else if (selectedDeviceIndex == 1)
{
//连接摄像头1。
videoSource2 = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);
videoSource2.VideoResolution = videoSource2.VideoCapabilities[selectedDeviceIndex];
icImage11.VideoSource = videoSource2;
icImage11.Start();
}
}
catch (Exception ex)
{
log.Error("USB摄像头打开失败: " + ex.Message);
}
}
}