Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            ImagesRenderer renderer = newImageRenderer();

            // screen + reduce + invert
            Iterator <Image> screenIter = new MockIterator(toImage(new Bitmap("player9.png")));
            //Iterator<Image> screenIter = new ScreenImageIterator(new Rectangle(100, 400, 80, 30));
            Iterator <Image> reduceIter  = new ReduceColorIterator(screenIter, new ColorReducers.TextBox());
            Iterator <Image> invertIter  = new InvertColorIterator(reduceIter, Color.White, Color.Black);
            Iterator <Image> replaceIter = new ReplaceColorIterator(invertIter, Color.White, Color.Transparent);

            // proxy
            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> > > decomposeIter = new DecomposeImageIterator(patitionIter);
            Iterator <List <List <Image> > > cropIter      = new CropImageIterator(decomposeIter);

            // hash
            HashSet <HashImage> hashImages = new HashSet <HashImage>();
            int count = 0;

            while (cropIter.hasNext())
            {
                List <List <Image> > images = cropIter.next();
                foreach (List <Image> line in images)
                {
                    foreach (Image image in line)
                    {
                        // dimensions
                        if (!hasDimensions(image))
                        {
                            continue;
                        }

                        // hash
                        HashImage hash = new HashImage(image);
                        if (!hashImages.Contains(hash))
                        {
                            hashImages.Add(hash);
                            System.Drawing.Image bitmap = toBitmap(image);
                            addImage(renderer, bitmap);
                            Console.WriteLine("Saving image " + count++);
                            saveBitmap("char", uniqueId(hash), bitmap);
                        }
                    }
                }
            }
        }
        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 MockIterator(toImage(new Bitmap("player10.png")));
            //Iterator<Image> screenIter = new ScreenImageIterator(new Rectangle(100, 400, 80, 30));
            Iterator <Image> reduceIter  = new ReduceColorIterator(screenIter, new ColorReducers.TextBox());
            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> > > decomposeIter = new DecomposeImageIterator(patitionIter);
            Iterator <List <List <Image> > > cropIter      = new CropImageIterator(decomposeIter);

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

            // identify
            int count = 0;

            while (cropIter.hasNext())
            {
                List <List <Image> > images = cropIter.next();
                foreach (List <Image> line in images)
                {
                    foreach (Image chr in line)
                    {
                        String chars = identifyChars(identifier, chr, ref count);
                        Console.Write(chars);
                    }
                    Console.WriteLine();
                }
            }
        }
Exemplo n.º 4
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);
            }
        }