Exemplo n.º 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 ##");
            }
        }
        public static void Main(string[] args)
        {
            // screen + reduce + invert
            Iterator <Image> screenIter  = new MockOneImageIterator(toImage(new Bitmap("test/control_post_sb.bmp")));
            Iterator <Image> reduceIter  = new ReduceColorIterator(screenIter, new ColorReducers.ControlsChars());
            Iterator <Image> invertIter  = new InvertColorIterator(reduceIter, Color.WhiteSmoke, Color.Black);
            Iterator <Image> replaceIter = new ReplaceColorIterator(invertIter, Color.WhiteSmoke, Color.Transparent);

            // proxy
            ImagesRenderer        renderer  = newImageRenderer();
            IteratorProxy <Image> proxyIter = new IteratorProxy <Image>(replaceIter);
            ColorReplacer         replacer  = new ColorReplacer(Color.Transparent, Color.Cyan);

            proxyIter.handler += delegate(Image next)
            {
                setImage(renderer, toBitmap(replacer.replace(next)));
            };

            // partition + decompose + crop
            Iterator <List <List <Image> > > patitionIter = new ImageHoriPartitionIterator(proxyIter);
            Iterator <List <List <Image> > > cropIter     = new CropImageIterator(patitionIter);

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

            // identify
            int count = 0;

            while (cropIter.hasNext())
            {
                List <List <Image> > lines = cropIter.next();
                // line
                foreach (List <Image> line in lines)
                {
                    // chars
                    String textLine = "";
                    foreach (Image chars in line)
                    {
                        List <Image> combos = CharDecomposer.decompose(chars, 0);
                        foreach (Image chr in combos)
                        {
                            Image character = ImageCropper.crop(chr);
                            textLine += identifyChars(identifier, character, ref count);
                        }
                    }
                    Console.WriteLine(textLine);
                }
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            // screen + reduce + invert
            Iterator <Image> screenIter = new MockOneImageIterator(toImage(new Bitmap("test/table_no_middle_button.png")));
            Iterator <Image> reduceIter = new ReduceColorIterator(screenIter, new ColorPaletteReducer(new Color[] { Color.White, Color.Black }));

            // table
            ImagesRenderer renderer1 = newImageRenderer();

            setImage(renderer1, toBitmap(reduceIter.next()));

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

            // proxy
            ImagesRenderer renderer2 = newImageRenderer();

            tableIdentifier.RenderImageEvent += delegate(Image image, Point point)
            {
                setImage(renderer2, toBitmap(image));
            };

            // check
            Image    check1   = toImage(new Bitmap("test/table_no_middle_button.png"));
            Image    check2   = toImage(new Bitmap("test/table_with_mouse_fold.png"));
            Image    check3   = toImage(new Bitmap("test/table_seat_is_occupied.png"));
            DateTime start    = DateTime.Now;
            bool     controls = tableIdentifier.identifyMove(check1);
            double   time     = DateTime.Now.Subtract(start).TotalMilliseconds;

            Console.WriteLine(controls);
            DateTime start2 = DateTime.Now;

            controls = tableIdentifier.identifyMove(check2);
            Console.WriteLine(controls);
            double time2 = DateTime.Now.Subtract(start2).TotalMilliseconds;

            controls = tableIdentifier.identifyMove(check3);
            Console.WriteLine(controls);
            Console.WriteLine("took " + time + " ms and with boost " + time2 + " ms");
        }
Exemplo n.º 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 ##");
            }
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            Log.SetLevel(Log.Level.FINEST);
            Iterator <Image> screenIter;

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

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

                // desk
                LobbyLayout layout = new LobbyLayout();
                screenIter = new ScreenImageIterator(new Win32Control(), new Rectangle(offset.X + layout.TableList.X, offset.Y + layout.TableList.Y, layout.TableList.Width, layout.TableList.Height));
            }
            else
            {
                screenIter = new MockOneImageIterator(toImage(new Bitmap("test/lobby1.bmp")));
            }

            // screen + reduce + invert
            Iterator <Image> reduceIter  = new ReduceColorIterator(screenIter, new ColorReducers.LobbyChars());
            Iterator <Image> replaceIter = new ReplaceColorIterator(reduceIter, Color.White, Color.Transparent);

            // proxy
            ImagesRenderer        renderer  = newImageRenderer();
            IteratorProxy <Image> proxyIter = new IteratorProxy <Image>(replaceIter);
            ColorReplacer         replacer  = new ColorReplacer(Color.Transparent, Color.Cyan);

            proxyIter.handler += delegate(Image next)
            {
                setImage(renderer, toBitmap(replacer.replace(next)));
            };

            // partition + decompose + crop
            Iterator <List <List <Image> > > patitionIter = new ImageHoriPartitionIterator(proxyIter);
            Iterator <List <List <Image> > > cropIter     = new CropImageIterator(patitionIter);

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

            // identify
            int count = 0;

            while (cropIter.hasNext())
            {
                List <List <Image> > lines = cropIter.next();
                // line
                foreach (List <Image> line in lines)
                {
                    // chars
                    String textLine = "";
                    foreach (Image chars in line)
                    {
                        List <Image> combos = CharDecomposer.decompose(chars, 0);
                        foreach (Image chr in combos)
                        {
                            Image character = ImageCropper.crop(chr);
                            textLine += identifyChars(identifier, character, ref count);
                        }
                    }

                    Console.WriteLine(textLine);
                }
            }
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            // screen + reduce + invert
            Iterator <Image> screenIter = new MockOneImageIterator(toImage(new Bitmap("test/bet.png")));
            //Iterator<Image> screenIter = new ScreenImageIterator(new Rectangle(100, 400, 80, 30));
            Iterator <Image> reduceIter  = new ReduceColorIterator(screenIter, new ColorReducers.Bets());
            Iterator <Image> invertIter  = new InvertColorIterator(reduceIter, Color.White, Color.Black);
            Iterator <Image> replaceIter = new ReplaceColorIterator(invertIter, Color.White, Color.Transparent);

            // proxy
            ImagesRenderer        renderer  = newImageRenderer();
            IteratorProxy <Image> proxyIter = new IteratorProxy <Image>(replaceIter);
            ColorReplacer         replacer  = new ColorReplacer(Color.Transparent, Color.Cyan);

            proxyIter.handler += delegate(Image next)
            {
                setImage(renderer, toBitmap(replacer.replace(next)));
            };

            // partition + decompose + crop
            Iterator <List <List <Image> > > patitionIter = new ImageHoriPartitionIterator(proxyIter);
            Iterator <List <List <Image> > > cropIter     = new CropImageIterator(patitionIter);

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

            // identify
            int count = 0;

            while (cropIter.hasNext())
            {
                List <Image> line = cropIter.next()[0];
                // chars
                String textLine = "";
                foreach (Image chars in line)
                {
                    List <Image> combos = CharDecomposer.decompose(chars);
                    foreach (Image chr in combos)
                    {
                        Image character = ImageCropper.crop(chr);
                        textLine += identifyChars(identifier, character, ref count);
                    }
                }

                // original
                Console.WriteLine(textLine);

                // check for digit
                if (!containsDigit(textLine))
                {
                    textLine = "no bet";
                }
                else
                {
                    // format
                    textLine = textLine.Replace("?", "").Replace("$", "").Trim();
                }

                Console.WriteLine(textLine);
            }
        }
Exemplo n.º 7
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();
            }
        }