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 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)); }