Page 3 of 3
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).
Real RealSense In C#
- Getting Started With RealSense In C#
- Event Streams
- A Point Cloud - coming soon
- Hand Tracking - coming soon
Related Articles
BitmapSource: WPF Bitmaps
WriteableBitmap
Comments
or email your comment to: comments@i-programmer.info
|