title: How to display webcam images captured with Emgu?
body: <p>I'm currently working on a project that use Facial Recognition.
  I therefore need a way to display the webcam images to the user so he can adjust his face.</p>
  
  <p>I've been trying a lot of things to get images from the webcam using as less CPU as possible:</p>
  
  <ul>
  <li><a href="http://www.codeplex.com/VideoRendererElement" rel="noreferrer">VideoRendererElement</a></li>
  <li><a href="http://www.codeplex.com/WPFMediaKit" rel="noreferrer">WPFMediaKit</a></li>
  <li><a href="http://directshownet.sourceforge.net/" rel="noreferrer">DirectShow-Lib</a></li>
  </ul>
  
  <p>But none of them were fine... Either way too slow or too CPU resources consuming.</p>
  
  <p>Then I tried the <a href="http://www.emgu.com/wiki/index.php/Main_Page" rel="noreferrer">Emgu library</a> and I felt great about it.
  At first, I tried it in a Windows Form project and was updating the image in a <em>Picture Box</em>. 
  But then, when I tried to integrate it in my WPF Project I got stuck on how to pass my image to my Image control..</p>
  
  <p>Right now, I've the following source code:</p>
  
  <pre><code>&lt;Window x:Class="HA.FacialRecognition.Enroll.Window1"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="Window1" Width="800" Height="600"
          Loaded="Window_Loaded" Closing="Window_Closing"&gt;
      &lt;Grid&gt;
          &lt;Image x:Name="webcam" Width="640" Height="480" &gt;
              &lt;Image.Clip&gt;
                  &lt;EllipseGeometry  RadiusX="240" RadiusY="240"&gt;
                      &lt;EllipseGeometry.Center&gt;
                          &lt;Point X="320" Y="240" /&gt;
                      &lt;/EllipseGeometry.Center&gt;
                  &lt;/EllipseGeometry&gt;
              &lt;/Image.Clip&gt;
          &lt;/Image&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And the code behind:</p>
  
  <pre><code>private Capture capture;
  private System.Timers.Timer timer;
  
  public Window1()
  {
      InitializeComponent();
  }
  
  private void Window_Loaded(object sender, RoutedEventArgs e)
  {
      capture = new Capture();
      capture.FlipHorizontal = true;
  
      timer = new System.Timers.Timer();
      timer.Interval = 15;
      timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
      timer.Start();
  }
  
  void timer_Elapsed(object sender, ElapsedEventArgs e)
  {
      using (Image&lt;Bgr, byte&gt; frame = capture.QueryFrame())
      {
          if (frame != null)
          {
              var bmp = frame.Bitmap;
              // How do I pass this bitmap to my Image control called "webcam"?
          }
      }
  }
  
  private void Window_Closing(object sender, CancelEventArgs e)
  {
      if (capture != null)
      {
          capture.Dispose();
      }
  }
  </code></pre>
  
  <p>My guess was to use BitmapSource/WriteableBitmap but I did not get them working...</p>
  
  <p>Thanks!</p>