public LobbyIdentifier() { List <CharPattern> patterns = CharReader.readCharsFromResourcesLobby(); identifier = new CharIdentifier(patterns); }
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); } }
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); } } }
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(); } }