Beispiel #1
0
        protected override void OnStep()
        {
            Point  origin      = (Point)GetVar("Origin");
            Point  size        = (Point)GetVar("Size");
            double sensivity   = (double)GetVar("Sensivity");
            bool   alwaysClick = (bool)GetVar("AlwaysClick");

            GloveHand lastRightSides = HandRecord.LastRightWithBothSides();
            GloveHand lastRightIndex = HandRecord.LastRightWithIndex();

            if (lastRightSides == null)
            {
                return;
            }

            Rectangle box = new Rectangle(origin.X, origin.Y, size.X, size.Y);

            if (Collision.Inside(box, lastRightSides.SideMiddlePoint)) //we can move
            {
                int ydiff = (int)((double)(lastRightSides.SideMiddlePoint.Y - origin.Y) / (double)size.Y * (double)Screen.PrimaryScreen.Bounds.Height);
                int xdiff = (int)((double)(size.X - (lastRightSides.SideMiddlePoint.X - origin.X)) / (double)size.X * (double)Screen.PrimaryScreen.Bounds.Width);
                Mouse.SetPos(xdiff, ydiff);
            }
            _lastPos = lastRightSides.SideMiddlePoint;
            if (alwaysClick || Collision.Inside(box, lastRightSides.SideMiddlePoint))
            {
                if (lastRightIndex != null && lastRightIndex.SideFingers.Length == 2)
                {
                    if (GeometryExt.Distance(lastRightIndex.SideFingers[0].LightCenter, lastRightIndex.SideFingers[1].LightCenter) >= size.X / 3.0)
                    {
                        if (Math.Abs(lastRightIndex.SideFingers[0].LightCenter.Y - lastRightIndex.SideFingers[1].LightCenter.Y) <
                            Math.Abs(lastRightIndex.SideFingers[0].LightCenter.X - lastRightIndex.SideFingers[1].LightCenter.X)) // i side sono messi in orizzontale
                        {
                            Mouse.Release(false);
                            if (lastRightIndex.IndexFinger.LightCenter.Y > lastRightIndex.SideMiddlePoint.Y)
                            {
                                Mouse.Press(true);
                            }
                            else
                            {
                                Mouse.Release(true);
                            }
                        }
                        else //in verticale
                        {
                            Mouse.Press(false);
                            if (lastRightIndex.IndexFinger.LightCenter.X > lastRightIndex.SideMiddlePoint.X)
                            {
                                Mouse.Press(true);
                            }
                            else
                            {
                                Mouse.Release(true);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
 private void Record(List <GloveHand> h, GloveHand hand)
 {
     h.Add(hand);
     while (h.Count > MaxHistory)
     {
         h.RemoveAt(0);
     }
 }
Beispiel #3
0
        protected override void OnDraw(ref Image <Bgr, Byte> src)
        {
            double maxDistMul  = (double)GetVar("MaxDistMul");
            double minDist     = (double)GetVar("MinDist");
            double verticalMul = (double)GetVar("VerticalMul");

            GloveHand lastSides = HandRecord.LastRightWithBothSides();

            if (lastSides == null)
            {
                return;
            }

            Bgr col  = new Bgr(0, 255, 0);
            Bgr col2 = new Bgr(0, 200, 0);

            if (GeometryExt.Distance(lastSides.SideFingers[0].LightCenter, lastSides.SideFingers[1].LightCenter) > minDist * maxDistMul)
            {
                col  = new Bgr(0, 0, 255);
                col2 = new Bgr(0, 0, 200);
            }
            if (GeometryExt.Distance(lastSides.SideFingers[0].LightCenter, lastSides.SideFingers[1].LightCenter) < minDist)
            {
                col  = new Bgr(200, 200, 200);
                col2 = new Bgr(150, 150, 150);
            }
            if (Math.Abs(lastSides.SideFingers[0].LightCenter.Y - lastSides.SideFingers[1].LightCenter.Y) >=
                Math.Abs(lastSides.SideFingers[0].LightCenter.X - lastSides.SideFingers[1].LightCenter.X) * verticalMul)         // i side sono messi in verticale
            {
                col2 = new Bgr(255, 0, 0);
            }

            if (lastSides.SideFingers.Length == 2)
            {
                System.Drawing.Point p1 = lastSides.SideFingers[0].LightCenter;
                System.Drawing.Point p2 = lastSides.SideFingers[1].LightCenter;
                float smallC            = ((float)GeometryExt.Distance(p1, p2) / 2) - 8;
                float bigC = ((float)GeometryExt.Distance(p1, p2) / 2) + 8;
                if (smallC < 0)
                {
                    smallC = 0;
                }
                if (bigC < 0)
                {
                    bigC = 0;
                }
                src.Draw(new CircleF(lastSides.SideMiddlePoint, smallC), col2, 3);
                src.Draw(new CircleF(lastSides.SideMiddlePoint, bigC), col, 3);
                src.Draw(new CircleF(lastSides.SideMiddlePoint, 5), new Bgr(255, 0, 255), -1);
            }
        }
Beispiel #4
0
        protected override Image <Bgr, Byte> OnDraw(Image <Bgr, Byte> src)
        {
            Point origin = (Point)GetVar("Origin");
            Point size   = (Point)GetVar("Size");

            Rectangle box            = new Rectangle(origin.X, origin.Y, size.X, size.Y);
            GloveHand lastRightSides = HandRecord.LastRightWithBothSides();

            if (lastRightSides != null && Collision.Inside(box, lastRightSides.SideMiddlePoint))
            {
                src.Draw(box, new Bgr(100, 100, 255), -1);
            }
            else
            {
                src.Draw(box, new Bgr(100, 100, 100), -1);
            }

            return(src);
        }
        protected override Image <Bgr, Byte> OnDraw(Image <Bgr, Byte> src)
        {
            Point middlePoint = (Point)GetVar("MiddlePoint");
            float deadZone    = (float)GetVar("DeadZone");

            src.Draw(new CircleF(middlePoint, deadZone), new Bgr(100, 100, 100), -1);
            src.Draw(new CircleF(middlePoint, (float)3), new Bgr(0, 0, 255), -1);

            GloveHand lastSides = HandRecord.LastRightWithBothSides();

            if (lastSides == null)
            {
                return(src);
            }

            if (GeometryExt.Distance(lastSides.SideMiddlePoint, middlePoint) > deadZone)
            {
                src.Draw(new LineSegment2D(lastSides.SideMiddlePoint, middlePoint), new Bgr(255, 0, 255), 3);
            }

            return(src);
        }
Beispiel #6
0
        protected override void OnDraw(ref Image <Bgr, Byte> src)
        {
            Point middlePoint = (Point)GetVar("MiddlePoint");
            float deadZone    = (float)GetVar("DeadZone");

            src.Draw(new CircleF(middlePoint, deadZone), new Bgr(100, 100, 100), -1);
            src.Draw(new CircleF(middlePoint, (float)3), new Bgr(0, 0, 255), -1);

            GloveHand lastSides = HandRecord.LastRightWithBothSides();

            if (lastSides == null)
            {
                return;
            }

            if (GeometryExt.Distance(lastSides.SideMiddlePoint, middlePoint) > deadZone)
            {
                src.Draw(new LineSegment2D(lastSides.SideMiddlePoint, middlePoint), new Bgr(255, 0, 255), 3);
            }

            if (lastSides.SideFingers.Length == 2)
            {
                System.Drawing.Point p1 = lastSides.SideFingers[0].LightCenter;
                System.Drawing.Point p2 = lastSides.SideFingers[1].LightCenter;
                float smallC            = ((float)GeometryExt.Distance(p1, p2) / 2) - 8;
                float bigC = ((float)GeometryExt.Distance(p1, p2) / 2) + 8;
                if (smallC < 0)
                {
                    smallC = 0;
                }
                if (bigC < 0)
                {
                    bigC = 0;
                }
                src.Draw(new CircleF(lastSides.SideMiddlePoint, smallC), new Bgr(0, 255, 0), 3);
                src.Draw(new CircleF(lastSides.SideMiddlePoint, bigC), new Bgr(0, 200, 0), 3);
                src.Draw(new CircleF(lastSides.SideMiddlePoint, 5), new Bgr(255, 0, 255), -1);
            }
        }
Beispiel #7
0
 public void RecordLeft(GloveHand hand)
 {
     Record(LeftHistory, hand);
 }
Beispiel #8
0
 public void RecordRight(GloveHand hand)
 {
     Record(RightHistory, hand);
 }
        protected override void OnStep()
        {
            Point  middlePoint = (Point)GetVar("MiddlePoint");
            float  deadZone    = (float)GetVar("DeadZone");
            double sensivity   = (double)GetVar("Sensivity");
            bool   alwaysClick = (bool)GetVar("AlwaysClick");

            GloveHand lastRightSides = HandRecord.LastRightWithBothSides();
            GloveHand lastRightIndex = HandRecord.LastRightWithIndex();

            if (lastRightSides == null)
            {
                return;
            }

            double len   = GeometryExt.Distance(lastRightSides.SideMiddlePoint, middlePoint);
            Point  delta = HandRecord.RightSideMovementDelta(2, 10, 15);

            if (len > deadZone && Math.Abs(delta.X) >= 1 && Math.Abs(delta.Y) >= 1)
            {
                double xdiff = (-(lastRightSides.SideMiddlePoint.X - middlePoint.X) / len) * (len - deadZone);
                double ydiff = ((lastRightSides.SideMiddlePoint.Y - middlePoint.Y) / len) * (len - deadZone);

                double mxdiff = GeometryExt.Center(Screen.PrimaryScreen.Bounds).X + xdiff * sensivity;
                double mydiff = GeometryExt.Center(Screen.PrimaryScreen.Bounds).Y + ydiff * sensivity;
                //Console.WriteLine(mxdiff+":"+mydiff);
                Console.WriteLine(GeometryExt.Center(Screen.PrimaryScreen.Bounds));
                Mouse.SetPos((int)mxdiff, (int)mydiff);
            }
            if (alwaysClick || len <= deadZone)
            {
                if (lastRightIndex != null && lastRightIndex.SideFingers.Length == 2)
                {
                    if (GeometryExt.Distance(lastRightIndex.SideFingers[0].LightCenter, lastRightIndex.SideFingers[1].LightCenter) >= deadZone)
                    {
                        if (Math.Abs(lastRightIndex.SideFingers[0].LightCenter.Y - lastRightIndex.SideFingers[1].LightCenter.Y) <
                            Math.Abs(lastRightIndex.SideFingers[0].LightCenter.X - lastRightIndex.SideFingers[1].LightCenter.X)) // i side sono messi in orizzontale
                        {
                            Mouse.Release(false);
                            if (lastRightIndex.IndexFinger.LightCenter.Y > lastRightIndex.SideMiddlePoint.Y)
                            {
                                Mouse.Press(true);
                            }
                            else
                            {
                                Mouse.Release(true);
                            }
                        }
                        else //in verticale
                        {
                            Mouse.Release(true);
                            if (lastRightIndex.IndexFinger.LightCenter.X < lastRightIndex.SideMiddlePoint.X)
                            {
                                Mouse.Press(false);
                            }
                            else
                            {
                                Mouse.Release(false);
                            }
                        }
                    }
                }
            }
        }
Beispiel #10
0
        public GloveHand Read(Image <Bgr, Byte> src)
        {
            //double areaDiv = 55.0;

            var redLeds  = indexLEDDetect.GetAll(src, out _lightCount).OrderByDescending(x => GeometryExt.Area(x.HaloBox)).ToList();
            var blueLeds = sideLEDDetect.GetAll(src, out _lightCount).OrderByDescending(x => GeometryExt.Area(x.HaloBox)).ToList();

            if (redLeds.Count == 0 && blueLeds.Count == 0)
            {
                return(null);
            }


            List <LEDBoxTuple> ledBoxes = new List <LEDBoxTuple>();

            foreach (var l in blueLeds)
            {
                foreach (var box in l.LightBoxes)
                {
                    ledBoxes.Add(new LEDBoxTuple(l, box));
                }
            }
            ledBoxes = ledBoxes.OrderByDescending(x => GeometryExt.Area(x.box)).ToList();

            GloveHand res = new GloveHand();

            if (redLeds.Count >= 1)
            {
                res.IndexFinger = FingerLED.FromLED(redLeds[0], redLeds[0].MainLightBox);
            }
            double avgBigArea = 0.0;

            if (res.IndexFinger != null)
            {
                avgBigArea = GeometryExt.Area(res.IndexFinger.LightBox);
            }
            if (ledBoxes.Count > 0 && GeometryExt.Area(ledBoxes[0].box) > avgBigArea)
            {
                GeometryExt.Area(ledBoxes[0].box);
            }

            if (blueLeds.Count == 0)
            {
                res.SideFingers = new FingerLED[0];                      //non si vedono led blu
            }
            else
            {
                List <FingerLED> splitLEDS = new List <FingerLED>();
                for (int k = 0; k < ledBoxes.Count; k++)
                {
                    if (res.IndexFinger == null || GeometryExt.Distance(ledBoxes[k].box, res.IndexFinger.LightBox) >= 20.0)
                    {
                        if (splitLEDS.Count == 0 || GeometryExt.Distance(splitLEDS[0].LightBox, ledBoxes[k].box) >= 10.0)
                        {
                            splitLEDS.Add(FingerLED.FromLED(ledBoxes[k].led, ledBoxes[k].box));
                        }
                    }
                    if (splitLEDS.Count == 2)
                    {
                        break;
                    }
                }

                /*while (splitLEDS.Count < 2 && res.IndexFinger != null)
                 * {
                 *  splitLEDS.Add(FingerLED.FromLED(redLeds[0], redLeds[0].MainLightBox));
                 * }*/
                res.SideFingers = splitLEDS.ToArray();
            }
            return(res);
        }
Beispiel #11
0
        protected override void OnStep()
        {
            double sensivity        = (double)GetVar("Sensivity");
            double acceleration     = (double)GetVar("Acceleration");
            double minDist          = (double)GetVar("MinDist");
            double maxDistMul       = (double)GetVar("MaxDistMul");
            double maxDistActionMul = (double)GetVar("MaxDistActionMul");
            int    trail            = (int)GetVar("Trail");
            double verticalMul      = (double)GetVar("VerticalMul");

            GloveHand lastRightSides = HandRecord.LastRightWithBothSides();
            GloveHand lastRightIndex = HandRecord.LastRightWithIndex();

            if (lastRightSides == null)
            {
                return;
            }

            Point delta = HandRecord.RightSideMovementDelta(trail);

            if (GeometryExt.Distance(lastRightSides.SideFingers[0].LightCenter, lastRightSides.SideFingers[1].LightCenter) >= minDist)
            {
                double acc2  = GeometryExt.Distance(lastRightSides.SideFingers[0].LightCenter, lastRightSides.SideFingers[1].LightCenter) / (minDist * maxDistMul);
                double xdiff = -delta.X * (sensivity * acc2);
                double ydiff = delta.Y * (sensivity * acc2);
                xdiff = Math.Sign(xdiff) * Math.Pow(Math.Abs(xdiff), acceleration);
                ydiff = Math.Sign(ydiff) * Math.Pow(Math.Abs(ydiff), acceleration);

                Mouse.MoveBy((int)xdiff, (int)ydiff);
            }

            if (lastRightIndex != null && lastRightIndex.SideFingers.Length == 2)
            {
                if (GeometryExt.Distance(lastRightIndex.SideFingers[0].LightCenter, lastRightIndex.SideFingers[1].LightCenter) >= minDist * maxDistActionMul)
                {
                    if (Math.Abs(lastRightIndex.SideFingers[0].LightCenter.Y - lastRightIndex.SideFingers[1].LightCenter.Y) <
                        Math.Abs(lastRightIndex.SideFingers[0].LightCenter.X - lastRightIndex.SideFingers[1].LightCenter.X) * verticalMul) // i side sono messi in orizzontale
                    {
                        Mouse.Release(MOUSE_BUTTON.RIGHT);
                        Mouse.Release(MOUSE_BUTTON.MIDDLE);
                        if (lastRightIndex.IndexFinger.LightCenter.Y > lastRightIndex.SideMiddlePoint.Y)
                        {
                            Mouse.Press(MOUSE_BUTTON.LEFT);
                        }
                        else
                        {
                            Mouse.Release(MOUSE_BUTTON.LEFT);
                        }


                        /*if (lastRightIndex.IndexFinger.LightCenter.X < Math.Min(lastRightIndex.SideFingers[0].LightCenter.X,
                         *                                                      lastRightIndex.SideFingers[1].LightCenter.X))
                         *  Mouse.Press(MOUSE_BUTTON.MIDDLE);
                         * else
                         *  Mouse.Release(MOUSE_BUTTON.MIDDLE);*/
                    }
                    else //in verticale
                    {
                        if (GeometryExt.Distance(lastRightIndex.IndexFinger.LightCenter, lastRightIndex.SideMiddlePoint) <= 15.0)
                        {
                            Mouse.Press(MOUSE_BUTTON.RIGHT);
                            Mouse.Press(MOUSE_BUTTON.LEFT);
                            Mouse.Release(MOUSE_BUTTON.MIDDLE);
                        }
                        else if (lastRightIndex.IndexFinger.LightCenter.X < lastRightIndex.SideMiddlePoint.X)
                        {
                            Mouse.Press(MOUSE_BUTTON.RIGHT);
                            Mouse.Release(MOUSE_BUTTON.LEFT);
                            Mouse.Release(MOUSE_BUTTON.MIDDLE);
                        }
                        else if (lastRightIndex.IndexFinger.LightCenter.X > lastRightIndex.SideMiddlePoint.X)
                        {
                            Mouse.Press(MOUSE_BUTTON.MIDDLE);
                        }
                    }
                }
            }
        }
Beispiel #12
0
        protected override void OnStep()
        {
            Point  middlePoint  = (Point)GetVar("MiddlePoint");
            float  deadZone     = (float)GetVar("DeadZone");
            double sensivity    = (double)GetVar("Sensivity");
            double acceleration = (double)GetVar("Acceleration");
            bool   alwaysClick  = (bool)GetVar("AlwaysClick");

            GloveHand lastRightSides = HandRecord.LastRightWithBothSides();
            GloveHand lastRightIndex = HandRecord.LastRightWithIndex();

            if (lastRightSides == null)
            {
                return;
            }

            double len = GeometryExt.Distance(lastRightSides.SideMiddlePoint, middlePoint);

            if (len > deadZone)
            {
                double xdiff = (-(lastRightSides.SideMiddlePoint.X - middlePoint.X) / len) * (len - deadZone);
                double ydiff = ((lastRightSides.SideMiddlePoint.Y - middlePoint.Y) / len) * (len - deadZone);

                xdiff /= sensivity;
                ydiff /= sensivity;
                xdiff  = Math.Sign(xdiff) * Math.Pow(Math.Abs(xdiff), acceleration);
                ydiff  = Math.Sign(ydiff) * Math.Pow(Math.Abs(ydiff), acceleration);

                Mouse.MoveBy((int)xdiff, (int)ydiff);
            }
            if (alwaysClick || len <= deadZone)
            {
                if (lastRightIndex != null && lastRightIndex.SideFingers.Length == 2)
                {
                    if (GeometryExt.Distance(lastRightIndex.SideFingers[0].LightCenter, lastRightIndex.SideFingers[1].LightCenter) >= deadZone * 1.5)
                    {
                        if (Math.Abs(lastRightIndex.SideFingers[0].LightCenter.Y - lastRightIndex.SideFingers[1].LightCenter.Y) <
                            Math.Abs(lastRightIndex.SideFingers[0].LightCenter.X - lastRightIndex.SideFingers[1].LightCenter.X)) // i side sono messi in orizzontale
                        {
                            Mouse.Release(false);
                            if (lastRightIndex.IndexFinger.LightCenter.Y > lastRightIndex.SideMiddlePoint.Y)
                            {
                                Mouse.Press(true);
                            }
                            else
                            {
                                Mouse.Release(true);
                            }
                        }
                        else //in verticale
                        {
                            Mouse.Press(false);
                            if (lastRightIndex.IndexFinger.LightCenter.X > lastRightIndex.SideMiddlePoint.X)
                            {
                                Mouse.Press(true);
                            }
                            else
                            {
                                Mouse.Release(true);
                            }
                        }
                    }
                }
            }
        }