Real RealSense In C# - Event Streams
Written by Harry Fairhead   
Thursday, 16 April 2015
Article Index
Real RealSense In C# - Event Streams
Multiple streams
Complete Listing

Listing

The complete program with stream alignment is:

namespace WpfCallback
{
 public partial class MainWindow : Window
 {
  private PXCMSenseManager sm;
  public WriteableBitmap wbm;
  public MainWindow()
  {
   InitializeComponent();
  }

  private void Button_Click(object sender,
                             RoutedEventArgs e)
  {
   sm = PXCMSenseManager.CreateInstance();
   PXCMVideoModule.DataDesc ddesc =
                new PXCMVideoModule.DataDesc();
   ddesc.deviceInfo.streams =
     PXCMCapture.StreamType.STREAM_TYPE_COLOR |
      PXCMCapture.StreamType.STREAM_TYPE_DEPTH;
   sm.EnableStreams(ddesc);
   PXCMSenseManager.Handler handler =
                new PXCMSenseManager.Handler();
   handler.onNewSample = OnNewSample;
   sm.Init(handler);
   sm.StreamFrames(false);
  }

  pxcmStatus OnNewSample(int mid,
                     PXCMCapture.Sample sample)
  {
   if (sample.color != null)
   {
    PXCMImage image = sample.color; 
    PXCMImage.ImageData data;
    image.AcquireAccess(
                  PXCMImage.Access.ACCESS_READ,
      PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32,
                                     out data);
    wbm = data.ToWritableBitmap(0,
                              image.info.width,
                             image.info.height,
                                   96.0, 96.0);
    wbm.Freeze();
    image1.Dispatcher.Invoke(
        new Action(() => image1.Source = wbm));
    image.ReleaseAccess(data);
   }
   if (sample.depth != null)
   {
    PXCMImage image = sample.depth;
    PXCMImage.ImageData data;
    image.AcquireAccess(
                 PXCMImage.Access.ACCESS_READ,
     PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32,
                                    out data);
    wbm = data.ToWritableBitmap(0,
                             image.info.width,
                            image.info.height,
                                   96.0, 96.0);
    wbm.Freeze();
    image1.Dispatcher.Invoke(
        new Action(() => image2.Source = wbm));

    image.ReleaseAccess(data);
   }
   GC.Collect();
   return pxcmStatus.PXCM_STATUS_NO_ERROR;
  }
 
  private void Button_Click_1(object sender,
                             RoutedEventArgs e)
  {
 
    sm.Close();
  }
 }
}

   

You can download the code for this program from the CodeBin. (Note you have to register first).

realcamera

Real RealSense In C#

  1. Getting Started With RealSense In C#
  2. Event Streams
  3. A Point Cloud - coming soon
  4. Hand Tracking - coming soon

Related Articles

BitmapSource: WPF Bitmaps 

WriteableBitmap

All About Kinect

Introduction To Kinect

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter

 

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 



Last Updated ( Friday, 26 January 2018 )