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)); }
private double processBet(Image table, Image bet, Rectangle rect, TableIdentifier parent, double defaultBet) { try { return(betPipe.process(bet, rect, parent)); } catch (Exception ex) { ErrorHandler.BeepError(); if (SAVE_EXCEPTION_REPORTS) { ErrorHandler.ReportBetException(ex, table, bet, "Cannot identify bet"); } else { Log.Error("Cannot identify bet"); } return(defaultBet); } }
public List <Card> process(Image image, Rectangle rect, TableIdentifier parent) { // colors Image reduced = reducer.reduceColors(image); parent.renderImage(reduced, rect); // empty? if (!nearlySameColor(reduced)) { List <Card> cards = identifier.identifyCards(reduced); Log.Fine("found " + cards.Count + " cards"); return(cards); } else { Log.Fine("no cards"); return(new List <Card>()); } }
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"); }
public int process(Image image, Rectangle[] rects, TableIdentifier parent) { // crop List <Image> images = new List <Image>(); foreach (Rectangle rect in rects) { Image cropped = crop(image, rect); Image reduced = reducer.reduceColors(cropped); images.Add(reduced); parent.renderImage(reduced, rect); } // positions for (int i = 0; i < images.Count; i++) { if (ButtonIdentifier.isReducedButton(images[i])) { return(i); } } throw new Exception("Cannot identify button"); }
public List <String> process(Image image, int id, Rectangle rect, TableIdentifier parent, bool isMySeat) { // colors Image reduced = reducer.reduceColors(image); Image inverted = inverter.invert(reduced); Image replaced = replacer.replace(inverted); // text List <String> textLines = identifyLines(replaced, rect, parent); // if highlighted if (isMySeat && textLines.Count == 0) { // smaller rect Image smallerImage = reduced.crop(15, reduced.width - 15, 1, reduced.height - 1); // not inverted Image notInverted = replacer.replace(smallerImage); textLines = identifyLines(notInverted, rect, parent); } return(textLines); }
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) { 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 ##"); } }
public TableOpener(DeviceControl deviceControl, Mouse mouse, Keyboard keyboard, TableIdentifier tableIdentifier) { this.deviceControl = deviceControl; this.mouse = mouse; this.keyboard = keyboard; this.tableIdentifier = tableIdentifier; this.controller = new Controller(keyboard, mouse, tableIdentifier, new ScreenImageIterator(deviceControl)); // seat occupied pattern seatOccupiedPattern = AssemblyTools.getAssemblyImage("error.png"); }