예제 #1
0
 // This function assures if the gestures stored are not null
 private static void assureGestureResultViewNotNull(GestureResultView gestureResultView)
 {
     if (gestureResultView == null)
     {
         throw new ArgumentNullException("gestureResultView");
     }
 }
예제 #2
0
        /// <summary>
        ///Initialization of the gesture detector class. The GestureResultView has the discrete results for the gesture detector
        /// </summary>
        /// <param name="kinectSensor">The active Kinect Sensor</param>
        /// <param name="gestureResultView">It is an object which stores the gesture results</param>
        public GestureDetector(KinectSensor kinectSensor, GestureResultView gestureResultView)
        {
            verifyKinectSensorExists(kinectSensor);
            assureGestureResultViewNotNull(gestureResultView);
            this.GestureResultView = gestureResultView;
            // A valid body frame is the one with the valid tracking ID
            this.vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0);
            this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost;

            // open the reader for the vgb frames
            this.vgbFrameReader = this.vgbFrameSource.OpenReader();
            if (this.vgbFrameReader != null)
            {
                this.vgbFrameReader.IsPaused      = true;
                this.vgbFrameReader.FrameArrived += this.Reader_GestureFrameArrived;
            }

            // load the trained gesture using VGB from the gesture database
            using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase))
            {
                // Load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures),
                foreach (Gesture gesture in database.AvailableGestures)
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Application logic for the Main Window.
        /// SDK 2.0 can support one kinect sensor.
        /// </summary>
        public MainWindow()
        {
            this.kinectSensor = KinectSensor.GetDefault();

            //This event handler is set to know if the Kinect sensor status is changed
            this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;

            // To open the sensor to detect the bodies
            this.kinectSensor.Open();

            // The status text to find the status of Kinect
            this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
                                                            : Properties.Resources.NoSensorStatusText;

            // open the body frame reader to read the data frames from Kinect
            this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();

            // This event notifier is used to identify if the body frame has arrived
            this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;

            // It initializes the bodyviewer object to display tracked bodies in Presentation Layer
            this.kinectBodyView = new BodyView(this.kinectSensor);

            // initialize the gesture detection objects for the gestures
            this.gestureDetectorList = new List <GestureDetector>();

            // initialize the MainWindow
            this.InitializeComponent();

            // The data context objects are set to display in UI
            this.DataContext = this;
            this.kinectBodyViewbox.DataContext = this.kinectBodyView;
            // The total bodies are six but we can use only one for the application

            int col0Row   = 0;
            int col1Row   = 0;
            int maxBodies = this.kinectSensor.BodyFrameSource.BodyCount;

            for (int i = 0; i < maxBodies; ++i)
            {
                GestureResultView result   = new GestureResultView(i, false, false, 0.0f);
                GestureDetector   detector = new GestureDetector(this.kinectSensor, result);
                this.gestureDetectorList.Add(detector);
                // It is used for displaying gestures
                ContentControl contentControl = new ContentControl();
                contentControl.Content = this.gestureDetectorList[i].GestureResultView;

                if (i % 2 == 0)
                {
                    // For even number of bodies
                    Grid.SetColumn(contentControl, 0);
                    Grid.SetRow(contentControl, col0Row);
                    ++col0Row;
                }
                else
                {
                    // For odd number of bodies
                    Grid.SetColumn(contentControl, 1);
                    Grid.SetRow(contentControl, col1Row);
                    ++col1Row;
                }

                // this.contentGrid.Children.Add(contentControl);
            }
        }