Example #1
0
        public void RecognizeFromWholeBmp(Bitmap bmp, AppSettings settings)
        {
            for (int i = 0; i < PlayerRects.Count; i++)
            {
                var playerRect = PlayerRects[i];
                if (playerRect == Rectangle.Empty)
                    continue;

                var bmpPl = GetArea(bmp, playerRect);
                var txt = _cardRecognizer.RecognizeText(bmpPl);

                Players[i].Txt = txt;
                Players[i].Image = bmpPl;
                Players[i].Parse(settings.RemoveDollar);

                if (PlayerFolds[i] != Rectangle.Empty)
                {
                    var bmpFl = GetArea(bmp, PlayerFolds[i]);
                    Players[i].IsFold = !_cardRecognizer.PlayerHasCards(bmpFl);
                }
            }

            Players[Players.Count - 1].IsMe = true;

            for (int i = 0; i < DealerButtons.Count; i++)
            {
                DealerButtons[i] = false;
            }

            for (int i = 0; i < ButtonRects.Count; i++)
            {
                var buttonRect = ButtonRects[i];
                if (buttonRect == Rectangle.Empty)
                    continue;

                var bmpPl = GetArea(bmp, buttonRect);

                if (_cardRecognizer.IsButton(bmpPl, null))
                    DealerButtons[i] = true;
            }

            //TODO player bets
            //decimal lastMaxBet = 0;
            //for (int i = 0; i < BetRects.Count; i++)
            //{
            //    var betRect = BetRects[i];
            //    if (betRect == Rectangle.Empty)
            //        continue;

            //    var bmpPl = GetArea(bmp, betRect);
            //    var txt = _cardRecognizer.RecognizeText(bmpPl);

            //    txt = RecognizeBet(betRect, bmp, 23);

            //    int cnt = 0;
            //    while ((txt == "" || txt == "none") && cnt < 3)
            //    {
            //        txt = RecognizeBet(betRect, bmp, 23*i);
            //        cnt++;
            //    }

            //    cnt = 0;
            //    while ((txt == "" || txt == "none") && cnt < 3)
            //    {
            //        txt = RecognizeBet(betRect, bmp, - 23 * i);
            //        cnt++;
            //    }

            //    PlayerBets[i].Txt = txt;
            //    PlayerBets[i].Image = bmpPl;
            //    PlayerBets[i].Parse(settings.RemoveDollar);

            //    //PlayerBets[i].AnalyseBets(settings.MinBet, lastMaxBet);
            //    //if (lastMaxBet < PlayerBets[i].CurrentBet)
            //    //    lastMaxBet = PlayerBets[i].CurrentBet;
            //}

            //PlayerBets[PlayerBets.Count - 1].IsMe = true;

            if (settings.BalanceRect != Rectangle.Empty)
            {
                var bmpMy = GetArea(bmp, settings.BalanceRect);
                MyBalance.Txt = _cardRecognizer.RecognizeText(bmpMy);
                MyBalance.Image = bmpMy;
                MyBalance.Parse(settings.RemoveDollar);
            }

            RandomTableRect = settings.RandomTableRect;
            PauseRect = settings.PauseRect;
            ResumeRect = settings.ResumeRect;
            BuyIn = settings.BuyIn;

            RectBuyInOk = settings.RectBuyInOk;
            RectCancelTable = settings.RectCancelTable;
            RectLeaveTableOk = settings.RectLeaveTableOk;
            RectOpenTable = settings.RectOpenTable;
            RectTableX = settings.RectTableX;

            if (settings.BankSizeRect != Rectangle.Empty)
            {
                var bmpBank = GetArea(bmp, settings.BankSizeRect);
                Bank.BankStr = _cardRecognizer.RecognizeText(bmpBank);
                Bank.BankImg = bmpBank;
                BankRect = settings.BankSizeRect;
            }

            if (settings.CallRateRect != Rectangle.Empty)
            {
                var bmpCall = GetArea(bmp, settings.CallRateRect);
                Bank.CallStr = _cardRecognizer.RecognizeTextSmall(bmpCall);
                Bank.CallImg = bmpCall;
            }

            if (settings.RaiseRateRect != Rectangle.Empty)
            {
                var bmpRaise = GetArea(bmp, settings.RaiseRateRect);
                Bank.RaiseStr = _cardRecognizer.RecognizeTextSmall(bmpRaise);
                Bank.RaiseImg = bmpRaise;
            }

            Bank.Parse(settings.RemoveDollar);

            MyCardsBmp = GetArea(bmp, settings.MyCardsRect);
            AllCardsBmp = GetArea(bmp, settings.AllCardsRect);
            TableBmp = bmp;

            try
            {
                MyCards = _cardRecognizer.Recognize(MyCardsBmp, TempDir, 0, CardMinSize, CardSuitRect, CardRankRect);
            }
            catch (Exception ex)
            {
                MyCards = new CardCollection();
            }

            try
            {
                AllCards = _cardRecognizer.Recognize(AllCardsBmp, TempDir, 0, CardMinSize, CardSuitRect, CardRankRect);
            }
            catch (Exception ex)
            {
                AllCards = new CardCollection();
            }

            try
            {
                Buttons = new ButtonCollection();

                ButtonFoldBmp = GetArea(bmp, settings.FoldRect);
                ButtonCallCheckBmp = GetArea(bmp, settings.CheckCallRect);
                ButtonBetRaiseBmp = GetArea(bmp, settings.BetRaiseRect);

                Buttons.Add(_cardRecognizer.RecognizeOneButton(ButtonFoldBmp, settings.FoldRect, TempDir, 0));
                Buttons.Add(_cardRecognizer.RecognizeOneButton(ButtonCallCheckBmp, settings.CheckCallRect, TempDir, 0));
                Buttons.Add(_cardRecognizer.RecognizeOneButton(ButtonBetRaiseBmp, settings.BetRaiseRect, TempDir, 0));
            }
            catch (Exception ex)
            {
                Buttons = new ButtonCollection();
            }

            //var txtRestImg = GetArea(bmp, settings.TxtResultRect);
            //TxtResult = _cardRecognizer.RecognizeText2(txtRestImg, "", 0);
        }
Example #2
0
        public void RecogniseButton(AppSettings settings)
        {
            try
            {
                Buttons = new ButtonCollection();

                ButtonFoldBmp = GetAreaFromScreen(settings.FoldRect);
                ButtonCallCheckBmp = GetAreaFromScreen(settings.CheckCallRect);
                ButtonBetRaiseBmp = GetAreaFromScreen(settings.BetRaiseRect);

                Buttons.Add(_cardRecognizer.RecognizeOneButton(ButtonFoldBmp, settings.FoldRect, TempDir, 0));
                Buttons.Add(_cardRecognizer.RecognizeOneButton(ButtonCallCheckBmp, settings.CheckCallRect, TempDir, 0));
                Buttons.Add(_cardRecognizer.RecognizeOneButton(ButtonBetRaiseBmp, settings.BetRaiseRect, TempDir, 0));
            }
            catch (Exception ex)
            {

            }
        }