Exemple #1
0
        public ClosestBodyFrame(Microsoft.Kinect.BodyFrame bf, double engageMin, double engageMax)
        {
            Type = FrameType.ClosestBody;

            engageBeginBoundZ = engageMin;
            engageEndBoundZ   = engageMax;

            Body[] bodies = new Body[bf.BodyCount];
            bf.GetAndRefreshBodyData(bodies);

            double closestDistance = Double.MaxValue;

            for (int i = 0; i < bodies.Length; i++)
            {
                var body = bodies[i];

                if (body.IsTracked)
                {
                    TrackedCount++;
                }

                double distance = DistanceFromKinect(body);

                if (IsEngaged(distance))
                {
                    if (body.TrackingId == lastEngagedTrackingId)
                    {
                        closestBody  = body;
                        closestIndex = i;
                        break;
                    }
                    else if (distance < closestDistance)
                    {
                        closestBody     = body;
                        closestDistance = distance;
                        closestIndex    = i;
                    }
                }
            }

            // Enagaged implies BodyFound
            Debug.Assert(!Engaged || BodyFound);

            if (!BodyFound)
            {
                lastEngagedTrackingId = 0;
            }
            else if (TrackingId != lastEngagedTrackingId)
            {
                lastEngagedTrackingId = TrackingId;
            }

            //Debug.WriteLine("Number of tracked bodies: {0}", trackedCount);
        }
Exemple #2
0
 public BodyFrame(Microsoft.Kinect.BodyFrame bodyFrame)
 {
     _bodyFrame = bodyFrame;
 }