OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 6153|回复: 2

请教emgucv中同时读取两个usb摄像头

[复制链接]
发表于 2012-11-28 08:46:31 | 显示全部楼层 |阅读模式
这里好冷清啊,也不知道高手会不会回答我的问题。。。

我在学习用emgucv的双目部分。我dell本上有一个自带摄像头,我又买了一个usb免驱工业相机(使用上就是个usb摄像头)
我在单独读取任何一个摄像头都没问题,可是就是不能同时读。在初始化第二个摄像头时失败。
  1. try
  2.             {
  3.                 _captureLeft = new Capture(0);
  4.                 _captureLeft.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1600);
  5.                 _captureLeft.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1200);
  6.                 _captureLeft.ImageGrabbed += ProcessFrameLeft;
  7.                 _captureLeft.Start();
  8.                 _captureRight = new Capture(1);
  9.                 _captureRight.ImageGrabbed += ProcessFrameRight;
  10.                 _captureRight.Start();
  11.                 _stopwatch.Start();
  12.             }
  13.             catch (NullReferenceException excpt)
  14.             {
  15.                 MessageBox.Show(excpt.Message);
  16.             }
复制代码
请问是什么问题?如果用opencv同时读两个摄像头该如何写?我在网上找的都是封装的directshow的,可是c#没现成的东西,比较郁闷。
回复

使用道具 举报

发表于 2012-12-16 11:29:44 | 显示全部楼层

请教emgucv中同时读取两个usb摄像头

在我的电脑上是可以的。
xaml文件
  1. <Window x:Class=&quot;TestCameraEmguCV.TestTwoCamera&quot;
  2.         xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
  3.         xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
  4.         Title=&quot;MainWindow&quot; Height=&quot;700&quot; Width=&quot;525&quot;
  5.         Loaded=&quot;Window_Loaded&quot;
  6.         Closed=&quot;Window_Closed&quot;>
  7.     <Grid>
  8.         <Grid.RowDefinitions>
  9.             <RowDefinition Height=&quot;300*&quot; />
  10.             <RowDefinition Height=&quot;300*&quot; />
  11.             <RowDefinition Height=&quot;100&quot; />
  12.         </Grid.RowDefinitions>
  13.         <Image Name=&quot;imagebox1&quot; Grid.Row=&quot;0&quot; Margin=&quot;5&quot;/>
  14.         <Image Name=&quot;imagebox2&quot; Grid.Row=&quot;1&quot; Margin=&quot;5&quot;/>
  15.         <Button Name=&quot;btn&quot; Content=&quot;开始&quot;  Margin=&quot;0,0,68,16&quot; Click=&quot;btn_Click&quot;
  16.                 Height=&quot;40&quot; VerticalAlignment=&quot;Bottom&quot; HorizontalAlignment=&quot;Right&quot; Width=&quot;88&quot; Grid.Row=&quot;2&quot; />
  17.         <TextBlock Height=&quot;40&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;12,0,0,16&quot;
  18.                    Name=&quot;frameSpeed&quot; Text=&quot;&quot; VerticalAlignment=&quot;Bottom&quot; Width=&quot;257&quot; Grid.Row=&quot;2&quot; />
  19.     </Grid>
  20. </Window>
复制代码
c#文件
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using Emgu.CV;
  5. using Emgu.CV.Structure;
  6. using EmguCV.Liuxia;
  7. namespace TestCameraEmguCV
  8. {
  9.     /// <summary>
  10.     /// TestTwoCamera.xaml 的交互逻辑
  11.     /// </summary>
  12.     public partial class TestTwoCamera : Window
  13.     {
  14.         Capture capture1;
  15.         Capture capture2;
  16.         public TestTwoCamera()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.      
  21.      
  22.         private void Window_Loaded(object sender, RoutedEventArgs e)
  23.         {
  24.             capture1 = new Capture(0);
  25.             capture1.ImageGrabbed += new Capture.GrabEventHandler(capture1_ImageGrabbed);
  26.             capture2 = new Capture(1);
  27.             capture2.ImageGrabbed += new Capture.GrabEventHandler(capture2_ImageGrabbed);
  28.          
  29.         }
  30.         void capture1_ImageGrabbed(object sender, System.EventArgs e)
  31.         {
  32.             Capture capture = sender as Capture;
  33.             Image<Bgr, byte> image = capture.RetrieveBgrFrame();
  34.             this.Dispatcher.Invoke(
  35.                 new Action(
  36.                     () =>
  37.                     { imagebox1.Source = BitmapSourceConvert.ToBitmapSource(image); }
  38.                     )
  39.                 );
  40.         }
  41.         void capture2_ImageGrabbed(object sender, System.EventArgs e)
  42.         {
  43.             Capture capture = sender as Capture;
  44.             Image<Bgr, byte> image = capture.RetrieveBgrFrame();
  45.             this.Dispatcher.Invoke(
  46.                 new Action(
  47.                     () =>
  48.                     { imagebox2.Source = BitmapSourceConvert.ToBitmapSource(image); }
  49.                     )
  50.                 );      
  51.         }      
  52.         private void btn_Click(object sender, RoutedEventArgs e)
  53.         {
  54.             capture1.Start();
  55.             capture2.Start();
  56.         }
  57.         private void Window_Closed(object sender, EventArgs e)
  58.         {
  59.             //if (capture1 != null)
  60.                 capture1.Stop();
  61.             //if (capture2 != null)
  62.                 capture2.Stop();
  63.         }
  64.     }
  65. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2013-8-3 15:11:39 | 显示全部楼层

请教emgucv中同时读取两个usb摄像头

有双摄像头标定吗
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-5-10 20:08 , Processed in 0.008845 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表