|
发表于 2012-12-16 11:29:44
|
显示全部楼层
请教emgucv中同时读取两个usb摄像头
在我的电脑上是可以的。
xaml文件- <Window x:Class="TestCameraEmguCV.TestTwoCamera"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" Height="700" Width="525"
- Loaded="Window_Loaded"
- Closed="Window_Closed">
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="300*" />
- <RowDefinition Height="300*" />
- <RowDefinition Height="100" />
- </Grid.RowDefinitions>
- <Image Name="imagebox1" Grid.Row="0" Margin="5"/>
- <Image Name="imagebox2" Grid.Row="1" Margin="5"/>
- <Button Name="btn" Content="开始" Margin="0,0,68,16" Click="btn_Click"
- Height="40" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="88" Grid.Row="2" />
- <TextBlock Height="40" HorizontalAlignment="Left" Margin="12,0,0,16"
- Name="frameSpeed" Text="" VerticalAlignment="Bottom" Width="257" Grid.Row="2" />
- </Grid>
- </Window>
复制代码 c#文件- using System;
- using System.Windows;
- using System.Windows.Controls;
- using Emgu.CV;
- using Emgu.CV.Structure;
- using EmguCV.Liuxia;
- namespace TestCameraEmguCV
- {
- /// <summary>
- /// TestTwoCamera.xaml 的交互逻辑
- /// </summary>
- public partial class TestTwoCamera : Window
- {
- Capture capture1;
- Capture capture2;
- public TestTwoCamera()
- {
- InitializeComponent();
- }
-
-
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- capture1 = new Capture(0);
- capture1.ImageGrabbed += new Capture.GrabEventHandler(capture1_ImageGrabbed);
- capture2 = new Capture(1);
- capture2.ImageGrabbed += new Capture.GrabEventHandler(capture2_ImageGrabbed);
-
- }
- void capture1_ImageGrabbed(object sender, System.EventArgs e)
- {
- Capture capture = sender as Capture;
- Image<Bgr, byte> image = capture.RetrieveBgrFrame();
- this.Dispatcher.Invoke(
- new Action(
- () =>
- { imagebox1.Source = BitmapSourceConvert.ToBitmapSource(image); }
- )
- );
- }
- void capture2_ImageGrabbed(object sender, System.EventArgs e)
- {
- Capture capture = sender as Capture;
- Image<Bgr, byte> image = capture.RetrieveBgrFrame();
- this.Dispatcher.Invoke(
- new Action(
- () =>
- { imagebox2.Source = BitmapSourceConvert.ToBitmapSource(image); }
- )
- );
- }
- private void btn_Click(object sender, RoutedEventArgs e)
- {
- capture1.Start();
- capture2.Start();
- }
- private void Window_Closed(object sender, EventArgs e)
- {
- //if (capture1 != null)
- capture1.Stop();
- //if (capture2 != null)
- capture2.Stop();
- }
- }
- }
复制代码 |
|