Example #1
0
        public String NetworkOCR(Rectangle aRect, Color aSearchColor)
        {
            while (aRect.Bottom >= bmp.Height)
            {
                aRect.Height--;
            }


            ImageNet net = new ImageNet(bmp);

            RouteInfo allRoutes = net.CreateRoutes(aRect, aSearchColor);

            Rectangle searchrect = aRect;

            int xdiffer = aRect.Width >= 6 ? 1 : 0;

            searchrect.Width = searchrect.Width / 2 - xdiffer;
            RouteInfo leftRoutes = net.CreateRoutes(searchrect, aSearchColor);

            searchrect.Height /= 2;

            Point topCenter    = new Point(-1, searchrect.Bottom - 1);
            Point bottomCenter = new Point(-1, searchrect.Bottom + 1);

            RouteInfo topLeft = net.CreateRoutes(searchrect, aSearchColor);

            searchrect.Y     += aRect.Height / 2;
            searchrect.Height = aRect.Bottom - searchrect.Y;
            RouteInfo bottomLeft = net.CreateRoutes(searchrect, aSearchColor);

            int width = searchrect.Width;

            searchrect       = aRect;
            searchrect.X    += width + xdiffer;
            searchrect.Width = aRect.Right - searchrect.X;
            RouteInfo rightRoutes = net.CreateRoutes(searchrect, aSearchColor);

            searchrect.Height /= 2;
            RouteInfo topRight = net.CreateRoutes(searchrect, aSearchColor);

            searchrect.Y     += aRect.Height / 2;
            searchrect.Height = aRect.Bottom - searchrect.Y;
            RouteInfo bottomRight = net.CreateRoutes(searchrect, aSearchColor);

            Rectangle rightmostrect = new Rectangle(rightRoutes.Right.X - 3, rightRoutes.Top.Y, 3, aRect.Height);
            RouteInfo rightmost     = net.CreateRoutes(rightmostrect, aSearchColor);

            if (topRight == null)
            {
                if (allRoutes.hashRoute(new Point(bottomLeft.Left.X, bottomLeft.Bottom.Y), new Point(bottomRight.Bottom.X, bottomRight.Bottom.Y), movedirs.right))
                {
                    return("1");
                }
                return("");
            }

            if (bottomLeft != null && allRoutes.hashRoute(allRoutes.Top, allRoutes.Bottom, movedirs.down) && !bottomLeft.hashRoute(bottomLeft.Left, bottomCenter, movedirs.right | movedirs.up | movedirs.left))
            {
                return(""); // $
            }

            if (aRect.Width <= 3 && aRect.Height > 4)
            {
                if (topLeft != null && topRight != null && bottomRight != null && bottomLeft != null)
                {
                    if (allRoutes.hashRoute(bottomLeft.Left, bottomRight.Right, movedirs.right))
                    {
                        return("1");
                    }
                }
            }


            if (aRect.Width <= 3 || aRect.Height < 3 || aRect.Width > 15)
            {
                return("");
            }


            if (bottomLeft == null || bottomLeft.Bottom.Y <= bottomCenter.Y)
            {
                if (topRight.Top.Y == topLeft.Left.Y && allRoutes.hashRoute(topLeft.Top, topRight.Top, movedirs.right))
                {
                    return("7");
                }
            }

            if (bottomRight == null && bottomLeft == null || topLeft == null || topRight == null)
            {
                return("");
            }


            if (topLeft.Top.Y == topRight.Top.Y && !allRoutes.hashRoute(topLeft.Top, topRight.Top, movedirs.right))
            {
                if (topRight.Top.Y != topRight.Right.Y)
                {
                    return("10");
                }
            }


            if (leftRoutes.hashRoute(leftRoutes.Bottom, leftRoutes.Top, movedirs.all))
            {
                if (!topRight.hashRoute(topRight.Bottom, topRight.Top, movedirs.all))
                {
                    if (bottomRight.hashRoute(bottomRight.Bottom, bottomCenter, movedirs.right | movedirs.up))
                    {
                        return("6");
                    }
                }
                else
                {
                    if (bottomLeft.Left.X < topLeft.Left.X && topRight.Right.X < bottomRight.Right.X &&
                        bottomLeft.Left.Y == bottomRight.Bottom.Y &&
                        !allRoutes.hashRoute(leftRoutes.Bottom, new Point(rightRoutes.Right.X, -1), movedirs.right))
                    {
                        return("A");
                    }


                    if (!rightmost.hashRoute(rightmost.Top, topCenter, movedirs.all))
                    {
                        if (allRoutes.hashRoute(topLeft.Top, topRight.Top, movedirs.up | movedirs.right | movedirs.left))
                        {
                            return("6");
                        }
                        return("k");
                    }


                    if (Math.Abs(bottomLeft.Left.Y - allRoutes.Bottom.Y) < 3)
                    {
                        if (allRoutes.hashRoute(bottomLeft.Left, allRoutes.Right, movedirs.right))
                        {
                            if (allRoutes.Left.Y < allRoutes.Bottom.Y)
                            {
                                return("4");
                            }
                            return("1");
                        }
                    }
                    Point point = new Point(leftRoutes.Right.X, topCenter.Y - 1);

                    if (allRoutes.hashRoute(allRoutes.Left, new Point(allRoutes.Right.X, -1), movedirs.right))
                    {
                        return("4");
                    }

                    if (!bottomRight.hashRoute(bottomRight.Bottom, bottomRight.Right, movedirs.right | movedirs.up) ||
                        bottomRight.Bottom.Y > bottomLeft.Bottom.Y)
                    {
                        return("q");
                    }

                    Point topPoint    = new Point(aRect.X, aRect.Y + 2);
                    Point bottomPoint = new Point(aRect.X, aRect.Bottom - 2);

                    Rectangle rect  = new Rectangle(aRect.X, aRect.Y + 2, aRect.Width, aRect.Height - 4);
                    RouteInfo check = net.CreateRoutes(rect, aSearchColor);
                    if (check.hashRoute(check.Left, check.Right, movedirs.all))
                    {
                        return("8");
                    }

                    return("0");
                }
            }


            else
            {
                if (rightmost.hashRoute(rightmost.Bottom, rightmost.Top, movedirs.all))
                {
                    //bmp.Save("C:\\joo.bmp");
                    if (rightRoutes.Top.Y == rightRoutes.Right.Y)
                    {
                        if (!topRight.hashRoute(topRight.Top, topRight.Bottom, movedirs.all))
                        {
                            return("5");
                        }
                        if (bottomLeft.Left.X == allRoutes.Left.X)
                        {
                            return("j");
                        }
                        else
                        {
                            return("7");
                        }
                    }

                    if (topLeft.hashRoute(topLeft.Left, topCenter, movedirs.all))
                    {
                        if (bottomLeft.Bottom.X - allRoutes.Left.X > 2 && allRoutes.hashRoute(bottomLeft.Bottom, bottomRight.Bottom, movedirs.right))
                        {
                            return("4");
                        }
                        return("9");
                    }
                    else
                    {
                        if (rightRoutes.hashRoute(rightRoutes.Bottom, new Point(rightRoutes.Right.X, -1), movedirs.right))
                        {
                            return("2");
                        }
                        return("3");
                    }
                }
                else
                {
                    if (!rightRoutes.hashRoute(rightRoutes.Top, topCenter, movedirs.all))
                    {
                        return("5");
                    }
                    return("2");
                }
            }

            return("");
        }
Example #2
0
        private LANDS RegLand(Rectangle arect, Color asearchcolor)
        {
            Rectangle rect = new Rectangle(arect.Location, arect.Size);

            if (GetUpPixel(asearchcolor, arect) == -1)
            {
                return(LANDS.EUNKNOWN);
            }


            ImageNet  net    = new ImageNet(bmp);
            RouteInfo routes = net.CreateRoutes(rect, asearchcolor);

            Point CenterTop = new Point(arect.X + arect.Width / 2, rect.Top);

            bool  foundfirst = false;
            bool  foundcap   = false;
            Point checkpoint = new Point(routes.Left.X, routes.Top.Y);

            for (; checkpoint.X < routes.Right.X; checkpoint.X++)
            {
                bool hashroute = routes.hashRoute(checkpoint, checkpoint, movedirs.all);
                if (foundfirst)
                {
                    if (foundcap && hashroute)
                    {
                        return(LANDS.EHEART);
                    }

                    foundcap = !hashroute;
                }
                else
                {
                    foundfirst = hashroute;
                }
            }


            if (routes.hashRoute(routes.Left, new Point(routes.Top.X, -1), movedirs.upright))
            {
                if (routes.hashRoute(routes.Left, new Point(routes.Bottom.X, -1), movedirs.downright))
                {
                    return(LANDS.EDIAMOND);
                }
            }

            int maxy  = routes.Top.Y + (routes.Bottom.Y - routes.Top.Y) / 2;
            int lastx = routes.Top.X;

            checkpoint = new Point(routes.Top.X, routes.Top.Y);
            for (; checkpoint.Y < maxy; checkpoint.Y++)
            {
                while (check_pixel(checkpoint, asearchcolor))
                {
                    checkpoint.X++;
                }
                checkpoint.X--;
                if (checkpoint.X < lastx)
                {
                    return(LANDS.ECROSS);
                }
                lastx = checkpoint.X;
            }


            return(LANDS.ESPADE);
        }