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); }
public TableSwitcher(Mouse mouse, DeviceControl device, List <Color> colors) { this.mouse = mouse; this.screen = new ScreenImageIterator(device); this.device = device; this.activeColor = colors[0].ToArgb(); this.taskbarReducer = new ColorPaletteReducer(colors.ToArray()); }
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 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); }
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 ReduceColorIterator(Iterator <Image> iterator, ColorReducer reducer) { this.iterator = iterator; this.reducer = reducer; }
private static List <ValueWithY> identifyValues(Image tableList, int x, int width, int height, ColorReducer reducer, ColorReplacer replacer, CharIdentifier identifier, ImagesRenderer renderer) { // rows Image rows = tableList.crop(x, width, 0, height); // reduce & replace rows = reducer.reduceColors(rows); rows = replacer.replace(rows); // render setImage(renderer, toBitmap(rows)); // chars List <ImageLine> lines = HorizontalPartitioner.partitionWithY(rows); // 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)); } } return(result); }