void FramesReady(object sender, AllFramesReadyEventArgs e) { ColorImageFrame VFrame = e.OpenColorImageFrame(); if (VFrame == null) { return; } byte[] pixelS = new byte[VFrame.PixelDataLength]; Bitmap bmap = ImageToBitmap(VFrame); SkeletonFrame SFrame = e.OpenSkeletonFrame(); if (SFrame == null) { return; } Graphics g = Graphics.FromImage(bmap); Skeleton[] Skeletons = new Skeleton[SFrame.SkeletonArrayLength]; SFrame.CopySkeletonDataTo(Skeletons); foreach (Skeleton S in Skeletons) { //List<JointInfo> jointInfos = new List<JointInfo>(); if (S.TrackingState == SkeletonTrackingState.Tracked) { foreach (JointType j in Enum.GetValues(typeof(JointType))) { JointInfo.Update(S.Joints[j]); //jointInfos.Add(new JointInfo(S.Joints[j])); } for (int i = 0; i < 20; i++) { if (JointInfo.allJoints[i] != null) { jointLabels[i].Text = JointInfo.allJoints[i].ToString(); } else { jointLabels[i].Text = " "; } } foreach (JointInfo j in JointInfo.allJoints) { if (j != null) { MarkAtxy(j.position, Brushes.Blue, g); } } //body DrawBone(JointType.Head, JointType.ShoulderCenter, S, g); DrawBone(JointType.ShoulderCenter, JointType.Spine, S, g); DrawBone(JointType.Spine, JointType.HipCenter, S, g); //left leg DrawBone(JointType.HipCenter, JointType.HipLeft, S, g); DrawBone(JointType.HipLeft, JointType.KneeLeft, S, g); DrawBone(JointType.KneeLeft, JointType.AnkleLeft, S, g); DrawBone(JointType.AnkleLeft, JointType.FootLeft, S, g); //Right Leg DrawBone(JointType.HipCenter, JointType.HipRight, S, g); DrawBone(JointType.HipRight, JointType.KneeRight, S, g); DrawBone(JointType.KneeRight, JointType.AnkleRight, S, g); DrawBone(JointType.AnkleRight, JointType.FootRight, S, g); //Left Arm DrawBone(JointType.ShoulderCenter, JointType.ShoulderLeft, S, g); DrawBone(JointType.ShoulderLeft, JointType.ElbowLeft, S, g); DrawBone(JointType.ElbowLeft, JointType.WristLeft, S, g); DrawBone(JointType.WristLeft, JointType.HandLeft, S, g); //Right Arm DrawBone(JointType.ShoulderCenter, JointType.ShoulderRight, S, g); DrawBone(JointType.ShoulderRight, JointType.ElbowRight, S, g); DrawBone(JointType.ElbowRight, JointType.WristRight, S, g); DrawBone(JointType.WristRight, JointType.HandRight, S, g); } } pictureBox1.Image = bmap; SFrame.Dispose(); VFrame.Dispose(); }
void FramesReady(object sender, AllFramesReadyEventArgs e) { ColorImageFrame VFrame = e.OpenColorImageFrame(); if (VFrame == null) { return; } byte[] pixelS = new byte[VFrame.PixelDataLength]; Bitmap bmap = ImageToBitmap(VFrame); SkeletonFrame SFrame = e.OpenSkeletonFrame(); if (SFrame == null) { return; } Graphics g = Graphics.FromImage(bmap); Skeleton[] Skeletons = new Skeleton[SFrame.SkeletonArrayLength]; SFrame.CopySkeletonDataTo(Skeletons); foreach (Skeleton S in Skeletons) { //List<JointInfo> jointInfos = new List<JointInfo>(); if (S.TrackingState == SkeletonTrackingState.Tracked) { foreach (JointType j in Enum.GetValues(typeof(JointType))) { JointInfo.Update(S.Joints[j]); //jointInfos.Add(new JointInfo(S.Joints[j])); } for (int i = 0; i < 20; i++) { if (JointInfo.allJoints[i] != null) { jointLabels[i].Text = JointInfo.allJoints[i].ToString(); } else { jointLabels[i].Text = " "; } } foreach (JointInfo j in JointInfo.allJoints) { if (j != null) { MarkAtxy(j.position, Brushes.Blue, g); } } //Testing required coords /* Debug.Print(JointInfo.HandLeft.position.y + * " : " + JointInfo.HandRight.position.y + * " : " + JointInfo.Head.position.y); */ //Check for the relevant pose if ((JointInfo.HandRight.position.y) > JointInfo.Head.position.y && (JointInfo.HandLeft.position.y) > JointInfo.Head.position.y) { if (timer > 1) { if (alarm == false) { //Play Alarm on detecting hands above head player.PlayLooping(); } alarm = true; Debug.Print("Alarm"); pictureBox2.BackColor = Color.Red; } else { timer += 0.01f; pictureBox2.BackColor = Color.Orange; } } else { if (timer <= 0) { player.Stop(); timer = 0; alarm = false; pictureBox2.BackColor = Color.Green; } else { timer -= 0.005f; } } //body DrawBone(JointType.Head, JointType.ShoulderCenter, S, g); DrawBone(JointType.ShoulderCenter, JointType.Spine, S, g); DrawBone(JointType.Spine, JointType.HipCenter, S, g); //left leg DrawBone(JointType.HipCenter, JointType.HipLeft, S, g); DrawBone(JointType.HipLeft, JointType.KneeLeft, S, g); DrawBone(JointType.KneeLeft, JointType.AnkleLeft, S, g); DrawBone(JointType.AnkleLeft, JointType.FootLeft, S, g); //Right Leg DrawBone(JointType.HipCenter, JointType.HipRight, S, g); DrawBone(JointType.HipRight, JointType.KneeRight, S, g); DrawBone(JointType.KneeRight, JointType.AnkleRight, S, g); DrawBone(JointType.AnkleRight, JointType.FootRight, S, g); //Left Arm DrawBone(JointType.ShoulderCenter, JointType.ShoulderLeft, S, g); DrawBone(JointType.ShoulderLeft, JointType.ElbowLeft, S, g); DrawBone(JointType.ElbowLeft, JointType.WristLeft, S, g); DrawBone(JointType.WristLeft, JointType.HandLeft, S, g); //Right Arm DrawBone(JointType.ShoulderCenter, JointType.ShoulderRight, S, g); DrawBone(JointType.ShoulderRight, JointType.ElbowRight, S, g); DrawBone(JointType.ElbowRight, JointType.WristRight, S, g); DrawBone(JointType.WristRight, JointType.HandRight, S, g); } } pictureBox1.Image = bmap; SFrame.Dispose(); VFrame.Dispose(); }