Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat control do I need to show video from a webcam?
    primarykey
    data
    text
    <p>I want to integrate a webcam and I am using Aforge.NET framework. What control do I need to show the webcam video. My simple program will get the webcam, put it in the combo box and when i click 'ok', I can see that the camera is running but I don't see the video. C#/WPF</p> <p>`</p> <pre><code>&lt;Window x:Class="MyWebCam.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="425"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="4*"/&gt; &lt;RowDefinition Height="*"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Image Grid.ColumnSpan="2" x:Name="videoPlayer" Margin="15"&gt;&lt;/Image&gt; &lt;ComboBox Grid.Row="1" Grid.ColumnSpan="2" x:Name="cbxDevices" MinWidth="150" Margin="15" VerticalAlignment="Center" HorizontalAlignment="left" SelectionChanged="cbxDevices_SelectionChanged" /&gt; &lt;Button Grid.Column="1" Grid.Row="1" x:Name="btnOk" Content="OK" MinWidth="100" Margin="15" Click="btnOk_Click" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>`</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using AForge; using AForge.Imaging; using AForge.Video; using AForge.Video.VFW; using AForge.Video.DirectShow; using AForge.Controls; using System.Drawing; using AForge.Vision.Motion; using AForge.Vision; namespace MyWebCam { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { //opened video source private VideoCaptureDevice videoSource = null; //motion detector MotionDetector detector = new MotionDetector( new TwoFramesDifferenceDetector(), new MotionAreaHighlighting()); FilterInfoCollection videoDevices; private bool deviceExist = false; private string device; //video device public string VideoDevice { get { return device; } } public MainWindow() { InitializeComponent(); getCamList(); } private void getCamList() { try { videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); cbxDevices.Items.Clear(); if (videoDevices.Count == 0) { throw new ApplicationException(); } deviceExist = true; foreach (FilterInfo device in videoDevices) { cbxDevices.Items.Add(device.Name); } cbxDevices.SelectedIndex = 0; //make first cam default } catch (ApplicationException) { deviceExist = false; cbxDevices.Items.Add("No webcams on your system"); } } private void cbxDevices_SelectionChanged(object sender, SelectionChangedEventArgs e) { device = videoDevices[cbxDevices.SelectedIndex].MonikerString; if (cbxDevices.SelectedIndex != -1) { videoSource = new VideoCaptureDevice(videoDevices[cbxDevices.SelectedIndex].MonikerString); videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); } } private void video_NewFrame(object sender, NewFrameEventArgs eventArgs) { // get new frame Bitmap video = (Bitmap)eventArgs.Frame; // process the frame videoPlayer.Source = video; //this is where i'm having the problem } private void btnOk_Click(object sender, RoutedEventArgs e) { videoSource.Start(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload