利用Aforge.Net 调用多个摄像头的一个简单问题

JesseSong 2010-10-05 10:36:54
查看了Aforge 提供的例子(TwoCamerasTest)同时调用两个摄像头,OK,成功了!但是,小弟试试在电脑里面插入了四个摄像头加起手提自带的一个共有五个摄像头,,对原来的Aforge 进行扩展,OK,五个摄像头也可以同时调用。
但是,当我在自己项目里 用同样 的方法同时调用五个摄像头时,即只有一个摄像头可以调用的。
当我调用了ID==1 的摄像头时(这个成功显示画面),其他四个,只显示Connecting 并没有显示的画面,
当我调用ID==2 的摄像头时(这个成功显示画面), 其他四个,只显示Connecting 并没有显示的画面,
ID==3.....等都是这样的效果!
请问高手们。这是什么原因呢?

代码如下:

/// <summary>
/// 开启摄像头
/// </summary>
/// <param name="cb">要查看摄像头设备是否可用</param>
/// <param name="video">要调用摄像头的ID号</param>
/// <returns></returns>
private bool StartCamera(ComboBox cb,int videoID)
{
//判断摄像头可用
if (cb.Enabled == true)
{
switch (videoID)
{
case 1:
VideoCaptureDevice videoSource1 = new VideoCaptureDevice(videoDevices[this.comboBoxEx1.SelectedIndex].MonikerString);
videoSource1.DesiredFrameRate = 10;
videoSourcePlayer1.VideoSource = videoSource1;
videoSourcePlayer1.Start();
break;
case 2:
System.Threading.Thread.Sleep(500);
VideoCaptureDevice videoSource2 = new VideoCaptureDevice(videoDevices[this.comboBoxEx2.SelectedIndex].MonikerString);
videoSource2.DesiredFrameRate = 10;
videoSourcePlayer2.VideoSource = videoSource2;
videoSourcePlayer2.Start();
break;
case 3:
System.Threading.Thread.Sleep(500);
VideoCaptureDevice videoSource3 = new VideoCaptureDevice(videoDevices[this.comboBoxEx3.SelectedIndex].MonikerString);
videoSource3.DesiredFrameRate = 10;
videoSourcePlayer3.VideoSource = videoSource3;
videoSourcePlayer3.Start();
break;
case 4:
System.Threading.Thread.Sleep(500);
VideoCaptureDevice videoSource4 = new VideoCaptureDevice(videoDevices[this.comboBoxEx4.SelectedIndex].MonikerString);
videoSource4.DesiredFrameRate = 10;
videoSourcePlayer4.VideoSource = videoSource4;
videoSourcePlayer4.Start();
break;
case 5:
System.Threading.Thread.Sleep(500);
VideoCaptureDevice videoSource6 = new VideoCaptureDevice(videoDevices[this.comboBoxEx5.SelectedIndex].MonikerString);
videoSource6.DesiredFrameRate = 10;
videoSourcePlayer6.VideoSource = videoSource6;
videoSourcePlayer6.Start();
break;
}
return true;
}
else
{
this.BalloonTipShow("", cb, "提示", "请检查摄像设备是否可用", 2);
return false;
}

}
...全文
613 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyblusea 2013-03-13
  • 打赏
  • 举报
回复
以前写的代码 :

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                // 枚举所有视频输入设备
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

                if (videoDevices.Count == 0)
                    throw new ApplicationException();

                foreach (FilterInfo device in videoDevices)
                {
                    tscbxCameras.Items.Add(device.Name);
                }

                tscbxCameras.SelectedIndex = 0;
            }
            catch (ApplicationException)
            {
                tscbxCameras.Items.Add("No local capture devices");
                videoDevices = null;
            }
        }
hua_0304 2013-03-13
  • 打赏
  • 举报
回复
您好,我复用您的代码,只能调用一个摄像头,可不可以把您的解决办法贴出来呢
只为思考 2012-08-08
  • 打赏
  • 举报
回复
这个能保存么?能不能说说保存代码呀?
f2831890 2011-07-20
  • 打赏
  • 举报
回复
求完整的代码 谢谢
js_dada 2011-06-23
  • 打赏
  • 举报
回复
高手,我三个都不能同时调用,能帮我看看吗?
代码:
// 创建第一个摄像头数据源
if (comboBox1.Enabled == true)
{
VideoCaptureDevice videoSource1 = new VideoCaptureDevice(videoDevices[this.comboBox1.SelectedIndex].MonikerString);
videoSource1.DesiredFrameRate = 10;

videoSourcePlayer1.VideoSource = videoSource1;
videoSourcePlayer1.Start();
}

// 创建第二个摄像头数据源
if (comboBox2.Enabled == true)
{
//System.Threading.Thread.Sleep(500);

VideoCaptureDevice videoSource2 = new VideoCaptureDevice(videoDevices[this.comboBox2.SelectedIndex].MonikerString);
videoSource2.DesiredFrameRate = 10;

videoSourcePlayer2.VideoSource = videoSource2;
videoSourcePlayer2.Start();
}

//创建第三个摄像头数据源
if (comboBox3.Enabled == true)
{
VideoCaptureDevice videoSource3 = new VideoCaptureDevice(videoDevices[this.comboBox3.SelectedIndex].MonikerString);
videoSource3.DesiredFrameRate = 10;

videoSourcePlayer3.VideoSource = videoSource3;
videoSourcePlayer3.Start();
}
JesseSong 2010-10-05
  • 打赏
  • 举报
回复
shit。。。。原来是索引出了问题。。晕呀。

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧