Point getJointLocation(Microsoft.Research.Kinect.Nui.JointsCollection joints, JointID ids)
        {
            Point a = new Point();

            a = (getDisplayPosition(joints[ids]));

            return(a);
        }
        Polyline getBodySegment(Microsoft.Research.Kinect.Nui.JointsCollection joints, Brush brush, params JointID[] ids)
        {
            PointCollection points = new PointCollection(ids.Length);

            for (int i = 0; i < ids.Length; ++i)
            {
                points.Add(getDisplayPosition(joints[ids[i]]));
            }

            Polyline polyline = new Polyline();

            polyline.Points          = points;
            polyline.Stroke          = brush;
            polyline.StrokeThickness = 5;
            return(polyline);
        }
Example #3
0
        Polyline getBodySegment(Microsoft.Research.Kinect.Nui.JointsCollection joints, Brush brush, params JointID[] ids)
        {
            bool            containsCueJoint = false;
            PointCollection points           = new PointCollection(ids.Length);

            for (int i = 0; i < ids.Length; ++i)
            {
                if (this.context.CurrentCue != null && this.context.CurrentCue == ids[i])
                {
                    containsCueJoint = true;
                }

                points.Add(getDisplayPosition(joints[ids[i]]));
            }

            Polyline polyline = new Polyline();

            polyline.Points          = points;
            polyline.Stroke          = containsCueJoint ? new SolidColorBrush(Color.FromRgb(255, 255, 255)) : brush;
            polyline.StrokeThickness = 5;
            return(polyline);
        }
        /// <summary>
        /// Recognize current pose
        /// </summary>
        /// <param name="joints">Skelet positions</param>
        /// <param name="confidenceAngle">Maximum possible angle between left and right part body angles </param>
        /// <param name="standPoseFactor">Factor for recognition standing and sitting poses</param>
        /// <param name="isAutomaticChoiceAngle"> Chice flag of calculation angle between vectors HipShoulder and KneeShoulder
        /// if true nereast to sensor part body choiced else angle calculate as average between  left and right part body angles
        /// </param>
        /// <param name="angleShift">angle shift</param>
        /// <param name="recognitionHeadDistance">First time recognition distance of skelet head</param>
        /// <param name="leftAngle">left body part angle between vectors HipShoulder and KneeShoulder</param>
        /// <param name="rightAngle">left body part angle between vectors HipShoulder and KneeShoulder</param>
        /// <param name="currentHeadDistance">current Head Distance</param>
        /// <returns></returns>
        public static string RecognizePose(Microsoft.Research.Kinect.Nui.JointsCollection joints, double confidenceAngle, double standPoseFactor,
                                           bool isAutomaticChoiceAngle, double angleShift,
                                           ref double recognitionHeadDistance, out double leftAngle, out double rightAngle, out double currentHeadDistance,
                                           out double bodyFloorAngle, out double hipsKneesHigh, out double headHigh)
        {
            string result;

            rightAngle = CalculateAngle(joints[JointID.ShoulderLeft], joints[JointID.HipRight], joints[JointID.KneeRight]);
            leftAngle  = CalculateAngle(joints[JointID.ShoulderRight], joints[JointID.HipLeft], joints[JointID.KneeLeft]);

            // MICHI: New vble addings:
            List <Joint> highJoints = new List <Joint>();

            highJoints.Add(joints[JointID.Spine]);
            highJoints.Add(joints[JointID.HipCenter]);
            List <Joint> lowJoints = new List <Joint>();

            lowJoints.Add(joints[JointID.KneeLeft]);
            lowJoints.Add(joints[JointID.KneeRight]);
            bodyFloorAngle = CalculateAngle(highJoints, lowJoints);
//            bodyFloorAngle = RotateX((float)0.0, joints[JointID.Head]).Y;
            // If a knee is too high it can mean that the person is sitting or fallen or something else.
            //the more negative value is the most interesting since it doesn't mean anything if it is positive.
            hipsKneesHigh = joints[JointID.HipRight].Position.Y - joints[JointID.KneeRight].Position.Y;
            if (joints[JointID.HipLeft].Position.Y - joints[JointID.KneeLeft].Position.Y < hipsKneesHigh)
            {
                hipsKneesHigh = joints[JointID.HipLeft].Position.Y - joints[JointID.KneeLeft].Position.Y;
            }
            headHigh = joints[JointID.Head].Position.Y; // This value doesn't seem to be really realiable...

            if (recognitionHeadDistance == 0)
            {
                recognitionHeadDistance = vectorNorm(joints[JointID.Head].Position.X, joints[JointID.Head].Position.Y,
                                                     joints[JointID.Head].Position.Z);
            }

            currentHeadDistance = vectorNorm(joints[JointID.Head].Position.X, joints[JointID.Head].Position.Y,
                                             joints[JointID.Head].Position.Z);


            // If first headDistance is greater or equal than the product between the current one and the standPoseFactor (1.1)
//            if (!(recognitionHeadDistance < standPoseFactor * currentHeadDistance))
            if (joints[JointID.HandLeft].Position.Y > joints[JointID.Head].Position.Y || joints[JointID.HandRight].Position.Y > joints[JointID.Head].Position.Y)
            { // Raising at least one hand // MICHI: I CHANGED this so it detects both-hand risings and not only the first checked.
                if (joints[JointID.HandLeft].Position.Y < joints[JointID.Head].Position.Y)
                {
                    result = "Raising right hand";
                }
                else if (joints[JointID.HandRight].Position.Y < joints[JointID.Head].Position.Y)
                {
                    result = "Raising left hand";
                }
                else
                {
                    result = "Raising BOTH hands";
                }
            }
            else
            {
                // If the angle is in the confidence interval
                if (Math.Abs(rightAngle - leftAngle) < confidenceAngle)
                {
                    double angle;
                    if (!isAutomaticChoiceAngle)
                    {
                        angle = (rightAngle + leftAngle) / 2;
                    }
                    else
                    {
                        // Get distance to both solders
                        double shLD = vectorNorm(joints[JointID.ShoulderLeft].Position.X, joints[JointID.ShoulderLeft].Position.Y,
                                                 joints[JointID.ShoulderLeft].Position.Z);
                        double shRD = vectorNorm(joints[JointID.ShoulderRight].Position.X, joints[JointID.ShoulderRight].Position.Y,
                                                 joints[JointID.ShoulderRight].Position.Z);
                        // The nearest shoulder's angle is the one taken into account
                        if (shLD > shRD)
                        {
                            angle = rightAngle;
                        }
                        else
                        {
                            angle = leftAngle;
                        }
                    }
                    result = "Sitting pose... somehow";
                }
                else
                {
                    result = "Standing pose";
                }
            }

            result = result + calculatePercentage(joints);

            return(result);
        }