Example #1
0
        /// <summary>
        /// Creates body data and bone lists
        /// </summary>
        static BodyData()
        {
            FootPoints          = new List <Media3D.Point3D>();
            gestureDetectorList = new List <GestureDetector>();

            int maxBodies = KinectController._sensor.BodyFrameSource.BodyCount;

            // create a gesture detector for each body (6 bodies => 6 detectors) and create content controls to display results in the UI
            for (int i = 0; i < maxBodies; ++i)
            {
                GestureResult   result   = new GestureResult(i, false, false, 0.0f);
                GestureDetector detector = new GestureDetector(KinectController._sensor, result);
                gestureDetectorList.Add(detector);
            }

            // SKELETON DETECTION ->

            // a bone defined as a line between two joints
            bones = new List <Tuple <JointType, JointType> >();

            // Torso
            bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck));
            bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder));
            bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid));
            bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase));
            bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight));
            bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft));
            bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight));
            bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft));

            // Right Arm
            bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight));
            bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight));
            bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight));
            bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight));
            bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight));

            // Left Arm
            bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft));
            bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft));
            bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft));
            bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft));
            bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft));

            // Right Leg
            bones.Add(new Tuple <JointType, JointType>(JointType.HipRight, JointType.KneeRight));
            bones.Add(new Tuple <JointType, JointType>(JointType.KneeRight, JointType.AnkleRight));
            bones.Add(new Tuple <JointType, JointType>(JointType.AnkleRight, JointType.FootRight));

            // Left Leg
            bones.Add(new Tuple <JointType, JointType>(JointType.HipLeft, JointType.KneeLeft));
            bones.Add(new Tuple <JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft));
            bones.Add(new Tuple <JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft));
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
        /// </summary>
        /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param>
        /// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param>
        public GestureDetector(KinectSensor kinectSensor, GestureResult gestureResultView)
        {
            if (kinectSensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }

            if (gestureResultView == null)
            {
                throw new ArgumentNullException("gestureResultView");
            }

            this.GestureResultView = gestureResultView;

            // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
            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 'Seated' gesture from the gesture database
            using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase))
            {
                // we could load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures),
                // but for this program, we only want to track one discrete gesture from the database, so we'll load it by name
                foreach (Gesture gesture in database.AvailableGestures)
                {
                    if (gesture.Name.Equals(this.GestureName))
                    {
                        vgbFrameSource.AddGesture(gesture);
                    }
                }
            }
        }