コード例 #1
0
        public static void Main(string[] args)
        {
            Iterator <Image> screen;

            if (USE_SCREEN)
            {
                // wait
                Log.Info("waiting ...");
                Thread.Sleep(5000);

                // full screen
                Console.WriteLine("## scanning for table ##");
                Image fullScreen = new ScreenImageIterator(new Win32Control()).next();
                Point offset     = PatternLocator.locateTable(fullScreen);
                Console.WriteLine("table found at x=" + offset.X + " y=" + offset.Y);

                // desk
                screen = new ScreenImageIterator(new Win32Control(), new Rectangle(offset.X, offset.Y, new TableLayout9().Size.Width, new TableLayout9().Size.Height));
                screen = new WaitDeltaImageIterator(screen);
            }
            else
            {
                screen = new MockOneImageIterator(toImage(new Bitmap("test/table_highlight.png")));
            }

            // identifier
            TableIdentifier tableIdentifier = new TableIdentifier(new TableLayout9());

            tableIdentifier.RenderImageEvent += delegate(Image image, Point point)
            {
                renderer.renderImage(image, point);
            };

            // loop
            while (screen.hasNext())
            {
                // start
                Console.WriteLine("## iteration -> start ##");
                DateTime start = DateTime.Now;

                // clear
                renderer.clearImages();

                // table
                Console.WriteLine("# next table image #");
                Image tableImage = screen.next();
                renderer.renderImage(tableImage, 0, 0);

                // identify table
                Table table = tableIdentifier.identifyTable(tableImage, TableIdentifier.PlayerInfoEnum.BOTH, -1, 0);

                // render table
                Console.WriteLine("# rendering table");
                renderer.render(table, tableIdentifier.Layout);

                // end
                double time = DateTime.Now.Subtract(start).TotalMilliseconds;
                Console.WriteLine("## iteration -> end -> " + time + " ms ##");
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            Log.SetLevel(Log.Level.FINEST);

            // patterns
            List <CardPattern> patterns = CardReader.readCardsFromResources();

            Console.WriteLine("read " + patterns.Count + " candidate patterns");

            // renderer
            ImagesRenderer renderer = newImageRenderer();

            // iterator
            Iterator <Image> wait;

            if (USE_SCREEN)
            {
                Thread.Sleep(10);
                TableContainer   table  = new BotAppLogic(new Win32Control()).LocateNewTable(new Settings());
                Rectangle        rect   = new Rectangle(table.Layout.Offset.X, table.Layout.Offset.Y, table.Layout.Size.Width, table.Layout.Size.Height);
                Iterator <Image> screen = new ScreenImageIterator(new Win32Control(), rect);
                wait = new WaitDeltaImageIterator(screen);
            }
            else
            {
                wait = new MockIterator(toImage(new Bitmap("test/table_no_middle_button.png")));
            }

            // proxy
            IteratorProxy <Image> proxyIter = new IteratorProxy <Image>(wait);

            proxyIter.handler += delegate(Image next)
            {
                setImage(renderer, toBitmap(next));
            };
            Console.WriteLine("initialized iterator");

            // identifier
            CardStrategy           strategy   = new CardStrategyFast(patterns, new TableLayout9());
            CardIdentifierIterator identifier = new CardIdentifierIterator(proxyIter,
                                                                           strategy.identifyRegions,
                                                                           strategy.identifyCards);

            // go
            while (identifier.hasNext())
            {
                DateTime    start = DateTime.Now;
                List <Card> cards = identifier.next();
                setText(renderer, toText(cards));
                Console.WriteLine("iteration took " + DateTime.Now.Subtract(start).TotalSeconds + "s");
                Console.ReadKey();
            }
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            Log.SetLevel(Log.Level.FINE);

            // patterns
            List <CardPattern> patterns = CardReader.readCardsFromResources();

            Console.WriteLine("read " + patterns.Count + " candidate patterns");

            // renderer
            ImagesRenderer renderer = newImageRenderer();

            // iterator
            Iterator <Image> wait;

            if (USE_SCREEN)
            {
                Iterator <Image> screen = new ScreenImageIterator(new Win32Control(), new Rectangle(400, 400, 300, 80));
                wait = new WaitDeltaImageIterator(screen);
            }
            else
            {
                wait = new MockIterator(toImage(new Bitmap("test/cards_56.png")));
            }

            Iterator <Image> low = new ReduceColorIterator(wait, new ColorReducers.Card());

            // proxy
            IteratorProxy <Image> proxyIter = new IteratorProxy <Image>(low);

            proxyIter.handler += delegate(Image next)
            {
                setImage(renderer, toBitmap(next));
            };
            Console.WriteLine("initialized iterator");

            // identifier
            CardStrategy           strategy   = new CardStrategySlow(patterns);
            CardIdentifierIterator identifier = new CardIdentifierIterator(proxyIter,
                                                                           strategy.identifyRegions,
                                                                           strategy.identifyCards);

            // go
            while (identifier.hasNext())
            {
                DateTime    start = DateTime.Now;
                List <Card> cards = identifier.next();
                setText(renderer, toText(cards));
                Console.WriteLine("iteration took " + DateTime.Now.Subtract(start).TotalSeconds + "s");
            }
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            Iterator <Image> screen;

            if (USE_SCREEN)
            {
                // wait
                Log.Info("waiting ...");
                Thread.Sleep(5000);

                // full screen
                Console.WriteLine("## scanning for table ##");
                Image fullScreen = new ScreenImageIterator(new Win32Control()).next();
                Point offset     = PatternLocator.locateTable(fullScreen);
                Console.WriteLine("table found at x=" + offset.X + " y=" + offset.Y);

                // desk
                screen = new ScreenImageIterator(new Win32Control(), new Rectangle(offset.X, offset.Y, new TableLayout9().Size.Width, new TableLayout9().Size.Height));
                screen = new WaitDeltaImageIterator(screen);
            }
            else
            {
                screen = new MockOneImageIterator(toImage(new Bitmap("test/seatsopen_cropped.bmp")));
            }

            // renderer
            ImagesRenderer renderer = newImageRenderer();

            // identifier
            TableIdentifier tableIdentifier = new TableIdentifier(new TableLayout9());

            // pattern
            Log.Debug("reading seat pattern");
            Stream stream  = AssemblyTools.getAssemblyStream("open_seat.png");
            Bitmap bitmap  = Bitmap.FromStream(stream) as Bitmap;
            Image  pattern = toImage(bitmap);

            pattern = new ColorReducers.SeatOpen().reduceColors(pattern);
            stream.Close();

            // loop
            while (screen.hasNext())
            {
                // start
                Console.WriteLine("## iteration -> start ##");
                DateTime start = DateTime.Now;

                // table
                Console.WriteLine("# next table image #");
                Image tableImage = screen.next();

                // reduce
                ColorReducer reducer = new ColorReducers.SeatOpen();

                // rnder
                setImage(renderer, toBitmap(tableImage));

                // identify seats
                List <Point> seats = new List <Point>();
                Log.Fine("scanning lines ...");
                DateTime seatsStart = DateTime.Now;
                foreach (Rectangle seat in new TableLayout9().Seats)
                {
                    bool isOpen = IsOpen(reducer, seat, pattern, tableImage, 5);
                }
                Console.WriteLine("## seat scan -> " + DateTime.Now.Subtract(seatsStart).TotalMilliseconds + " ms ##");

                // print
                foreach (Point seat in seats)
                {
                    Console.WriteLine(seat);
                }

                // end
                double time = DateTime.Now.Subtract(start).TotalMilliseconds;
                Console.WriteLine("## iteration -> end -> " + time + " ms ##");
            }
        }
コード例 #5
0
        public static void Main(string[] args)
        {
            Log.SetLevel(Log.Level.FINEST);
            Iterator <Image> screenIter;
            LobbyLayout      layout = new LobbyLayout();
            Point            offset;

            if (USE_SCREEN)
            {
                // wait
                Log.Info("waiting ...");
                Thread.Sleep(3000);

                // full screen
                Console.WriteLine("## scanning for lobby ##");
                Image fullScreen = new ScreenImageIterator(new Win32Control()).next();
                offset = PatternLocator.locateLobby(fullScreen);
                Console.WriteLine("lobby found at x=" + offset.X + " y=" + offset.Y);

                // lobby
                screenIter = new ScreenImageIterator(new Win32Control(), new Point(offset.X, offset.Y));
                screenIter = new WaitDeltaImageIterator(screenIter);
            }
            else
            {
                offset     = new Point(0, 0);
                screenIter = new MockOneImageIterator(toImage(new Bitmap("test/lobby1.bmp")));
            }

            // screen + reduce + invert
            ColorReducer  reducer       = new ColorReducers.LobbyChars();
            ColorReducer  reducerJoined = new ColorReducers.LobbyCharsJoined();
            ColorReplacer replacer      = new ColorReplacer(Color.White, Color.Transparent);


            // renderer
            ImagesRenderer renderer      = newImageRenderer();
            ColorReplacer  replacerTrans = new ColorReplacer(Color.Transparent, Color.Cyan);

            // patterns
            List <CharPattern> patterns   = CharReader.readCharsFromResourcesLobby();
            CharIdentifier     identifier = new CharIdentifier(patterns);

            // identify
            while (screenIter.hasNext())
            {
                // rows
                List <LobbyTable> rows = new List <LobbyTable>();

                // image
                Image screen = screenIter.next();

                // list
                Image tableList = screen.crop(layout.TableList.X, layout.TableList.X + layout.TableList.Width,
                                              layout.TableList.Y, layout.TableList.Y + layout.TableList.Height);

                // identify
                List <ValueWithY> playerCounts = identifyValues(tableList, layout.PlayersCountX,
                                                                layout.PlayersCountX + layout.PlayersCountW, tableList.height,
                                                                reducer, replacer, identifier, renderer);
                List <ValueWithY> potSizes = identifyValues(tableList, layout.PotX,
                                                            layout.PotX + layout.PotW, tableList.height,
                                                            reducer, replacer, identifier, renderer);
                List <ValueWithY> flops = identifyValues(tableList, layout.FlopsX,
                                                         layout.FlopsX + layout.FlopsW, tableList.height,
                                                         reducer, replacer, identifier, renderer);

                List <LobbyTable> tables = new List <LobbyTable>();
                for (int i = 0; i < playerCounts.Count; i++)
                {
                    // location
                    int x = offset.X + layout.TableList.X + layout.TableList.Width / 2;
                    int y = offset.Y + layout.TableList.Y + playerCounts[i].Y;

                    // cell
                    int   celly  = playerCounts[i].Y;
                    int   cellx  = layout.PlayersCountX;
                    Image cell   = tableList.crop(cellx, cellx + layout.PlayersCountW, celly, celly + layout.CellHeight);
                    bool  joined = ContainsJoinedColor(cell, reducerJoined, renderer);

                    // table
                    tables.Add(new LobbyTable(i + 1, (int)playerCounts[i].Value, potSizes[i].Value, (int)flops[i].Value, x, y, offset.X, offset.Y, joined));
                }

                // print
                foreach (LobbyTable table in tables)
                {
                    Console.WriteLine(table.ToString());
                }

                // wait
                Console.ReadKey();
            }
        }