/// <summary>
        /// Adds the handpoints to the body. 
        /// </summary>
        /// /// <remarks> 
        /// The new candidate hands are compared to average location of previous hands for bodies with same id, to identify if the candidate hands are left or right.
        /// </remarks> 
        public void AddHands(List<int> handPoints)
        {
            List<CameraSpacePoint> handCenterPoints = BodyUtils.GroupHandPoints(handPoints);

            Hand[] newHands = new Hand[2];

            var averageHandLocationsLastFrames = BodyUtils.GetAverageHandLocationsLastFrames(Id);
            CameraSpacePoint avgFirstHandPoint = averageHandLocationsLastFrames[0];
            CameraSpacePoint avgSecondHandPoint = averageHandLocationsLastFrames[1];

            var distancesToHandAverages = BodyUtils.GetDistancesToHandAveragesLastFrames(handCenterPoints, avgFirstHandPoint, avgSecondHandPoint);

            var sortedDistancesToHandAverages = distancesToHandAverages.OrderBy(kvp => kvp.Value);

            if (BodyUtils.HasFirstHandTracking(Id) || BodyUtils.HasSecondHandTracking(Id))
            {
                bool[] handsUsed = { false, false };

                foreach (var distance in sortedDistancesToHandAverages)
                {
                    if (distance.Key == 0)
                    {
                        if (BodyUtils.HasFirstHandTracking(Id))
                        {
                            if (distancesToHandAverages[distance.Key] < Thresholds.LastFramesHandMaxDistance)
                            {
                                Hand hand = new Hand(handCenterPoints[0], 0, avgFirstHandPoint);
                                if (newHands[0] == null && !handsUsed[0])
                                {
                                    newHands[0] = hand;
                                    handsUsed[0] = true;
                                }
                            }
                        }
                        else
                        {
                            Hand hand = new Hand(handCenterPoints[0], 0, avgFirstHandPoint);
                            if (newHands[0] == null && !handsUsed[0])
                            {
                                newHands[0] = hand;
                                handsUsed[0] = true;
                            }
                        }
                    }
                    else if (distance.Key == 1)
                    {
                        if (BodyUtils.HasSecondHandTracking(Id))
                        {
                            if (distancesToHandAverages[distance.Key] < Thresholds.LastFramesHandMaxDistance)
                            {
                                Hand hand = new Hand(handCenterPoints[0], 1, avgSecondHandPoint);
                                if (newHands[1] == null && !handsUsed[0])
                                {
                                    newHands[1] = hand;
                                    handsUsed[0] = true;
                                }
                            }
                        }
                        else
                        {
                            Hand hand = new Hand(handCenterPoints[0], 1, avgSecondHandPoint);
                            if (newHands[1] == null && !handsUsed[0])
                            {
                                newHands[1] = hand;
                                handsUsed[0] = true;
                            }
                        }
                    }
                    else if (distance.Key == 2)
                    {
                        if (BodyUtils.HasFirstHandTracking(Id))
                        {
                            if (distancesToHandAverages[distance.Key] < Thresholds.LastFramesHandMaxDistance)
                            {
                                Hand hand = new Hand(handCenterPoints[1], 0, avgFirstHandPoint);
                                if (newHands[0] == null && !handsUsed[1])
                                {
                                    newHands[0] = hand;
                                    handsUsed[1] = true;
                                }
                            }
                        }
                        else
                        {
                            Hand hand = new Hand(handCenterPoints[1], 0, avgFirstHandPoint);
                            if (newHands[0] == null && !handsUsed[1])
                            {
                                newHands[0] = hand;
                                handsUsed[1] = true;
                            }
                        }
                    }
                    else if (distance.Key == 3)
                    {
                        if (BodyUtils.HasSecondHandTracking(Id))
                        {
                            if (distancesToHandAverages[distance.Key] < Thresholds.LastFramesHandMaxDistance)
                            {
                                Hand hand = new Hand(handCenterPoints[1], 1, avgSecondHandPoint);
                                if (newHands[1] == null && !handsUsed[1])
                                {
                                    newHands[1] = hand;
                                    handsUsed[1] = true;
                                }
                            }
                        }
                        else
                        {
                            Hand hand = new Hand(handCenterPoints[1], 1, avgSecondHandPoint);
                            if (newHands[1] == null && !handsUsed[1])
                            {
                                newHands[1] = hand;
                                handsUsed[1] = true;
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < handCenterPoints.Count; i++)
                {
                    newHands[i] = new Hand(handCenterPoints[i], i, new CameraSpacePoint() { X = float.NaN, Y = float.NaN, Z = float.NaN });
                }
            }
            Hands = newHands;
        }
Exemple #2
0
        /// <summary>
        /// Adds the handpoints to the body.
        /// </summary>
        /// /// <remarks>
        /// The new candidate hands are compared to average location of previous hands for bodies with same id, to identify if the candidate hands are left or right.
        /// </remarks>
        public void AddHands(List <int> handPoints)
        {
            List <CameraSpacePoint> handCenterPoints = BodyUtils.GroupHandPoints(handPoints);

            Hand[] newHands = new Hand[2];

            var averageHandLocationsLastFrames  = BodyUtils.GetAverageHandLocationsLastFrames(Id);
            CameraSpacePoint avgFirstHandPoint  = averageHandLocationsLastFrames[0];
            CameraSpacePoint avgSecondHandPoint = averageHandLocationsLastFrames[1];

            var distancesToHandAverages = BodyUtils.GetDistancesToHandAveragesLastFrames(handCenterPoints, avgFirstHandPoint, avgSecondHandPoint);

            var sortedDistancesToHandAverages = distancesToHandAverages.OrderBy(kvp => kvp.Value);

            if (BodyUtils.HasFirstHandTracking(Id) || BodyUtils.HasSecondHandTracking(Id))
            {
                bool[] handsUsed = { false, false };

                foreach (var distance in sortedDistancesToHandAverages)
                {
                    if (distance.Key == 0)
                    {
                        if (BodyUtils.HasFirstHandTracking(Id))
                        {
                            if (distancesToHandAverages[distance.Key] < Thresholds.LastFramesHandMaxDistance)
                            {
                                Hand hand = new Hand(handCenterPoints[0], 0, avgFirstHandPoint);
                                if (newHands[0] == null && !handsUsed[0])
                                {
                                    newHands[0]  = hand;
                                    handsUsed[0] = true;
                                }
                            }
                        }
                        else
                        {
                            Hand hand = new Hand(handCenterPoints[0], 0, avgFirstHandPoint);
                            if (newHands[0] == null && !handsUsed[0])
                            {
                                newHands[0]  = hand;
                                handsUsed[0] = true;
                            }
                        }
                    }
                    else if (distance.Key == 1)
                    {
                        if (BodyUtils.HasSecondHandTracking(Id))
                        {
                            if (distancesToHandAverages[distance.Key] < Thresholds.LastFramesHandMaxDistance)
                            {
                                Hand hand = new Hand(handCenterPoints[0], 1, avgSecondHandPoint);
                                if (newHands[1] == null && !handsUsed[0])
                                {
                                    newHands[1]  = hand;
                                    handsUsed[0] = true;
                                }
                            }
                        }
                        else
                        {
                            Hand hand = new Hand(handCenterPoints[0], 1, avgSecondHandPoint);
                            if (newHands[1] == null && !handsUsed[0])
                            {
                                newHands[1]  = hand;
                                handsUsed[0] = true;
                            }
                        }
                    }
                    else if (distance.Key == 2)
                    {
                        if (BodyUtils.HasFirstHandTracking(Id))
                        {
                            if (distancesToHandAverages[distance.Key] < Thresholds.LastFramesHandMaxDistance)
                            {
                                Hand hand = new Hand(handCenterPoints[1], 0, avgFirstHandPoint);
                                if (newHands[0] == null && !handsUsed[1])
                                {
                                    newHands[0]  = hand;
                                    handsUsed[1] = true;
                                }
                            }
                        }
                        else
                        {
                            Hand hand = new Hand(handCenterPoints[1], 0, avgFirstHandPoint);
                            if (newHands[0] == null && !handsUsed[1])
                            {
                                newHands[0]  = hand;
                                handsUsed[1] = true;
                            }
                        }
                    }
                    else if (distance.Key == 3)
                    {
                        if (BodyUtils.HasSecondHandTracking(Id))
                        {
                            if (distancesToHandAverages[distance.Key] < Thresholds.LastFramesHandMaxDistance)
                            {
                                Hand hand = new Hand(handCenterPoints[1], 1, avgSecondHandPoint);
                                if (newHands[1] == null && !handsUsed[1])
                                {
                                    newHands[1]  = hand;
                                    handsUsed[1] = true;
                                }
                            }
                        }
                        else
                        {
                            Hand hand = new Hand(handCenterPoints[1], 1, avgSecondHandPoint);
                            if (newHands[1] == null && !handsUsed[1])
                            {
                                newHands[1]  = hand;
                                handsUsed[1] = true;
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < handCenterPoints.Count; i++)
                {
                    newHands[i] = new Hand(handCenterPoints[i], i, new CameraSpacePoint()
                    {
                        X = float.NaN, Y = float.NaN, Z = float.NaN
                    });
                }
            }
            Hands = newHands;
        }
 public Body(int id, TimeSpan timeStamp)
 {
     Id = id;
     Hands = new Hand[2];
     TimeStamp = timeStamp;
 }
Exemple #4
0
 public Body(int id, TimeSpan timeStamp)
 {
     Id        = id;
     Hands     = new Hand[2];
     TimeStamp = timeStamp;
 }