private List <String> identifyLines(Image replaced, Rectangle rect, TableIdentifier parent) { // image parent.renderImage(inker.replace(replaced), rect); // partition List <List <Image> > lines = HorizontalPartitioner.partition(replaced); // chars List <String> textLines = new List <String>(); foreach (List <Image> line in lines) { 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(character); } } textLines.Add(textLine); } return(textLines); }
private static List <Image> apply(Image image) { return(new List <Image>() { ImageCropper.crop(image) }); }
private List <ValueWithY> identifyValues(Image tableList, int x, int width, int height) { // rows Image rows = tableList.crop(x, width, 0, height); // reduce & replace Image reducedRows = reducer.reduceColors(rows); Image replacedRows = replacer.replace(reducedRows); // render renderImage(reducedRows, new Point(x, 0)); // chars List <ImageLine> lines = HorizontalPartitioner.partitionWithY(replacedRows); // chars List <ValueWithY> result = new List <ValueWithY>(); foreach (ImageLine line in lines) { 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); } } // pure numbers string numericTextLine = textLine; foreach (char chr in textLine) { if (!TextTools.IsNumeric(chr) && !TextTools.IsPoint(chr)) { numericTextLine = numericTextLine.Replace(chr.ToString(), ""); } } // convert if (numericTextLine.Length != 0) { double value = TextTools.ParseDouble(numericTextLine); result.Add(new ValueWithY(value, line.Y)); } else { result.Add(new ValueWithY(line.Y)); } } return(result); }
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); } } }
public double process(Image image, Rectangle rect, TableIdentifier parent) { // colors Image cropped = crop(image, rect); Image reduced = reducer.reduceColors(cropped); Image replaced = replacer.replace(reduced); // image parent.renderImage(inker.replace(replaced), rect); // partition List <List <Image> > lines = HorizontalPartitioner.partition(replaced); if (lines.Count == 0) { return(Table.NO_POT); } // chars String textLine = ""; foreach (Image chars in lines[0]) { List <Image> combos = CharDecomposer.decompose(chars); foreach (Image chr in combos) { Image character = ImageCropper.crop(chr); textLine += identifyChars(character); } } // check for digit if (!TextTools.ContainsDigit(textLine)) { return(Table.NO_POT); } // format textLine = textLine.Replace("$", "").Replace("?", "").Trim(); // money return(TextTools.ParseDouble(textLine)); }
public TableControl process(Image image, int position, Rectangle rect, TableIdentifier parent) { // crop image = crop(image, rect); // colors Image reduced = reducer.reduceColors(image); Image inverted = inverter.invert(reduced); Image replaced = replacer.replace(inverted); // image parent.renderImage(inker.replace(replaced), rect); // partition List <List <Image> > lines = HorizontalPartitioner.partition(replaced); // ## action ## TableControl.ControlType type = TableControl.ControlType.NONE; if (lines.Count >= 1) { // read chars String actionText = ""; foreach (Image chars in lines[0]) { List <Image> combos = CharDecomposer.decompose(chars, 0); foreach (Image chr in combos) { Image character = ImageCropper.crop(chr); actionText += identifyChars(character); } } if (actionText == "Fold") { type = TableControl.ControlType.FOLD; } else if (actionText == "Check") { type = TableControl.ControlType.CHECK; } else if (actionText.StartsWith("Cal")) { type = TableControl.ControlType.CALL; } else if (actionText == "Bet") { type = TableControl.ControlType.BET; } else if (actionText.StartsWith("Raise")) { type = TableControl.ControlType.RAISE; } else if (actionText.StartsWith("Post")) { type = TableControl.ControlType.POST_BLIND; } } // ## amount ## double amount = 0.0; if (lines.Count >= 2) { // read chars String amountText = ""; foreach (Image chars in lines[1]) { List <Image> combos = CharDecomposer.decompose(chars, 0); foreach (Image chr in combos) { Image character = ImageCropper.crop(chr); amountText += identifyChars(character); } } // format amountText = amountText.Replace("$", "").Replace("?", "").Trim(); // money amount = TextTools.ParseDouble(amountText); } return(new TableControl(type, position, amount)); }
public double process(Image image, Rectangle rect, TableIdentifier parent) { // colors Image reduced = reducer.reduceColors(image); Image inverted = inverter.invert(reduced); Image replaced = replacer.replace(inverted); // image parent.renderImage(inker.replace(replaced), rect); // partition List <List <Image> > lines = HorizontalPartitioner.partition(replaced); if (lines.Count == 0) { return(Player.NO_BET); } // chars String textLine = ""; foreach (Image chars in lines[0]) { List <Image> combos = CharDecomposer.decompose(chars); foreach (Image chr in combos) { Image character = ImageCropper.crop(chr); textLine += identifyChars(character); } } // check for digit if (!TextTools.ContainsDigit(textLine)) { return(Player.NO_BET); } // sanity check if (!textLine.Contains("$")) { throw new ArgumentException("bet text has no dollar sign"); } // replace all non-numeric chars textLine = textLine.Trim(); string numericTextLine = textLine; foreach (char chr in textLine) { if (!TextTools.IsNumeric(chr) && !TextTools.IsPoint(chr)) { numericTextLine = numericTextLine.Replace(chr.ToString(), ""); } } // sanity check (sometimes some pixels are identifier as '.') if (numericTextLine.StartsWith(".")) { numericTextLine = numericTextLine.Substring(1); } // money return(TextTools.ParseDouble(numericTextLine)); }
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) { // 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); } }