예제 #1
0
        private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
        {
            // Render Torso
            this.DrawBone(skeleton, drawingContext, JointType.Head, JointType.ShoulderCenter);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderLeft);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderRight);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.Spine);
            this.DrawBone(skeleton, drawingContext, JointType.Spine, JointType.HipCenter);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipLeft);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipRight);

            // Left Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderLeft, JointType.ElbowLeft);
            //LeftHand.Text = skeleton.Joints[JointType.ShoulderLeft].Position.X.ToString();
            Estado.Text     = postureRecognition.Predict(skeleton);
            currentPosition = Estado.Text;
            if (flag)
            {
                lista.Add(skeleton);
            }
            this.DrawBone(skeleton, drawingContext, JointType.ElbowLeft, JointType.WristLeft);
            this.DrawBone(skeleton, drawingContext, JointType.WristLeft, JointType.HandLeft);

            // Right Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderRight, JointType.ElbowRight);
            this.DrawBone(skeleton, drawingContext, JointType.ElbowRight, JointType.WristRight);
            this.DrawBone(skeleton, drawingContext, JointType.WristRight, JointType.HandRight);

            // Left Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipLeft, JointType.KneeLeft);
            this.DrawBone(skeleton, drawingContext, JointType.KneeLeft, JointType.AnkleLeft);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleLeft, JointType.FootLeft);

            // Right Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipRight, JointType.KneeRight);
            this.DrawBone(skeleton, drawingContext, JointType.KneeRight, JointType.AnkleRight);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleRight, JointType.FootRight);

            // Render Joints
            foreach (Joint joint in skeleton.Joints)
            {
                Brush drawBrush = null;

                if (joint.TrackingState == JointTrackingState.Tracked)
                {
                    drawBrush = this.trackedJointBrush;
                }
                else if (joint.TrackingState == JointTrackingState.Inferred)
                {
                    drawBrush = this.inferredJointBrush;
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, this.SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
                }
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            PostureRecognition <Skeleton, string> postureRecognition = new PostureRecognition <Skeleton, string>(PatternType.AnglePatternElbowKnee, DataTrainingType.DataTrainingFile, 1000000);

            FileStream fs = new FileStream("Test2.txt", FileMode.Create);
            // First, save the standard output.
            TextWriter   tmp = Console.Out;
            StreamWriter sw  = new StreamWriter(fs);

            Console.SetOut(sw);
            Console.WriteLine("ITERACION : " + postureRecognition.training() + "-------------------------------------------------------\n");
            Console.WriteLine("VIDEO1 " + "-------------------------------------------------------");

            File.WriteAllBytes("save.dat", ToByteArray(postureRecognition));
            var lista = FromByteArray <List <Skeleton> >(File.ReadAllBytes("TRAINING_DATA2/video"));

            foreach (Skeleton skel in lista)
            {
                var x = postureRecognition.Predict(skel);
                if (x != null && x.Length > 0)
                {
                    Console.WriteLine(x);
                }
            }

            //Console.WriteLine("VIDEO2 " + "-------------------------------------------------------");
            //lista = FromByteArray<List<Skeleton>>(File.ReadAllBytes("TRAINING_DATA2/video2"));
            //foreach (Skeleton skel in lista)
            //{
            //    var x = postureRecognition.Predict(skel);
            //    if (x != null && x.Length > 0)
            //        Console.WriteLine(x);
            //    else
            //    {
            //        Console.WriteLine("NO RECONOCIDO");
            //    }
            //}
            Console.SetOut(tmp);
            sw.Close();
        }
예제 #3
0
        static void Main(string[] args)
        {
            PostureRecognition <Skeleton, string> postureRecognition = new PostureRecognition <Skeleton, string>(PatternType.AnglePatternElbowKnee, DataTrainingType.DataTrainingFile, 100000);

            //1000000
            //Console.WriteLine("MOSTRANDO DATOS BRUTOS" + "---------------------------------------------------");
            //List<Pose> poselist = LoadData("TRAINING_DATA3");
            //printPoses(poselist);
            //Console.WriteLine("ITERACION : " + postureRecognition.training() + "-------------------------------------------------------\n");

            Console.WriteLine("TESTING" + "-------------------------------------------------------");

            postureRecognition = ReadWriteObjectFile.FromByteArray <PostureRecognition <Skeleton, string> >(Convert.FromBase64String(DbServices.GetTrainingRed("octavo", "posture")));

            String folderPath = "TESTING";
            int    counter;

            foreach (string file in Directory.EnumerateFiles(folderPath, "*.TD"))
            {
                var readFile     = File.ReadAllBytes(file);
                var skeletonList = ReadWriteObjectFile.FromByteArray <List <Skeleton> >(readFile);
                counter = 0;
                foreach (Skeleton skel in skeletonList)
                {
                    if (counter == 7)
                    {
                        break;
                    }
                    var x = postureRecognition.Predict(skel);
                    if (x != null && x.Length > 0)
                    {
                        Console.Write(x + "\n");
                    }
                    counter++;
                }
            }
        }
        private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
        {
            // Render Torso
            this.DrawBone(skeleton, drawingContext, JointType.Head, JointType.ShoulderCenter);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderLeft);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderRight);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.Spine);
            this.DrawBone(skeleton, drawingContext, JointType.Spine, JointType.HipCenter);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipLeft);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipRight);

            // Left Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderLeft, JointType.ElbowLeft);
            //LeftHand.Text = skeleton.Joints[JointType.ShoulderLeft].Position.X.ToString();
            Estado.Text = postureRecognition.Predict(skeleton);
            ////currentPosition = Estado.Text;
            //try
            //{
            //    string message = Estado.Text;
            //    if (message != null && message.Length > 0)
            //    {
            //        if (!anterior.Equals(message))
            //        {
            //            ipAdress = System.Net.IPAddress.Parse("127.0.0.1");
            //            ipEndpoint = new IPEndPoint(ipAdress, 19834);

            //            client = new Socket(ipAdress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            //            client.Connect(ipEndpoint);
            //            byte[] sendmsg = Encoding.ASCII.GetBytes(message);
            //            byte[] msgLength = BitConverter.GetBytes(Convert.ToUInt32(sendmsg.Length));
            //            client.Send(msgLength);
            //            client.Send(sendmsg);
            //            client.Close();
            //            anterior = message;
            //        }
            //    }
            //}
            //catch (Exception e)
            //{
            //}

            if (flag)
            {
                lista.Add(skeleton);
            }
            this.DrawBone(skeleton, drawingContext, JointType.ElbowLeft, JointType.WristLeft);
            this.DrawBone(skeleton, drawingContext, JointType.WristLeft, JointType.HandLeft);

            // Right Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderRight, JointType.ElbowRight);
            this.DrawBone(skeleton, drawingContext, JointType.ElbowRight, JointType.WristRight);
            this.DrawBone(skeleton, drawingContext, JointType.WristRight, JointType.HandRight);

            // Left Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipLeft, JointType.KneeLeft);
            this.DrawBone(skeleton, drawingContext, JointType.KneeLeft, JointType.AnkleLeft);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleLeft, JointType.FootLeft);

            // Right Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipRight, JointType.KneeRight);
            this.DrawBone(skeleton, drawingContext, JointType.KneeRight, JointType.AnkleRight);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleRight, JointType.FootRight);

            // Render Joints
            foreach (Joint joint in skeleton.Joints)
            {
                Brush drawBrush = null;

                if (joint.TrackingState == JointTrackingState.Tracked)
                {
                    drawBrush = this.trackedJointBrush;
                }
                else if (joint.TrackingState == JointTrackingState.Inferred)
                {
                    drawBrush = this.inferredJointBrush;
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, this.SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
                }
            }
        }