Exemplo n.º 1
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();
        }
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Create the drawing group we'll use for drawing
            this.drawingGroup = new DrawingGroup();

            // Create an image source that we can use in our image control
            this.imageSource = new DrawingImage(this.drawingGroup);

            // Display the drawing using our image control
            Image.Source = this.imageSource;

            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser).
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                TransformSmoothParameters smoothingParam = new TransformSmoothParameters();

                smoothingParam.Smoothing          = 0.7f;
                smoothingParam.Correction         = 0.3f;
                smoothingParam.Prediction         = 1.0f;
                smoothingParam.JitterRadius       = 1.0f;
                smoothingParam.MaxDeviationRadius = 1.0f;
                // Turn on the skeleton stream to receive skeleton frames
                this.sensor.SkeletonStream.Enable(smoothingParam);

                // Add an event handler to be called whenever there is new color frame data
                this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                //------------------------------------------------ CREATE AND SAVE TRAINING RED----------------------------------------
                postureRecognition = new PostureRecognition <Skeleton, string>(PatternType.AnglePatternElbowKnee, DataTrainingType.DataTrainingFile, 100000);
                postureRecognition.training();
                string code = Convert.ToBase64String(ReadWriteObjectFile.ObjectToByteArray(postureRecognition));
                DbServices.AddTrainingRed("noveno", code, "posture");
                //---------------------------------------------------------------------------------------------------------------------
                //------------------------------------------------ LOAD TRAINIG RED FROM DATABASE -------------------------------------
                //postureRecognition = ReadWriteObjectFile.FromByteArray<PostureRecognition<Skeleton, string>>(Convert.FromBase64String(DbServices.GetTrainingRed("seven", "posture")));
                //---------------------------------------------------------------------------------------------------------------------

                //ipAdress = System.Net.IPAddress.Parse("192.168.0.6");
                //ipEndpoint = new IPEndPoint(ipAdress, 19834);

                //client = new Socket(ipAdress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                //client.Connect(ipEndpoint);

                //ExecuteThreadServiceAsync();
                //StartSocketListenner();
                // Start the sensor!
                try
                {
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    this.sensor = null;
                }
            }

            /*
             * // Turn on the skeleton stream to receive skeleton frames
             * this.sensor.SkeletonStream.Enable();
             *
             *  // Add an event handler to be called whenever there is new color frame data
             *  this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;
             *
             *  // Start the sensor!
             *  try
             *  {
             *      this.sensor.Start();
             *  }
             *  catch (IOException)
             *  {
             *      this.sensor = null;
             *  }
             * }
             */

            if (null == this.sensor)
            {
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
            }
        }