Beispiel #1
0
 public static void Enter(PostureRecognition <Skeleton, string> postureRecognition, List <Skeleton> lista, string output)
 {
     foreach (Skeleton skel in lista)
     {
         postureRecognition.enterPosture(skel, output);
     }
 }
 public void PostureDataReady(Posture posture)
 {
     if (!training.isFinish())
     {
         if (PostureRecognition.matches(posture, training.getPosture()))
         {
             LogUtil.log("匹配成功。");
             nextPosture(true);
         }
     }
 }
Beispiel #3
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();
        }
        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++;
                }
            }
        }
Beispiel #5
0
        public static MyPostureTraining create1()
        {
            MyPostureTraining training = new MyPostureTraining();

            using (StreamReader sr = new StreamReader(Constant.BASE_PATH + "/data/data1/data.txt"))
            {
                for (int i = 1; i <= 9; i++)
                {
                    Posture           pos            = new Posture(PostureType.Both);
                    List <VectorType> vectorTypeList = PostureRecognition.getVectorTypeList(PostureType.Both);
                    pos.setPic(Constant.BASE_PATH + "/data/data1/" + i + "_color.jpg");

                    foreach (VectorType type in vectorTypeList)
                    {
                        string[] lineData = sr.ReadLine().Split(',');
                        pos.setVector(type, new Vector(double.Parse(lineData[0]), double.Parse(lineData[1]), double.Parse(lineData[2])));
                    }
                    sr.ReadLine();
                    training.PostureList.Add(pos);
                }
            }

            return(training);
        }
        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;
            }
        }
Beispiel #7
0
        private void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            if (pause)
            {
                return;
            }

            Skeleton[] skeletons = new Skeleton[0];

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }


            using (DrawingContext dc = this.drawingGroup.Open())
            {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                if (skeletons.Length != 0)
                {
                    foreach (Skeleton skel in skeletons)
                    {
                        RenderClippedEdges(skel, dc);

                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            this.DrawBonesAndJoints(skel, dc);


                            index++;

                            if (actionState)
                            {
                                BitmapSource colorFrame = (BitmapSource)this.colorImageElement.Source;
                                //BitmapSource skeletonFrame = (BitmapSource)this.skeletonImageElement.Source;


                                actionData.add(colorFrame, null, skel);
                            }

                            if (index == 30)
                            {
                                index = 0;
                                Posture posture = PostureRecognition.computePosture(skel, PostureType.Both);
                                Text_PostureData.Text = posture.toJsonString();
                            }
                        }
                        else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
                        {
                            dc.DrawEllipse(
                                this.centerPointBrush,
                                null,
                                this.SkeletonPointToScreen(skel.Position),
                                BodyCenterThickness,
                                BodyCenterThickness);
                        }
                    }
                }

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
            }
        }