Esempio n. 1
0
        /// <summary>
        /// Event handler for Kinect sensor's SkeletonFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            if(visible)
            {
                Skeleton[] skeletons = new Skeleton[0];

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

                foreach (Skeleton skeleton in skeletons)
                {
                    if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        Puntos handRight = new Puntos();
                        handRight.x = skeleton.Joints[JointType.HandRight].Position.X;
                        handRight.y = skeleton.Joints[JointType.HandRight].Position.Y;
                        handRight.z = skeleton.Joints[JointType.HandRight].Position.Z;

                        Puntos handLeft = new Puntos();
                        handLeft.x = skeleton.Joints[JointType.HandLeft].Position.X;
                        handLeft.y = skeleton.Joints[JointType.HandLeft].Position.Y;
                        handLeft.z = skeleton.Joints[JointType.HandLeft].Position.Z;

                        Puntos elbowRight = new Puntos();
                        elbowRight.x = skeleton.Joints[JointType.ElbowRight].Position.X;
                        elbowRight.y = skeleton.Joints[JointType.ElbowRight].Position.Y;
                        elbowRight.z = skeleton.Joints[JointType.ElbowRight].Position.Z;

                        Puntos elbowLeft = new Puntos();
                        elbowLeft.x = skeleton.Joints[JointType.ElbowLeft].Position.X;
                        elbowLeft.y = skeleton.Joints[JointType.ElbowLeft].Position.Y;
                        elbowLeft.z = skeleton.Joints[JointType.ElbowLeft].Position.Z;

                        Puntos kneeRight = new Puntos();
                        kneeRight.x = skeleton.Joints[JointType.KneeRight].Position.X;
                        kneeRight.y = skeleton.Joints[JointType.KneeRight].Position.Y;
                        kneeRight.z = skeleton.Joints[JointType.KneeRight].Position.Z;

                        Puntos kneeLeft = new Puntos();
                        kneeLeft.x = skeleton.Joints[JointType.KneeLeft].Position.X;
                        kneeLeft.y = skeleton.Joints[JointType.KneeLeft].Position.Y;
                        kneeLeft.z = skeleton.Joints[JointType.KneeLeft].Position.Z;

                        Puntos shoulderRight = new Puntos();
                        kneeRight.x = skeleton.Joints[JointType.ShoulderRight].Position.X;
                        kneeRight.y = skeleton.Joints[JointType.ShoulderRight].Position.Y;
                        kneeRight.z = skeleton.Joints[JointType.ShoulderRight].Position.Z;

                        Puntos shoulderLeft = new Puntos();
                        kneeLeft.x = skeleton.Joints[JointType.ShoulderLeft].Position.X;
                        kneeLeft.y = skeleton.Joints[JointType.ShoulderLeft].Position.Y;
                        kneeLeft.z = skeleton.Joints[JointType.ShoulderLeft].Position.Z;

                        Puntos footRight = new Puntos();
                        footRight.x = skeleton.Joints[JointType.FootRight].Position.X;
                        footRight.y = skeleton.Joints[JointType.FootRight].Position.Y;
                        footRight.z = skeleton.Joints[JointType.FootRight].Position.Z;

                        Puntos footLeft = new Puntos();
                        footLeft.x = skeleton.Joints[JointType.FootLeft].Position.X;
                        footLeft.y = skeleton.Joints[JointType.FootLeft].Position.Y;
                        footLeft.z = skeleton.Joints[JointType.FootLeft].Position.Z;

                        Puntos shoulderCenter = new Puntos();
                        shoulderCenter.x = skeleton.Joints[JointType.ShoulderCenter].Position.X;
                        shoulderCenter.y = skeleton.Joints[JointType.ShoulderCenter].Position.Y;
                        shoulderCenter.z = skeleton.Joints[JointType.ShoulderCenter].Position.Z;

                        Puntos spine = new Puntos();
                        spine.x = skeleton.Joints[JointType.Spine].Position.X;
                        spine.y = skeleton.Joints[JointType.Spine].Position.Y;
                        spine.z = skeleton.Joints[JointType.Spine].Position.Z;

                        if (recto && correcto)
                        {
                            if (posic1)
                            {
                                //Cambiamos visualizacion de puntos
                                if (posic2)
                                {
                                    this.textblock.Text = "Genial. Has realizado todos los pasos correctamente.";
                                }
                                else
                                {
                                    this.textblock.Text = "Debe llevar la mano derecha hasta el circulo superior.";
                                    if (Posic2(handRight, handLeft))
                                    {
                                        this.textblock.Text = "";
                                        posic2 = true;
                                    }
                                }
                            }
                            else
                            {
                                this.textblock.Text = "Debe colocar las manos en los circulos.";
                                if (Posic1(handRight, handLeft))
                                {
                                    this.textblock.Text = "";
                                    posic1 = true;
                                }
                            }
                        }
                        else
                        {
                            this.textblock.Text = "Pongase lo mas recto posible. Cuando este bien apareceran unos circulos";
                            if (Recto(kneeRight, kneeLeft, footRight, footLeft, shoulderLeft, shoulderRight))
                            {
                                this.textblock.Text = "";
                                recto = true;
                            }
                        }

                        //Controlador de color de margen
                        float distancia = spine.z * 2 ;
                        int valor = 25 * (int)distancia;

                        byte red = Convert.ToByte(225 - valor);
                        byte green = Convert.ToByte(25 + valor);
                        correcto = false;
                        if (distancia > 6)
                        {
                            red = Convert.ToByte(25 + valor);
                            green = Convert.ToByte(225 - valor);
                        }
                        if (red == 100 && green == 150)
                        {
                            correcto = true;
                        }
                        SolidColorBrush scb = new SolidColorBrush(Color.FromArgb(255, red, green, 0));
                        this.grid.Background = scb;

                        this.button.BorderBrush = scb;
                        this.button.Background = new SolidColorBrush(Color.FromArgb(255, red, green, 0));

                    }
                }

                using (DrawingContext dc = this.drawingGroup.Open())
                {
                    // Draw a transparent background to set the render size
                    dc.DrawRectangle(Brushes.Transparent, 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);
                                //-------------------------------------------
                                Pen redPen = new Pen(Brushes.Red, 3);
                                Pen greenPen = new Pen(Brushes.Green, 3);

                                //LLamada al detector y visualizador de ayudas
                                if (recto && correcto)
                                {

                                    if (!posic1)
                                    {
                                        dc.DrawEllipse(Brushes.Transparent, redPen, pHombroD, 15, 15);
                                        dc.DrawEllipse(Brushes.Transparent, redPen, pHombroI, 15, 15);
                                    }
                                    else
                                    {

                                        //Cambiamos visualizacion de puntos
                                        if (posic2)
                                        {
                                            dc.DrawEllipse(Brushes.Transparent, greenPen, pHombroD, 15, 15);
                                            dc.DrawEllipse(Brushes.Transparent, greenPen, pHombroI, 15, 15);
                                            dc.DrawEllipse(Brushes.Transparent, greenPen, pArribaD, 15, 15);

                                            this.textblock.Text = "Genial. Has realizado todos los pasos correctamente.";
                                        }
                                        else
                                        {
                                            dc.DrawEllipse(Brushes.Transparent, greenPen, pHombroD, 15, 15);
                                            dc.DrawEllipse(Brushes.Transparent, greenPen, pHombroI, 15, 15);
                                            dc.DrawEllipse(Brushes.Transparent, redPen, pArribaD, 15, 15);
                                        }
                                    }
                                }

                                //this.textblock.Text = "Lo estas haciendo bien";
                            }
                            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));
                }
            }
        }
Esempio n. 2
0
        //Detect que el usuario este recto. Sirve para saber donde se tienen que colocar las manos al hacer la postura y el gesto.
        bool Recto(Puntos kneeRight, Puntos kneeLeft, Puntos footRight, Puntos footLeft, Puntos shoulderLeft, Puntos shoulderRight)
        {
            bool post = true;

            //Controla que manos y codos esten a la misma profundidad
            if (Math.Abs(shoulderRight.z - shoulderLeft.z) > 0.005f || Math.Abs(shoulderRight.y - shoulderLeft.y) > 0.1f)
            {
                post = false;
            }

            if (distance(kneeRight.x, footRight.x) > 0.2f || distance(kneeLeft.x, footLeft.x) > 0.2f ||
                Math.Abs(kneeRight.y - kneeLeft.y) > 0.2f || Math.Abs(footRight.y - footLeft.y) > 0.2f)
            {
                post = false;
            }

            return post;
        }
Esempio n. 3
0
        //Este es el controlador de la postura inicial
        bool Posic1(Puntos handRight, Puntos handLeft)
        {
            bool post = true;

            if (Math.Abs(handRight.y - pauxD.y) > 0.06f*precision || Math.Abs(handLeft.y - pauxI.y) > 0.06f*precision
                || Math.Abs(handRight.x - pauxD.x) > 0.05f*precision || Math.Abs(handLeft.x - pauxI.x) > 0.05f*precision)
            {

                post = false;
            }

            return post;
        }
Esempio n. 4
0
        //Controlador del gesto.
        bool Posic2(Puntos handRight, Puntos handLeft)
        {
            bool post = true;
            if (Math.Abs(handRight.y - pArrD.y) > 0.1f*precision || Math.Abs(handLeft.y - pauxI.y) > 0.06f*precision
                || Math.Abs(handRight.x - pArrD.x) > 0.1f*precision || Math.Abs(handLeft.x - pauxI.x) > 0.05f*precision)
            {
                //this.button.Content = Math.Abs(handRight.y - pauxD.y).ToString();
                post = false;
            }

            return post;
        }
Esempio n. 5
0
        /// <summary>
        /// Event handler for Kinect sensor's SkeletonFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            Skeleton[] skeletons = new Skeleton[0];
                puntocomp = new Point(40, 40);
                using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
                {
                    if (skeletonFrame != null)
                    {
                        skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                        skeletonFrame.CopySkeletonDataTo(skeletons);
                    }
                }

                foreach (Skeleton skeleton in skeletons)
                {
                    if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        Puntos spine = new Puntos();
                        spine.x = skeleton.Joints[JointType.Spine].Position.X;
                        spine.y = skeleton.Joints[JointType.Spine].Position.Y;
                        spine.z = skeleton.Joints[JointType.Spine].Position.Z;

                        //Controlador de color de margen
                        float distancia = spine.z * 2;
                        int valor = 25 * (int)distancia;

                        byte red = Convert.ToByte(225 - valor);
                        byte green = Convert.ToByte(25 + valor);
                        correcto = false;
                        if (distancia > 6)
                        {
                            red = Convert.ToByte(25 + valor);
                            green = Convert.ToByte(225 - valor);
                        }
                        if (red == 100 && green == 150)
                        {
                            correcto = true;
                        }
                        SolidColorBrush scb = new SolidColorBrush(Color.FromArgb(255, red, green, 0));
                        this.grid.Background = scb;

                        Point pr = SkeletonPointToScreen(skeleton.Joints[JointType.HandRight].Position);
                        Point pl = SkeletonPointToScreen(skeleton.Joints[JointType.HandLeft].Position);

                        if (tocarCaptura(pr, pl, puntocomp) && contadorCaptura >= 50 )
                        {
                            captura = true;
                            textblock.Text = "Colocate en la posicion que quieras.";
                        }

                        if (captura && !tocarCaptura(pr, pl, puntocomp))
                        {
                            int temp = 5;

                            textblock.Text = "La foto se realizara en " + temp + " segundos.";

                            this.dispathcer.Tick += (s, a) =>
                            {
                                temp--;

                                textblock.Text = "La foto se realizara en " + temp + " segundos.";
                                if (temp == 0)
                                {

                                    BitmapEncoder encoder = new PngBitmapEncoder();
                                    encoder.Frames.Add(BitmapFrame.Create(this.colorBitmap));
                                    //string nombre = "Foto" + DateTime.Now.ToString() + ".png";
                                    string time = System.DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat);
                                    string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Foto-" + time +".png");
                                    try
                                    {
                                        using (FileStream fs = new FileStream(path, FileMode.Create))
                                        {
                                            encoder.Save(fs);

                                        }
                                    }
                                    catch (IOException ioe)
                                    {
                                        Console.WriteLine(ioe.ToString());
                                    }

                                    textblock.Text = "";
                                    this.dispathcer.Stop();
                                }

                            };

                            this.dispathcer.Start();
                            captura = false;
                        }

                        if (tocarDepth(pr, pl) && contadorDepth >= 50)
                        {
                            cambioVisualizacion("depth");
                        }
                        if (tocarInfrared(pr, pl) && contadorInfrared >= 50)
                        {
                            cambioVisualizacion("infrared");
                        }
                        if (tocarVideo(pr, pl) && contadorVideo >= 50)
                        {
                            cambioVisualizacion("color");
                        }

                        if (tocarSlider(pr) && contadorSlider >= 25)
                        {
                            if (!slider)
                            {
                                slider = true;
                            }
                            Point aux = SkeletonPointToScreen(skeleton.Joints[JointType.HandRight].Position);

                            if (aux.Y < 75.0)
                            {
                                handY = 75.0;
                            }
                            else if (aux.Y > 425.0)
                            {
                                handY = 425.0;
                            }
                            else
                            {
                                handY = aux.Y;

                            }
                        }
                        else if(slider){
                            slider = false;
                            angule = -27 + (int)Math.Round(54.0 * (425 - handY) / 350);
                            cambioAngulo();
                        }

                    }
                }

                using (DrawingContext dc = this.drawingGroup.Open())
                {
                    Pen pen = new Pen(Brushes.Green, 3);

                    dc.DrawEllipse(Brushes.Transparent, pen, puntocomp, 30, 30);
                    // Draw a transparent background to set the render size
                    dc.DrawRectangle(Brushes.Transparent, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                    dc.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Gray, 3), new Rect(0.0, 390.0, 150.0, 130.0));
                    dc.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Gray, 3), new Rect(150.0, 390.0, 150.0, 130.0));
                    dc.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Gray, 3), new Rect(300.0, 390.0, 150.0, 130.0));

                    dc.DrawRectangle(Brushes.White, new Pen(Brushes.Gray, 3), new Rect(560.0, 75.0, 10.0, 350.0));

                    dc.DrawRectangle(Brushes.White, new Pen(Brushes.Gray, 3), new Rect(540.0, handY, 50.0, 20.0));

                    dc.DrawRectangle(Brushes.Gray, null, new Rect(40.0, 425.0, 75.0, 30.0));
                    dc.DrawRectangle(Brushes.Gray, null, new Rect(190.0, 425.0, 75.0, 30.0));
                    dc.DrawRectangle(Brushes.Gray, null, new Rect(340.0, 425.0, 70.0, 30.0));

                    FormattedText fText = new FormattedText("Color", System.Globalization.CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 24, Brushes.Black);
                    FormattedText fText2 = new FormattedText("Depth", System.Globalization.CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 24, Brushes.Black);
                    FormattedText fText3 = new FormattedText("IR", System.Globalization.CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 24, Brushes.Black);

                    dc.DrawText(fText, new Point(45.0, 425.0));
                    dc.DrawText(fText2, new Point(190.0, 425.0));
                    dc.DrawText(fText3, new Point(360.0, 425.0));
                    // prevent drawing outside of our render area
                    this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
                }
        }