Advertisement
Guest User

Skeleton Tracking 1706

a guest
Jun 11th, 2014
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. .cs code:
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. using Microsoft.Kinect;
  17.  
  18. namespace WpfApplicationKinectSkeletonTracking
  19. {
  20. /// <summary>
  21. /// Interaction logic for MainWindow.xaml
  22. /// </summary>
  23. ///
  24. public partial class MainWindow : Window
  25. {
  26. public MainWindow()
  27. {
  28. InitializeComponent();
  29. }
  30.  
  31. private void Window_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. kinectSensorChooser1.KinectSensorChanged += new DependencyPropertyChangedEventHandler(kinectSensorChooser1_KinectSensorChanged);
  34. }
  35.  
  36. void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
  37. {
  38. KinectSensor oldSensor = (KinectSensor)e.OldValue;
  39. StopKinect(oldSensor);
  40.  
  41. KinectSensor newSensor = (KinectSensor)e.NewValue;
  42.  
  43. newSensor.DepthStream.Enable();
  44. newSensor.SkeletonStream.Enable();
  45.  
  46. try
  47. { newSensor.Start(); }
  48. catch (System.IO.IOException)
  49. { kinectSensorChooser1.AppConflictOccurred(); }
  50. }
  51.  
  52. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  53. {
  54. StopKinect(kinectSensorChooser1.Kinect);
  55. }
  56.  
  57. void StopKinect(KinectSensor sensor)
  58. {
  59. if (sensor != null)
  60. {
  61. sensor.Stop();
  62. sensor.AudioSource.Stop();
  63. }
  64. }
  65. }
  66. }
  67.  
  68. .xaml code:
  69.  
  70. <Window x:Class="WpfApplicationKinectSkeletonTracking.MainWindow"
  71. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  72. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  73. Title="MainWindow" Height="350" Width="745" xmlns:my="clr-namespace:Microsoft.Samples.Kinect.WpfViewers;assembly=Microsoft.Samples.Kinect.WpfViewers" Closing="Window_Closing" Loaded="Window_Loaded">
  74. <Grid Width="699">
  75. <Grid.ColumnDefinitions>
  76. <ColumnDefinition Width="613*" />
  77. <ColumnDefinition Width="86*" />
  78. </Grid.ColumnDefinitions>
  79. <my:KinectDepthViewer HorizontalAlignment="Left" Margin="30,12,0,0" Name="kinectDepthViewer1" VerticalAlignment="Top" Width="320" Height="240" Kinect="{Binding ElementName=kinectSensorChooser1, Path=Kinect}" />
  80. <my:KinectSensorChooser HorizontalAlignment="Left" Margin="192,63,0,0" Name="kinectSensorChooser1" Width="328" Height="181" VerticalAlignment="Top" />
  81. <my:KinectSkeletonViewer HorizontalAlignment="Left" Margin="379,12,0,0" Name="kinectSkeletonViewer1" VerticalAlignment="Top" Width="320" Height="240" Grid.ColumnSpan="2" Kinect="{Binding ElementName=kinectSensorChooser1, Path=Kinect}" />
  82. </Grid>
  83. </Window>
  84.  
  85.  
  86. Dependencies(references) added:
  87. Microsoft.kinect.dll - found in programfiles/microsoftsdks/kinect/v1.8/assemblies
  88. Microsoft.kinect - found in .NET tab
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement