public static List <CardPattern> readCards(String path) { string[] cards = Directory.GetFiles(path, "card_*.png"); List <CardPattern> patterns = new List <CardPattern>(); foreach (String filepath in cards) { // get png Image png = readPng(filepath); // filename only string filename = Path.GetFileName(filepath); filename = filename.Replace("card_", ""); // crop Image image = cropTransparentLines(png); // colors image = reducer.reduceColors(image); // new pattern Card.SuitEnum suit = toSuit(filename); Card.RankEnum rank = toRank(filename); CardPattern pattern = new CardPattern(image, suit, rank); patterns.Add(pattern); } return(patterns); }
private void reducePattern() { foreach (CardPattern pattern in cards) { pattern.Image = reducer.reduceColors(pattern.Image); } }
public static Point locatePattern(string patternName, ColorReducer reducer, Image screen) { // get a reference to the current assembly Log.Debug("screen dimensions {" + screen.width + "," + screen.height + "}"); // read from assembly Log.Debug("reading " + patternName + " pattern"); Image pattern = AssemblyTools.getAssemblyImage(patternName); // reduce colors Log.Debug("reducing pattern colors"); pattern = reducer.reduceColors(pattern); screen = reducer.reduceColors(screen); // locate pattern Log.Fine("scanning lines ..."); for (int y = 0; y < screen.height - pattern.height; y++) { Log.FineIf(y % 100 == 0, y + "/" + screen.height); for (int x = 0; x < screen.width - pattern.width; x++) { Image sub = screen.crop(x, x + pattern.width, y, y + pattern.height); if (ImageTools.match(sub, pattern)) { Log.Info("found " + patternName + " pattern x=" + x + ", y=" + y); return(new Point(x, y)); } } } return(Point.Empty); }
private Point checkTaskbarActivity() { int tries = 0; while (true) { // tries tries++; if (tries > 2) { return(Point.Empty); } // crop Image screenshot = screen.next(); int xStart = 250; int xEnd = device.DisplayWidth - 100; // scan fist row { int yStart = device.DisplayHeight - 36; int yEnd = yStart + 2; Image taskbarLine = screenshot.crop(xStart, xEnd, yStart, yEnd); taskbarLine = taskbarReducer.reduceColors(taskbarLine); int xPos = locateColor(taskbarLine, activeColor); if (xPos != -1) { // log ErrorHandler.ReportExceptionWithImage(new Exception("taskbar active"), "window seems to be blocked", screenshot); // location return(new Point(xStart + xPos + 30, yStart - 5)); } } // scan second row { int yStart = device.DisplayHeight - 5; int yEnd = yStart + 2; Image taskbarLine = screenshot.crop(xStart, xEnd, yStart, yEnd); taskbarLine = taskbarReducer.reduceColors(taskbarLine); int xPos = locateColor(taskbarLine, activeColor); if (xPos != -1) { // log ErrorHandler.ReportExceptionWithImage(new Exception("taskbar active"), "window seems to be blocked", screenshot); // location return(new Point(xStart + xPos + 30, yStart - 5)); } } Thread.Sleep(100); } }
public bool process(Image image, Rectangle rect, TableIdentifier parent) { // crop Image cropped = crop(image, rect); // real color unknown if (realButtonColor == null) { // colors Image reduced = reducer.reduceColors(cropped); parent.renderImage(reduced, rect); // check bool visible = ControlsIdentifier.areReducedControlsVisible(reduced); if (visible) { realButtonColor = ImageTools.getSignificantColorRange(cropped); } return(visible); } // real color known else { // check return(ControlsIdentifier.areControlsVisibleWithNativeColor(cropped, realButtonColor)); } }
public OpenSeatPipeline() { Log.Debug("reading seat pattern"); Stream stream = AssemblyTools.getAssemblyStream("open_seat.png"); Bitmap bitmap = Bitmap.FromStream(stream) as Bitmap; pattern = ImageTools.toImage(bitmap); pattern = reducer.reduceColors(pattern); }
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 bool process(Image image, Rectangle rect, TableIdentifier parent) { // colors Image reduced = reducer.reduceColors(image); // render parent.renderImage(reduced, rect); // positions return(SmallCardsIdentifier.areReducedSmallCards(reduced)); }
public List <Card> process(Image image, Rectangle rect, TableIdentifier parent) { // colors Image reduced = reducer.reduceColors(image); parent.renderImage(reduced, rect); // hand List <Card> cards = identifier.identifyCards(reduced); return(cards); }
private static bool ContainsJoinedColor(Image cell, ColorReducer reducer) { cell = reducer.reduceColors(cell); foreach (int pixel in cell.pixels) { if (pixel == ColorReducers.LobbyCharsJoined.JOINED_COLOR.ToArgb()) { return(true); } } return(false); }
private static bool isPatternVisible(Image image, ColorReducer reducer, Image pattern, string patternName) { // reduce colors Log.Debug("reducing pattern colors"); pattern = reducer.reduceColors(pattern); image = reducer.reduceColors(image); // locate pattern Log.Debug("scanning lines ..."); for (int y = 0; y < image.height - pattern.height; y++) { Log.FineIf(y % 100 == 0, y + "/" + image.height); for (int x = 0; x < image.width - pattern.width; x++) { Image sub = image.crop(x, x + pattern.width, y, y + pattern.height); if (ImageTools.match(sub, pattern)) { Log.Info("found " + patternName + " pattern x=" + x + ", y=" + y); return(true); } } } return(false); }
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 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>()); } }
private bool IsOpen(ColorReducer reducer, Rectangle seat, Image pattern, Image tableImage, int maxScanY) { Image seatCropped = tableImage.crop(seat.X, seat.X + seat.Width, seat.Y, seat.Y + seat.Height); Image seatReduced = reducer.reduceColors(seatCropped); for (int y = 0; y < maxScanY; y++) { Log.FineIf(y % 100 == 0, y + "/" + seatReduced.height); for (int x = 0; x < seatReduced.width - pattern.width; x++) { Image sub = seatReduced.crop(x, x + pattern.width, y, y + pattern.height); if (ImageTools.match(sub, pattern)) { Log.Info("found open seat pattern x=" + x + ", y=" + y); return(true); } } } return(false); }
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 static bool isButton(Image image) { Image reduced = reducer.reduceColors(image); return(isReducedButton(reduced)); }
public Image next() { return(reducer.reduceColors(iterator.next())); }
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 bool areControlsVisible(Image image) { Image reduced = reducer.reduceColors(image); return(areReducedControlsVisible(reduced)); }
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)); }