Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        public static void Update(Joint joint)
        {
            switch (joint.JointType)
            {
            case JointType.AnkleLeft:
                if (AnkleLeft == null)
                {
                    AnkleLeft = new JointInfo(joint);
                    ListUpdate(0, AnkleLeft);
                }
                else
                {
                    AnkleLeft.position = new Vector3(joint);
                }
                break;

            case JointType.AnkleRight:
                if (AnkleRight == null)
                {
                    AnkleRight = new JointInfo(joint);
                    ListUpdate(1, AnkleRight);
                }
                else
                {
                    AnkleRight.position = new Vector3(joint);
                }
                break;

            case JointType.ElbowLeft:
                if (ElbowLeft == null)
                {
                    ElbowLeft = new JointInfo(joint);
                    ListUpdate(2, ElbowLeft);
                }
                else
                {
                    ElbowLeft.position = new Vector3(joint);
                }
                break;

            case JointType.ElbowRight:
                if (ElbowRight == null)
                {
                    ElbowRight = new JointInfo(joint);
                    ListUpdate(3, ElbowRight);
                }
                else
                {
                    ElbowRight.position = new Vector3(joint);
                }
                break;

            case JointType.FootLeft:
                if (FootLeft == null)
                {
                    FootLeft = new JointInfo(joint);
                    ListUpdate(4, FootLeft);
                }
                else
                {
                    FootLeft.position = new Vector3(joint);
                }
                break;

            case JointType.FootRight:
                if (FootRight == null)
                {
                    FootRight = new JointInfo(joint);
                    ListUpdate(5, FootRight);
                }
                else
                {
                    FootRight.position = new Vector3(joint);
                }
                break;

            case JointType.HandLeft:
                if (HandLeft == null)
                {
                    HandLeft = new JointInfo(joint);
                    ListUpdate(6, HandLeft);
                }
                else
                {
                    HandLeft.position = new Vector3(joint);
                }
                break;

            case JointType.HandRight:
                if (HandRight == null)
                {
                    HandRight = new JointInfo(joint);
                    ListUpdate(7, HandRight);
                }
                else
                {
                    HandRight.position = new Vector3(joint);
                }
                break;

            case JointType.Head:
                if (Head == null)
                {
                    Head = new JointInfo(joint);
                    ListUpdate(8, Head);
                }
                else
                {
                    Head.position = new Vector3(joint);
                }
                break;

            case JointType.HipCenter:
                if (HipCenter == null)
                {
                    HipCenter = new JointInfo(joint);
                    ListUpdate(9, HipCenter);
                }
                else
                {
                    HipCenter.position = new Vector3(joint);
                }
                break;

            case JointType.HipLeft:
                if (HipLeft == null)
                {
                    HipLeft = new JointInfo(joint);
                    ListUpdate(10, HipLeft);
                }
                else
                {
                    HipLeft.position = new Vector3(joint);
                }
                break;

            case JointType.HipRight:
                if (HipRight == null)
                {
                    HipRight = new JointInfo(joint);
                    ListUpdate(11, HipRight);
                }
                else
                {
                    HipRight.position = new Vector3(joint);
                }
                break;

            case JointType.KneeLeft:
                if (KneeLeft == null)
                {
                    KneeLeft = new JointInfo(joint);
                    ListUpdate(12, KneeLeft);
                }
                else
                {
                    KneeLeft.position = new Vector3(joint);
                }
                break;

            case JointType.KneeRight:
                if (KneeRight == null)
                {
                    KneeRight = new JointInfo(joint);
                    ListUpdate(13, KneeRight);
                }
                else
                {
                    KneeRight.position = new Vector3(joint);
                }
                break;

            case JointType.ShoulderCenter:
                if (ShoulderCenter == null)
                {
                    ShoulderCenter = new JointInfo(joint);
                    ListUpdate(14, ShoulderCenter);
                }
                else
                {
                    ShoulderCenter.position = new Vector3(joint);
                }
                break;

            case JointType.ShoulderLeft:
                if (ShoulderLeft == null)
                {
                    ShoulderLeft = new JointInfo(joint);
                    ListUpdate(15, ShoulderLeft);
                }
                else
                {
                    ShoulderLeft.position = new Vector3(joint);
                }
                break;

            case JointType.ShoulderRight:
                if (ShoulderRight == null)
                {
                    ShoulderRight = new JointInfo(joint);
                    ListUpdate(16, ShoulderRight);
                }
                else
                {
                    ShoulderRight.position = new Vector3(joint);
                }
                break;

            case JointType.Spine:
                if (Spine == null)
                {
                    Spine = new JointInfo(joint);
                    ListUpdate(17, Spine);
                }
                else
                {
                    Spine.position = new Vector3(joint);
                }
                break;

            case JointType.WristLeft:
                if (WristLeft == null)
                {
                    WristLeft = new JointInfo(joint);
                    ListUpdate(18, WristLeft);
                }
                else
                {
                    WristLeft.position = new Vector3(joint);
                }
                break;

            case JointType.WristRight:
                if (WristRight == null)
                {
                    WristRight = new JointInfo(joint);
                    ListUpdate(19, WristRight);
                }
                else
                {
                    WristRight.position = new Vector3(joint);
                }
                break;

            default:
                Console.WriteLine("How did you get here?");
                break;
            }
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
 private static void ListUpdate(int index, JointInfo joint)
 {
     allJoints[index] = joint;
 }