public MainWindow() { InitializeComponent(); foreach (var item in Enum.GetValues(typeof(JointType))) { cmbPoinType.Items.Add(item); } cmbPoinType.SelectedItem = JointType.HandRight; try { kinect = new KinectGestureAPI(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error on startup", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(1); } kinect.Video.ImageReady += new VideoImageReadyEventHandler(VideoImageReady); kinect.FrameReady += new FrameReadyEventHandler(SkeletonFrame_FrameReady); kinect.SequenceReady += new SequenceReadyEventHandler(SkeletonFrame_SequenceReady); }
/// <summary> /// Window constructor. /// </summary> public MainWindow() { InitializeComponent(); try { kinect = new KinectGestureAPI(0, false); //gesture counter int gestureID = 0; //add all gestures in gesture folder string[] files = Directory.GetFiles("Gestures", "*.gdf", SearchOption.AllDirectories); foreach (var file in files) { kinect.RegisterGesture(new GenericOnePoint(gestureID++), file); } } catch (GestureStateException ex) { MessageBox.Show(ex.Message, "Error on gesture loading", MessageBoxButton.OK, MessageBoxImage.Error); if (kinect != null) kinect.Dispose(); Environment.Exit(1); } catch (KinectStateException ex) { MessageBox.Show(ex.Message, "Error on kinect initailizazion", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(1); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error on startup", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(1); } //register events kinect.Video.ImageReady += new VideoImageReadyEventHandler(VideoImageReady); kinect.FrameReady += new FrameReadyEventHandler(SkeletonFrame_FrameReady); kinect.GestureRecognized += new GestureRecognizedEventHandler(Players_GestureRecognized); //timer for gesture info hide timer.Tick += new EventHandler(timer_Tick); timer.Interval = new TimeSpan(0, 0, 3); }
/// <summary> /// Construct and initialize each KinectGesturePlayer instance and register their events. /// </summary> /// <param name="api">Instance of api using this collection.</param> /// <param name="playerColors">Array of 6 colors user for players visualization. If not set, uses dafaults.</param> public KinectGesturePlayerCollection(KinectGestureAPI api, Color[] playerColors = null) { this.api = api; this.kinect = api.Kinect; if (playerColors == null) playerColors = DefaultPlayerColors; for (int i = 0; i <= 5; i++) { players[i] = new KinectGesturePlayer(kinect, i, playerColors[i % 6]); players[i].SequenceReady += new SequenceReadyEventHandler(KinectGesturePlayerCollection_SequenceReady); players[i].GestureRecognized += new GestureRecognizedEventHandler(KinectGesturePlayerCollection_GestureRecognized); } visualElements = new List<UIElement>(); lastUpdate = DateTime.MinValue; }