private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { if (isRecording) { DateTime Time = DateTime.Now; Skeleton[] skeletons = new Skeleton[0]; float[] floor = new float[4]; using (Microsoft.Kinect.SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); floor[0] = skeletonFrame.FloorClipPlane.Item1; floor[1] = skeletonFrame.FloorClipPlane.Item2; floor[2] = skeletonFrame.FloorClipPlane.Item3; floor[3] = skeletonFrame.FloorClipPlane.Item4; } } foreach (Skeleton skel in skeletons) { if (skel.TrackingState == SkeletonTrackingState.Tracked) { KinectLib.SkeletonFrame frame = new KinectLib.SkeletonFrame(); frame.Date = Time; frame.SkeletonId = skel.TrackingId; frame.Nodes = new List<SkeletonNode>(); frame.X = skel.Position.X; frame.Y = skel.Position.Y; frame.Z = skel.Position.Z; frame.Floor = floor; foreach (Joint joint in skel.Joints) { SkeletonNode node = new SkeletonNode(); node.NodeType = (int)joint.JointType; node.X = joint.Position.X; node.Y = joint.Position.Y; node.Z = joint.Position.Z; frame.Nodes.Add(node); } Frames.Add(frame); Skeleton DisplaySkeleton = skel; Joint Crotch = DisplaySkeleton.Joints.First(j => j.JointType == JointType.HipCenter); if (Crotch != null) { DrawingGroup DrawingGroup = new DrawingGroup(); using (DrawingContext Context = DrawingGroup.Open()) { Double CrotchDisplayX = image1.Width / 2; Double CrotchDisplayY = image1.Height / 2; foreach (Joint Node in DisplaySkeleton.Joints) { double X = (Node.Position.X - Crotch.Position.X) / 2.5 * image1.Width + CrotchDisplayX; double Y = (-Node.Position.Y + Crotch.Position.Y) / 2.5 * image1.Height + CrotchDisplayY; Context.DrawEllipse(Brushes.Wheat, new Pen(Brushes.Navy, 2), new Point(X, Y), 7, 7); } } DrawingGroup.Freeze(); Dispatcher.Invoke(new Action(() => { image1.Source = new DrawingImage(DrawingGroup); })); } } } } }
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { if (isRecording) { DateTime Time = DateTime.Now; Skeleton[] skeletons = new Skeleton[0]; using (Microsoft.Kinect.SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } foreach (Skeleton skel in skeletons) { if (skel.TrackingState == SkeletonTrackingState.Tracked) { KinectLib.SkeletonFrame frame = new KinectLib.SkeletonFrame(); frame.Date = Time; frame.SkeletonId = skel.TrackingId; frame.Nodes = new List<SkeletonNode>(); frame.X = skel.Position.X; frame.Y = skel.Position.Y; frame.Z = skel.Position.Z; foreach (Joint joint in skel.Joints) { SkeletonNode node = new SkeletonNode(); node.NodeType = (int)joint.JointType; node.X = joint.Position.X; node.Y = joint.Position.Y; node.Z = joint.Position.Z; frame.Nodes.Add(node); } Frames.Add(frame); } } } }