title: Perform live video stream processing from CaptureElement & MediaCapture
body: <p>In my Windows 8 Store Application, I tend to perform live video stream processing (Face detection for example).</p>
  
  <hr>
  
  <h2>Technique 1</h2>
  
  <p>In my previous Windows 7 application, I was able to use the following technique (<a href="http://www.codeproject.com/Articles/462527/Camera-Face-Detection-in-Csharp-Using-Emgu-CV-Open" rel="nofollow">Camera Face Detection in C# Using Emgu CV (OpenCV in .NET) and WPF</a>) to perform live video processing. The technique was, <strong>having a fixed period timer callback, to actively query image buffer from camera object</strong>.</p>
  
  <pre><code>void timer_Tick(object sender, EventArgs e)
  {
      Image&lt;Bgr,Byte&gt; currentFrame = capture.QueryFrame();
      // Perform image processing based on currentFrame
  </code></pre>
  
  <hr>
  
  <h2>Technique 2</h2>
  
  <p>Another technique I had used before in <a href="http://developer.android.com/reference/android/hardware/Camera.PreviewCallback.html" rel="nofollow">Android</a> is that, I will install a camera buffer preview callback on camera itself. <strong>The camera will periodically trigger the callback, by passing along the captured camera buffer</strong>. From there, I can perform image processing.</p>
  
  <pre><code>public abstract void onPreviewFrame (byte[] data, Camera camera)
  {
      // Perform image processing based on data
  </code></pre>
  
  <hr>
  
  <p>However, in articles which talks about video processing for <strong>Windows 8 Store Application</strong>, they are mostly using built-in processing functions</p>
  
  <ul>
  <li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868174.aspx" rel="nofollow">How to rotate captured video (Windows Store apps using C#/VB/C++ and XAML)</a></li>
  <li><a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868169.aspx" rel="nofollow">How to add video stabilization effect to captured video (Windows Store apps using C#/VB/C++ and XAML)</a></li>
  </ul>
  
  <p><strong>None of them demonstrate how to access raw camera captured buffer, iterate the buffer pixel by pixel.</strong></p>
  
  <p>I believe I need to make use of <code>CaptureElement &amp; MediaCapture</code> according to </p>
  
  <p><a href="http://blog.xyzzer.me/2012/01/22/displaying-webcam-preview-in-a-metro-app-using-winrt-and-xaml/" rel="nofollow">http://blog.xyzzer.me/2012/01/22/displaying-webcam-preview-in-a-metro-app-using-winrt-and-xaml/</a></p>
  
  <blockquote>
    <p>This method is great if you just want to see the webcam input or
    capture it to a file with no hassle. If you want to process the video
    in real time or overlay some other UI components – enter…</p>
    
    <p>The CaptureElement &amp; MediaCapture Way</p>
  </blockquote>
  
  <p>However, the author doesn't elaborate more after that. (I hope he does so :)</p>
  
  <p>Any hint how to perform live video stream processing from CaptureElement &amp; MediaCapture?</p>