Exemplo n.º 1
0
        public static Point locateTable(Image screen)
        {
            // get a reference to the current assembly
            Log.Debug("screen dimensions {" + screen.width + "," + screen.height + "}");

            // read from assembly
            Log.Debug("reading table pattern");
            Image pattern = AssemblyTools.getAssemblyImage("table_top_left_corner.png");

            // reduce colors
            Log.Debug("reducing pattern colors");
            ColorReducer reducer = new ColorReducers.Table();

            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 table pattern x=" + x + ", y=" + y);
                        return(new Point(x, y));
                    }
                }
            }
            throw new Exception("Table pattern not found");
        }
Exemplo n.º 2
0
        public static Point locateUnknownTable(Image screen, List <Point> offsets, TableLayout layout)
        {
            // vars
            Image    originalScreen = screen;
            Image    pattern        = tablePattern;
            DateTime start          = DateTime.Now;

            // reduce or use exact image
            if (pattern == Image.Empty)
            {
                // read from assembly
                Log.Debug("reading table pattern");
                pattern = AssemblyTools.getAssemblyImage("table_top_left_corner.png");

                // reduce colors
                Log.Debug("reducing pattern colors");
                ColorReducer reducer = new ColorReducers.Table();
                screen  = reducer.reduceColors(screen);
                pattern = reducer.reduceColors(pattern);
            }

            // first line
            int[] patternFirstLine = pattern.lines[0];

            // locate pattern
            for (int y = 0; y < screen.height - pattern.height; y++)
            {
                int[] screenLine = screen.lines[y];
                for (int x = 0; x < screen.width - pattern.width; x++)
                {
                    // check first line
                    if (match(patternFirstLine, screenLine, x))
                    {
                        // first corner
                        Image cornerTL = screen.crop(x, x + pattern.width, y, y + pattern.height);
                        if (ImageTools.match(cornerTL, pattern))
                        {
                            // second corner
                            Image cornerBR = originalScreen.crop(x + layout.CornerBottom.X, x + layout.CornerBottom.X + layout.CornerBottom.Width,
                                                                 y + layout.CornerBottom.Y, y + layout.CornerBottom.Y + layout.CornerBottom.Height);
                            if (isTableBottomRightCornerVisible(cornerBR))
                            {
                                // remember exact pattern
                                if (tablePattern == Image.Empty)
                                {
                                    tablePattern = originalScreen.crop(x, x + pattern.width, y, y + pattern.height);
                                }

                                // return location
                                Point point = new Point(x, y);
                                if (!offsets.Contains(point))
                                {
                                    Log.Info("found new table pattern x=" + x + ", y=" + y + " took " + DateTime.Now.Subtract(start).TotalMilliseconds + "ms");
                                    return(point);
                                }
                            }
                        }
                    }
                }
            }
            return(Point.Empty);
        }