public ActionResult Index(int tabletDeviceNumber, int boardNumber, bool fromView)
        {
            TabletDeviceStatus tabletDeviceStatus = AppData.TabletDeviceStatusList[tabletDeviceNumber];
            TableStatus        tableStatus        = AppData.TableStatusList.Find(x => x.SectionID == tabletDeviceStatus.SectionID && x.TableNumber == tabletDeviceStatus.TableNumber);
            HandRecord         handRecord         = HandRecords.HandRecordsList.Find(x => x.SectionID == tabletDeviceStatus.SectionID && x.BoardNumber == boardNumber);

            if (handRecord == null)     // Can't find matching hand record, so use default SectionID = 1
            {
                handRecord = HandRecords.HandRecordsList.Find(x => x.SectionID == 1 && x.BoardNumber == boardNumber);
            }
            handRecord.TabletDeviceNumber = tabletDeviceNumber;
            handRecord.FromView           = fromView;

            ViewData["Title"] = $"Hand Record - {tabletDeviceStatus.Location}";
            if (AppData.IsIndividual)
            {
                ViewData["Header"] = $"{tabletDeviceStatus.Location} - Round {tableStatus.RoundNumber} - {Utilities.ColourPairByVulnerability("NS", boardNumber, $"{tableStatus.RoundData.NumberNorth}+{tableStatus.RoundData.NumberSouth}")} v {Utilities.ColourPairByVulnerability("EW", boardNumber, $"{tableStatus.RoundData.NumberEast}+{tableStatus.RoundData.NumberWest}")}";
            }
            else
            {
                ViewData["Header"] = $"{tabletDeviceStatus.Location} - Round {tableStatus.RoundNumber} - {Utilities.ColourPairByVulnerability("NS", boardNumber, $"NS {tableStatus.RoundData.NumberNorth}")} v {Utilities.ColourPairByVulnerability("EW", boardNumber, $"EW {tableStatus.RoundData.NumberEast}")}";
            }
            ViewData["ButtonOptions"] = ButtonOptions.OKEnabled;
            return(View(handRecord));
        }
Example #2
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);
                            }
                        }
                    }
                }
            }
        }
Example #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);
            }
        }
Example #4
0
    public void ReadFile()
    {
        path = Application.dataPath + "/Archivos/GestosJson/" + NombreDeArchivo + ".json";

        string tmp = NombreDeArchivo.Split('-')[1];

        print(tmp);

        der = new HandRecord(int.Parse(tmp));
        izq = new HandRecord(int.Parse(tmp));


        //Read the text from directly from the test.txt file
        StreamReader reader = new StreamReader(path);

        izq = JsonUtility.FromJson <HandRecord>(reader.ReadLine());
        der = JsonUtility.FromJson <HandRecord>(reader.ReadLine());
        reader.Close();
    }
Example #5
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);
        }
Example #6
0
        /// <summary>
        ///  运行监测页面,失败后手工启动脚本流实例/脚本节点实例
        /// </summary>
        /// <param name="StartType">启动类型 1 脚本流实例 2 脚本节点实例</param>
        /// <param name="ExampleId">脚本流实例ID</param>
        /// <param name="ExampleNode">脚本流节点实例ID</param>
        /// <returns>备注:在SelectScriptExample调用方法,直接使用传参数的方式</returns>
        public bool StartExampSelect(short StartType, long ExampleId, long ExampleNode)
        {
            //short? StartType, long? ExampleId, long? ExampleNode = 0
            long OBJECT_ID = 0;

            PubEnum.HandType start = (PubEnum.HandType)StartType;

            if (start == PubEnum.HandType.Script)
            {
                OBJECT_ID = ExampleId;
            }
            else if (start == PubEnum.HandType.ScriptNode)
            {
                OBJECT_ID = ExampleNode;
            }
            try
            {
                HandRecord hr = new HandRecord();
                hr.HandType = (short)StartType;
                hr.UserId   = AbpSession.UserId.Value;
                //hr.ObjectId = OBJECT_ID;
                hr.AddTime = DateTime.Now;
                //hr.StartTime = DateTime.Now;
                hr.ObjectCaseId = OBJECT_ID;
                #region 赋值脚本节点ID给手工记录
                var nodeCase = _scriptNodeCase.FirstOrDefault(ExampleId);
                if (nodeCase != null)
                {
                    hr.ObjectId = nodeCase.ScriptNodeId;
                }
                #endregion
                _handRecord.Insert(hr);
                return(true);
            }
            catch (Exception ex)
            {
                throw new UserFriendlyException("启动失败!" + ex.Message);
            }
        }
        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);
        }
Example #8
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);
            }
        }
Example #9
0
        /// <summary>
        /// 手工启动脚本流实例/脚本节点实例
        /// </summary>
        /// <param name="StartType">启动类型 1 脚本流实例 2 脚本节点实例</param>
        /// <param name="ExampleId">脚本流实例ID</param>
        /// <param name="ExampleNode">脚本流节点实例ID</param>
        /// <returns>备注:在配置报表哪里直接调用方法,跟删除方法类似,不能直接使用传参数的方式,要建立一个Dto类型,类型里面包含这些参数</returns>
        public bool StartExamp(StartExampModel input)
        {
            //short? StartType, long? ExampleId, long? ExampleNode = 0
            short StartType   = input.StartType;
            long  ExampleId   = input.ExampleId;
            long  ExampleNode = input.ExampleNode;
            long  OBJECT_ID   = 0;

            PubEnum.HandType start = (PubEnum.HandType)StartType;

            if (start == PubEnum.HandType.Script)
            {
                OBJECT_ID = ExampleId;
            }
            else if (start == PubEnum.HandType.ScriptNode)
            {
                OBJECT_ID = ExampleNode;
            }
            try
            {
                HandRecord hr = new HandRecord();
                hr.HandType = (short)StartType;
                hr.UserId   = AbpSession.UserId.Value;
                hr.ObjectId = OBJECT_ID;
                hr.AddTime  = DateTime.Now;
                #region 任务启动时间和实例ID由服务去添加
                //hr.StartTime = DateTime.Now;
                //hr.ObjectCaseId = ExampleId;
                #endregion
                _handRecord.Insert(hr);
                return(true);
            }
            catch (Exception ex)
            {
                throw new UserFriendlyException("启动失败!" + ex.Message);
            }
        }
Example #10
0
        // GET api/contracts?pbn=W:KJ95.T.AT873.T98 76.AQJ9642.KJ.QJ QT8.K87.962.A654 A432.53.Q54.K732
        // GET api/contracts?html=true&pbn=W:KJ95.T.AT873.T98 76.AQJ9642.KJ.QJ QT8.K87.962.A654 A432.53.Q54.K732
        public object Get(string pbn, bool?html = false, bool?stats = false)
        {
            var board = new Board
            {
                Hands = HandCollection.ParsePbn(pbn)
            };

            if (board.Hands[Seat.North].Cards.Count != 13)
            {
                throw new FormatException("North needs 13 cards.");
            }
            if (board.Hands[Seat.South].Cards.Count != 13)
            {
                throw new FormatException("South needs 13 cards.");
            }
            if (board.Hands[Seat.East].Cards.Count != 13)
            {
                throw new FormatException("East needs 13 cards.");
            }
            if (board.Hands[Seat.West].Cards.Count != 13)
            {
                throw new FormatException("West needs 13 cards.");
            }

            // Return HTML report?
            if (html.HasValue && html.Value)
            {
                var tournament = new Session();
                tournament.Boards.Add(board);
                var writer = new StringWriter();
                var report = new HandRecord()
                {
                    Tournament = tournament
                };
                report.Produce(writer);

                var response = new HttpResponseMessage();
                response.Content = new StringContent(writer.ToString());
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
                return(response);
            }

            // Stats and the data?
            if (stats.HasValue && stats.Value)
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                var contracts = Solver.MakeableContracts(board);
                stopWatch.Stop();

                return(new
                {
                    Stats = new
                    {
                        ProcessorCount = Environment.ProcessorCount,
                        ProcessorSpeedMhz = CPUSpeed(),
                        RunTime = stopWatch.Elapsed
                    },
                    Contracts = contracts
                });
            }

            // Just return the data.
            return(Solver.MakeableContracts(board));
        }
Example #11
0
        public HandsDisplay(int deviceNumber, Table table)
        {
            DeviceNumber = deviceNumber;
            Device device = AppData.DeviceList[deviceNumber];
            int    northDirectionNumber = (4 - Utilities.DirectionToNumber(device.Direction)) % 4;

            HandRecord handRecord = HandRecords.HandRecordsList.Find(x => x.SectionID == device.SectionID && x.BoardNumber == table.BoardNumber);

            if (handRecord == null)     // Can't find matching hand record, so use default SectionID = 1
            {
                handRecord = HandRecords.HandRecordsList.Find(x => x.SectionID == 1 && x.BoardNumber == table.BoardNumber);
            }
            Dealer = handRecord.Dealer;

            Direction = new string[4];
            Direction[northDirectionNumber]           = "North";
            Direction[(northDirectionNumber + 1) % 4] = "East";
            Direction[(northDirectionNumber + 2) % 4] = "South";
            Direction[(northDirectionNumber + 3) % 4] = "West";
            HCP = new string[4];
            HCP[northDirectionNumber]           = handRecord.HCPNorth;
            HCP[(northDirectionNumber + 1) % 4] = handRecord.HCPEast;
            HCP[(northDirectionNumber + 2) % 4] = handRecord.HCPSouth;
            HCP[(northDirectionNumber + 3) % 4] = handRecord.HCPWest;
            CardString  = handRecord.HandTable(northDirectionNumber, "NT");
            DisplayRank = new string[4, 13];
            DisplaySuit = new string[4, 13];
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    DisplayRank[i, j] = Utilities.DisplayRank(CardString[i, j]);
                    DisplaySuit[i, j] = Utilities.DisplaySuit(CardString[i, j]);
                }
            }
            SuitLengths = handRecord.SuitLengths(northDirectionNumber, "NT");
            if (northDirectionNumber % 2 == 0)
            {
                Vuln02 = Utilities.NSVulnerability[(table.BoardNumber - 1) % 16];
                Vuln13 = Utilities.EWVulnerability[(table.BoardNumber - 1) % 16];
            }
            else
            {
                Vuln02 = Utilities.EWVulnerability[(table.BoardNumber - 1) % 16];
                Vuln13 = Utilities.NSVulnerability[(table.BoardNumber - 1) % 16];
            }

            EvalNorthNT       = handRecord.EvalNorthNT;
            EvalNorthSpades   = handRecord.EvalNorthSpades;
            EvalNorthHearts   = handRecord.EvalNorthHearts;
            EvalNorthDiamonds = handRecord.EvalNorthDiamonds;
            EvalNorthClubs    = handRecord.EvalNorthClubs;
            EvalEastNT        = handRecord.EvalEastNT;
            EvalEastSpades    = handRecord.EvalEastSpades;
            EvalEastHearts    = handRecord.EvalEastHearts;
            EvalEastDiamonds  = handRecord.EvalEastDiamonds;
            EvalEastClubs     = handRecord.EvalEastClubs;
            EvalSouthNT       = handRecord.EvalSouthNT;
            EvalSouthSpades   = handRecord.EvalSouthSpades;
            EvalSouthHearts   = handRecord.EvalSouthHearts;
            EvalSouthDiamonds = handRecord.EvalSouthDiamonds;
            EvalSouthClubs    = handRecord.EvalSouthClubs;
            EvalWestNT        = handRecord.EvalWestNT;
            EvalWestSpades    = handRecord.EvalWestSpades;
            EvalWestHearts    = handRecord.EvalWestHearts;
            EvalWestDiamonds  = handRecord.EvalWestDiamonds;
            EvalWestClubs     = handRecord.EvalWestClubs;
        }
        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);
                            }
                        }
                    }
                }
            }
        }
    /**
     * Idea from this method is to get all the data we can get from the sensor
     * then, we will write it to a file that will be learned on in Matlab
     * then, passed back to another method here that will have a method to classify
     *
     */
    int snapshot(Hand hand1, Frame frame)
    {
        //Hand hand1 = hands [h];
        FingerList fingers = hand1.Fingers;
        HandRecord record  = new HandRecord();

        for (int j = 0; j < fingers.Count; j++)
        {
            Finger            f1       = fingers [j];
            Finger.FingerType fingtype = f1.Type();

            if (f1.IsExtended)
            {
                record.extend(fingtype);
            }

            Vector fpos = f1.TipPosition;
            record.tips(fpos, fingtype);
        }

        if (hand1.IsLeft)
        {
            record.left = true;
        }

        float pitch = hand1.Direction.Pitch;
        float yaw   = hand1.Direction.Yaw;
        float roll  = hand1.PalmNormal.Roll;

        record.setDirections(pitch, yaw, roll);

        Vector handCenter = hand1.PalmPosition;

        record.setHandCenter(handCenter);

        Classifier cf = new Classifier(handCenter);


        record.updateAlt();
        //record.writeData ();

        //1 is Feature Detection
        //2 is Nearest Neighbor
        //3 is K-Nearest Neighbor
        int result = cf.classify(record, 1);

        Debug.Log("Result: " + result.ToString());

        //float confid = hand1.Confidence;
        //confSum += confid;
        //writeResultData(result, confid);

        //GameMechanic game = new GameMechanic (result);
        //game.printPlayers ();
        //Debug.Log (game.decision ());

        return(result);

        //test randoms
        //in theory - should be good to use with classifier now
        //GameMechanic game = new GameMechanic ();
        //game.printPlayers ();
        //Debug.Log (game.decision ());
    }    //end get hand data
Example #14
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);
                        }
                    }
                }
            }
        }
Example #15
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);
                            }
                        }
                    }
                }
            }
        }
Example #16
0
    public int classify(HandRecord handRecord, int classMode)
    {
        int[] fex = handRecord.getExtended();

        int tx = fex [0];
        int ix = fex [1];
        int mx = fex [2];
        int rx = fex [3];
        int px = fex [4];


        //Debug.Log ("Fingers: " + tx + " " + ix + " " + mx + " " + rx + " " + px);
        int allex = tx + ix + mx + rx + px;

        float gap0 = handRecord.getThumbPos().DistanceTo(handRecord.getIndexPos());
        float gap1 = handRecord.getIndexPos().DistanceTo(handRecord.getMiddlePos());
        float gap2 = handRecord.getMiddlePos().DistanceTo(handRecord.getRingPos());
        float gap3 = handRecord.getRingPos().DistanceTo(handRecord.getPinkyPos());

        float sumgap = gap0 + gap1 + gap2 + gap3;

        //float scisNorm = gap1 / sumgap;
        //float spockNorm = gap2 / sumgap;
        //float spockTest = (gap1 + gap3) / sumgap;

        //Debug.Log (gap2.ToString ());

        Vector lizthumb = handRecord.getThumbPos();
        Vector lizindex = handRecord.getIndexPos();

        /**
         * Hierarchy of Tree
         * Rock - Scissors --> easy to determine
         * Spock
         * Lizard is a special type of Paper, so needs to be checked first
         * */

        /*
         * if (tx == 1) {
         *      Debug.Log ("Thumb is Extended");
         * }*/


        float ngap0 = gap0 / sumgap;
        float ngap1 = gap1 / sumgap;
        float ngap2 = gap2 / sumgap;
        float ngap3 = gap3 / sumgap;


        bool isRock     = this.classifyRock(allex);
        bool isScissors = this.classifyScissors(tx, ix, mx, rx, px, ngap1);
        bool isSpock    = this.classifySpock(ix, mx, rx, px, ngap2);
        bool isLizard   = this.classifyLizard(allex, lizthumb, lizindex);
        bool isPaper    = this.classifyPaper(ix, mx, rx, px);

        switch (classMode)
        {
        case 1:
            return(featureMap(isRock, isPaper, isScissors, isLizard, isSpock));

        case 2:
            return(nearestNeighbor(ngap0, ngap1, ngap2, ngap3));

        case 3:
            return(kNearestNeighbor(ngap0, ngap1, ngap2, ngap3));

        default:
            return(-1);
        }
    }