public void add(KinectBody Body) { bodies.Add(Body); }
private void OnSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs eventArgs) { SkeletonFrame skeletonFrame = null; try { skeletonFrame = eventArgs.OpenSkeletonFrame(); if (skeletonFrame == null) { return; } // Get the skeleton information if (this.skeletonData == null || this.skeletonData.Length != skeletonFrame.SkeletonArrayLength) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.skeletonData); int min1id = 0; int min2id = 0; float min1dist = maxDistance; float min2dist = maxDistance; // Update the list of trackers and the trackers with the current frame information foreach (Skeleton skeleton in this.skeletonData) { if (skeleton.TrackingState != SkeletonTrackingState.NotTracked) { if (skeleton.Position.Z > minDistance) { if (min2dist <= min1dist && skeleton.Position.Z < min1dist) { min1dist = skeleton.Position.Z; min1id = skeleton.TrackingId; } else if (min1dist <= min2dist && skeleton.Position.Z < min2dist) { min2dist = skeleton.Position.Z; min2id = skeleton.TrackingId; } } } } if (min1id > 0 && min2id > 0) { kinectSensor.SkeletonStream.ChooseSkeletons(min1id, min2id); } else if (min1id > 0) { kinectSensor.SkeletonStream.ChooseSkeletons(min1id); } else { kinectSensor.SkeletonStream.ChooseSkeletons(); } KinectBodySet bodies = new KinectBodySet(); foreach (Skeleton skeleton in this.skeletonData) { if (skeleton.TrackingState == SkeletonTrackingState.Tracked && skeleton.Joints[JointType.Head].TrackingState == JointTrackingState.Tracked) { KinectBody body = new KinectBody(); body.Id = (ulong)skeleton.TrackingId; SkeletonPoint head = skeleton.Joints[JointType.Head].Position; body.Head = new KinectBodyPart(head.X, head.Y, head.Z); if (skeleton.Joints[JointType.HandLeft].TrackingState == JointTrackingState.Tracked) { SkeletonPoint hand = skeleton.Joints[JointType.HandLeft].Position; body.HandLeft = new KinectBodyPart(hand.X, hand.Y, hand.Z); } if (skeleton.Joints[JointType.HandRight].TrackingState == JointTrackingState.Tracked) { SkeletonPoint hand = skeleton.Joints[JointType.HandRight].Position; body.HandRight = new KinectBodyPart(hand.X, hand.Y, hand.Z); } bodies.add(body); } } if (bodies.size() > 0) { foreach (BodyListener listener in new List <BodyListener>(bodyListeners)) { listener.onBodiesReceived(bodies.ToString()); } } } finally { if (skeletonFrame != null) { skeletonFrame.Dispose(); } } }