コード例 #1
0
 public DifficultyCalculator()
 {
     Aiming   = new Aiming();
     Clicking = new Clicking();
     Reading  = new Reading();
     Skills.Add(Aiming);
     Skills.Add(Clicking);
     Skills.Add(Reading);
 }
コード例 #2
0
 public void Click()
 {
     Clicking?.Invoke(this, new ComponentActionEventArgs(this));
     WrappedElement.Click();
     Clicked?.Invoke(this, new ComponentActionEventArgs(this));
 }
コード例 #3
0
        public void OnFrame(object sender, FrameEventArgs args)
        {
            // Obtener el frame actual.
            Frame  currentFrame = controller.Frame();
            Vector center;

            center.x = 0;
            center.y = 0;
            center.z = 0;
            Vector size;

            size.x = 1000;
            size.y = 1000;
            size.z = 1000;


            currentTime = currentFrame.Timestamp;
            timeChange  = currentTime - previousTime;

            if (timeChange > 1000)
            {
                if (currentFrame.Hands.Count() > 0)
                {
                    // Consigue el primer dedo en la lista de dedos
                    Finger finger = controller.Frame().Hands[0].Fingers[1];

                    InteractionBox screen = new InteractionBox(center, size);
                    screen = controller.Frame().InteractionBox;
                    //textBox2.AppendText("tipo de dedo : "+ finger.Type);



                    // if (screen.IsValid)
                    if (!screen.IsValid)
                    {
                        // Obtenga la velocidad de la punta del dedo
                        var tipVelocity = (int)finger.TipVelocity.Magnitude;

                        // Use tipVelocity para reducir el pulso
                        // the cursor steady if (tipVelocity > 25)
                        if (tipVelocity < 25)
                        {
                            leapStart = (float)numericUpDown9.Value;
                            leapEnd   = (float)numericUpDown10.Value;
                            appStart  = (float)numericUpDown11.Value;
                            appEnd    = (float)numericUpDown12.Value;

                            leapPoint = finger.StabilizedTipPosition;

                            leapStarty = (float)numericUpDown17.Value;
                            leapEndy   = (float)numericUpDown18.Value;
                            appStarty  = (float)numericUpDown15.Value;
                            appEndy    = (float)numericUpDown16.Value;


                            leapPoint        = finger.StabilizedTipPosition;
                            pendienteX       = (appEnd - appStart) / (leapEnd - leapStart);
                            xScreenIntersect = screen.NormalizePoint(leapPoint, true).x;
                            yScreenIntersect = screen.NormalizePoint(leapPoint, true).y;
                            zScreenIntersect = screen.NormalizePoint(leapPoint, true).z;
                            //xScreenIntersect *= 0.7f;
                            //yScreenIntersect *= 1.5f;
                            xScreenIntersect *= (float)numericUpDown1.Value;
                            yScreenIntersect *= (float)numericUpDown2.Value;
                            zScreenIntersect *= (float)numericUpDown7.Value;

                            xScreenIntersect -= (float)numericUpDown3.Value;
                            yScreenIntersect -= (float)numericUpDown4.Value;
                            zScreenIntersect -= (float)numericUpDown8.Value;



                            if (xScreenIntersect.ToString() != "NaN")
                            {
                                /*if (leapPoint.x > 0)
                                 * {
                                 *  xTrans = leapStart - leapPoint.x;
                                 * }
                                 * else
                                 * {
                                 *  xTrans = leapStart - leapPoint.x;
                                 * }
                                 *
                                 * if (leapPoint.y > 0)
                                 * {
                                 *  yTrans = leapStarty - leapPoint.y;
                                 * }
                                 * else
                                 * {
                                 *  yTrans = leapStarty - leapPoint.y;
                                 * }*/
                                //x = (int)(xScreenIntersect * screen.Width);
                                //y = (int)(screen.Height - (yScreenIntersect * screen.Height));

                                if (clickState == 0)
                                {
                                    int extendedFingers = 0;
                                    for (int f = 0; f < controller.Frame().Hands[0].Fingers.Count; f++)
                                    {
                                        Finger digit = controller.Frame().Hands[0].Fingers[f];
                                        if (digit.IsExtended)
                                        {
                                            extendedFingers++;
                                        }
                                    }

                                    if (extendedFingers == 1)
                                    {
                                        textBox2.AppendText("Click 1");
                                        nClick++;
                                    }
                                    else
                                    {
                                        textBox2.AppendText("_");
                                        nClick = 0;
                                    }
                                    if (nClick == 3)
                                    {
                                        Clicking.SendClick(x, y);
                                        nClick     = 0;
                                        clickState = 1;
                                    }
                                }

                                if (clickState == 1)
                                {
                                    int extendedFingers = 0;
                                    for (int f = 0; f < controller.Frame().Hands[0].Fingers.Count; f++)
                                    {
                                        Finger digit = controller.Frame().Hands[0].Fingers[f];
                                        if (digit.IsExtended)
                                        {
                                            extendedFingers++;
                                        }
                                    }

                                    if (extendedFingers == 5)
                                    {
                                        textBox2.AppendText("upClick 1");
                                        nClick++;
                                    }
                                    else
                                    {
                                        textBox2.AppendText("_");
                                        nClick = 0;
                                    }
                                    if (nClick == 3)
                                    {
                                        Clicking.SendUpClick(x, y);
                                        nClick     = 0;
                                        clickState = 0;
                                    }
                                }

                                if (checkBox1.Checked)
                                {
                                    x = (int)Math.Abs((leapPoint.x - leapStart) * ((appEnd - appStart) / (leapEnd - leapStart)) + appStart);
                                }
                                else
                                {
                                    x = Math.Abs((int)((float)numericUpDown5.Value * (float)numericUpDown1.Value - xScreenIntersect * (float)numericUpDown5.Value * (float)numericUpDown1.Value + (float)numericUpDown13.Value));
                                    //x = (int)(xScreenIntersect * (float)numericUpDown5.Value);
                                    //textBox1.AppendText("Cambio de posicion de x1 " + (int)appStart + (float)numericUpDown11.Value);// valor de appstart y numericupdown11
                                }

                                if (checkBox2.Checked)
                                {
                                    y = (int)Math.Abs((leapPoint.z - leapStarty) * ((appEndy - appStarty) / (leapEndy - leapStarty)) + appStarty);
                                }
                                else
                                {
                                    //y = (int)((float)numericUpDown6.Value - (yScreenIntersect * (float)numericUpDown6.Value) + (float)numericUpDown14.Value);
                                    //y = (int)(yScreenIntersect * (float)numericUpDown6.Value + (float)numericUpDown14.Value);
                                    y = 500;
                                }
                                //x = x * flipX;

                                //x = (int)((leapPoint.x - leapStart)*(leapEnd-leapStart)*(appEnd-appStart)+appStart);


                                //textBox1. AppendText("Screen intersect X: " + xScreenIntersect.ToString());
                                //textBox1.AppendText("Screen intersect Y: " + yScreenIntersect.ToString());
                                //textBox1.AppendText("Width pixels: " + screen.Width.ToString());
                                //textBox1.AppendText("Height pixels: " + screen.Height .ToString());

                                //textBox1.AppendText("\n");

                                // textBox1.AppendText("x: " + x.ToString());
                                //textBox1.AppendText("y: " + y.ToString());

                                //textBox1.AppendText("\n");

                                // textBox1.AppendText("Tip velocity: " + tipVelocity.ToString());

                                // Move the cursor
                                MouseCursor.MoveCursor(x, y);

                                //textBox1.AppendText("\n" + new String('=', 40) + "\n");
                            }
                        }
                    }
                }

                previousTime = currentTime;
            }



            // Obtiene el marco más reciente e informa información básica
            Frame frame = args.frame;

            Console.WriteLine(
                "Frame id: {0}, timestamp: {1}, hands: {2}",
                frame.Id, frame.Timestamp, frame.Hands.Count
                );


            foreach (Hand hand in frame.Hands)
            {
                if (hand.Fingers.Count == 1)
                {
                    this.label18.Text = hand.Fingers[0].TipPosition.ToString();
                }
                this.label18.Text = hand.Fingers[0].TipPosition.ToString();



                Console.WriteLine("  Hand id: {0}, palm position: {1}, fingers: {2}",
                                  hand.Id, hand.PalmPosition, hand.Fingers.Count);
                this.label15.Text = hand.Id.ToString();
                this.label5.Text  = hand.PalmPosition.ToString();
                handX             = hand.PalmPosition.x;
                handY             = hand.PalmPosition.y;
                handZ             = hand.PalmPosition.z;
                this.label7.Text  = hand.Fingers.Count.ToString();
                // Obtiene el vector y la dirección normal de la mano
                Vector normal    = hand.PalmNormal;
                Vector direction = hand.Direction;

                // Calcule los ángulos de pitch, roll y yaw de la mano.
                Console.WriteLine(
                    "  Hand pitch: {0} degrees, roll: {1} degrees, yaw: {2} degrees",
                    direction.Pitch * 180.0f / (float)Math.PI,
                    normal.Roll * 180.0f / (float)Math.PI,
                    direction.Yaw * 180.0f / (float)Math.PI
                    );

                this.label13.Text = (direction.Pitch * 180.0f / (float)Math.PI).ToString();
                this.label11.Text = (normal.Roll * 180.0f / (float)Math.PI).ToString();
                this.label9.Text  = (direction.Yaw * 180.0f / (float)Math.PI).ToString();
                this.label21.Text = x.ToString();
                this.label19.Text = y.ToString();
                this.label28.Text = xLeap1.ToString();
                this.label29.Text = yLeap1.ToString();
                this.label30.Text = xLeap2.ToString();
                this.label33.Text = yLeap2.ToString();
                this.label32.Text = xLeap3.ToString();
                this.label31.Text = yLeap3.ToString();
                this.label46.Text = xTrans.ToString();
                this.label48.Text = pendienteX.ToString();


                //Obtiene el hueso del brazo
                Arm arm = hand.Arm;
                Console.WriteLine(
                    "  Arm direction: {0}, wrist position: {1}, elbow position: {2}",
                    arm.Direction, arm.WristPosition, arm.ElbowPosition
                    );

                // Obtiene los dedos
                foreach (Finger finger in hand.Fingers)
                {
                    Console.WriteLine(
                        "    Finger id: {0}, {1}, length: {2}mm, width: {3}mm",
                        finger.Id,
                        finger.Type.ToString(),
                        finger.Length,
                        finger.Width
                        );



                    // Obtiene huesos de los dedos
                    Bone bone;
                    for (int b = 0; b < 4; b++)
                    {
                        bone = finger.Bone((Bone.BoneType)b);
                        Console.WriteLine(
                            "      Bone: {0}, start: {1}, end: {2}, direction: {3}",
                            bone.Type, bone.PrevJoint, bone.NextJoint, bone.Direction
                            );
                    }
                }
            }

            if (frame.Hands.Count != 0)
            {
                Console.WriteLine("");
            }
        }
        public Image <Bgr, byte> Capture_ImageGrabbed(VideoCapture captureGesture, float SStartX, float SEndX, float AStartX, float AEndX, float SStartY, float SEndY, float AStartY, float AEndY)
        {
            //try
            //{
            Mat m = new Mat();

            captureGesture.Retrieve(m);

            if (plugin == null)
            {
                return(m.ToImage <Bgr, byte>());
            }
            else
            {
                imageOut = plugin.RunPlugin(captureGesture).ToImage <Bgr, byte>();
                sensorX  = plugin.Center.X;
                sensorY  = plugin.Center.Y;

                if (plugin.DetectGesture)
                {
                    sensorStart = SStartX;
                    sensorEnd   = SEndX;
                    appStart    = AStartX;
                    appEnd      = AEndX;

                    sensorStarty = (float)SStartY;
                    sensorEndy   = (float)SEndY;
                    appStarty    = (float)AStartY;
                    appEndy      = (float)AEndY;



                    if (activeX)
                    {
                        xFinal = (int)Math.Abs((plugin.Center.X - sensorStart) * ((appEnd - appStart) / (sensorEnd - sensorStart)) + appStart);
                    }
                    else
                    {
                        xFinal = plugin.Center.X;
                    }

                    if (activeY)
                    {
                        yFinal = (int)Math.Abs((plugin.Center.Y - sensorStarty) * ((appEndy - appStarty) / (sensorEndy - sensorStarty)) + appStarty);
                    }
                    else
                    {
                        yFinal = plugin.Center.Y;
                    }
                    if (mouseRecOn)
                    {
                        MouseCursor.MoveCursor(xFinal, yFinal);
                    }
                    Console.WriteLine("X Y :" + xFinal + "," + yFinal);


                    if (!clickDown && plugin.AutoClick)
                    {
                        Clicking.SendClick(xFinal, yFinal);
                        Console.WriteLine("     Gesture recognition Click down (autoclick)");
                        clickDown = true;
                        respX     = plugin.Center.X;
                        respY     = plugin.Center.Y;
                    }

                    if (!plugin.AutoClick)
                    {
                        if (plugin.DetectClick && clickDown)
                        {
                            Clicking.SendClick(xFinal, yFinal);
                            Console.WriteLine("     Gesture recognition Click down");
                            clickDown = false;
                        }
                        if (!plugin.DetectClick && !clickDown)
                        {
                            Clicking.SendUpClick(xFinal, yFinal);
                            Console.WriteLine("     Gesture recognition Click up");
                            clickDown = true;
                        }
                    }
                }
                else
                {
                    if (clickDown && plugin.AutoClick)
                    {
                        Clicking.SendUpClick(xFinal, yFinal);
                        Console.WriteLine("     Gesture recognition Click up(autoclick)");

                        if (plugin.AutoCamCapture)
                        {
                            //Disparo de evento al finalizar una seleccion rectangular
                            // si el plugin AutoCamCapture lo permite
                            rectangularSelection.X      = plugin.Center.X;
                            rectangularSelection.Y      = plugin.Center.Y;
                            rectangularSelection.Width  = Math.Abs(respX - plugin.Center.X);
                            rectangularSelection.Height = Math.Abs(respY - plugin.Center.Y);
                            selectedRectangle(rectangularSelection);
                        }
                        clickDown = false;
                    }
                }
            }

            return(imageOut);
        }