Ejemplo n.º 1
0
        public KinectView()
        {
            // only one sensor is currently supported
            this.kinectSensor = KinectSensor.GetDefault();

            // set IsAvailableChanged event notifier
            this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;

            // open the sensor
            this.kinectSensor.Open();

            // open the reader for the body frames
            this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();

            endpoint = new KinectClientEndpoint();

            endpoint.Connect();

            // set the BodyFramedArrived event notifier
            this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;

            // initialize the BodyViewer object for displaying tracked bodies in the UI
            this.kinectBodyView = new KinectBodyView(this.kinectSensor);

            InitializeComponent();

            this.kinectBodyViewbox.DataContext = this.kinectBodyView;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the MainWindow class
        /// </summary>
        public MainWindow()
        {
            try
            {
                InitializeComponent();
                this.kinectSensor = KinectSensor.GetDefault();

                // set IsAvailableChanged event notifier
                //this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;

                // open the sensor
                this.kinectSensor.Open();


                // open the reader for the body frames
                this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();

                // set the BodyFramedArrived event notifier
                this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;

                // initialize the BodyViewer object for displaying tracked bodies in the UI
                this.kinectBodyView = new KinectBodyView(this.kinectSensor);

                // initialize the gesture detection objects for our gestures
                //this.gestureDetectorList = new GestureDetector(this.kinectSensor,this.gestureResultView);

                // initialize the MainWindow
                this.InitializeComponent();

                // set our data context objects for display in UI
                this.DataContext = this;
                //this.kinectBodyViewbox.DataContext = this.kinectBodyView;
                // GestureResultView result = new GestureResultView(0, false, false, 0.0f);
                //GestureDetector detector = new GestureDetector(this.kinectSensor, result);
                this.gestureDetectorList = new List <GestureDetector>();

                // set our data context objects for display in UI
                this.DataContext = this;
                this.kinectBodyViewbox.DataContext = this.kinectBodyView;

                // create a gesture detector for each body (6 bodies => 6 detectors) and create content controls to display results in the UI
                //int col0Row = 0;
                //int col1Row = 0;
                int maxBodies = this.kinectSensor.BodyFrameSource.BodyCount;
                //for (int i = 0; i < maxBodies; ++i)
                //{
                GestureResultView result   = new GestureResultView(0, false, false, 0.0f);
                GestureDetector   detector = new GestureDetector(this.kinectSensor, result);
                this.gestureDetectorList.Add(detector);

                // split gesture results across the first two columns of the content grid

                /*ContentControl contentControl = new ContentControl();
                 * contentControl.Content = this.gestureDetectorList[i].GestureResultView;
                 *
                 * if (i % 2 == 0)
                 * {
                 *  // Gesture results for bodies: 0, 2, 4
                 *  Grid.SetColumn(contentControl, 0);
                 *  Grid.SetRow(contentControl, col0Row);
                 ++col0Row;
                 * }
                 * else
                 * {
                 *  // Gesture results for bodies: 1, 3, 5
                 *  Grid.SetColumn(contentControl, 1);
                 *  Grid.SetRow(contentControl, col1Row);
                 ++col1Row;
                 * }
                 *
                 * this.contentGrid.Children.Add(contentControl);
                 * }*/

                // split gesture results across the first two columns of the content grid
                // ContentControl contentControl = new ContentControl();
                //contentControl.Content = this.gestureDetectorList.GestureResultView;
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.StackTrace);
                //throw;
            }
        }