コード例 #1
0
ファイル: ASProcessor.cs プロジェクト: ngoclong1997/mctools
        private static Rect DetectBottomRightCorner(Bitmap image)
        {
            var   marker          = new bool[image.Width, image.Height];
            Point p               = CommonImageProcessing.FindDifferentColorPoint(new Point(Constant.AS_RIGHT_BORDER, Constant.AS_BOTTOM_BORDER), image, Constant.WHITE, ref marker);
            Rect  bottomRightRect = CommonImageProcessing.ExpandTheRectBlackPixel(p, image, ref marker);

            if (bottomRightRect == null)
            {
                p = CommonImageProcessing.FindDifferentColorPoint(new Point(Constant.AS_RIGHT_BORDER, Constant.AS_BOTTOM_BORDER), image, Constant.WHITE, ref marker);
                bottomRightRect = CommonImageProcessing.ExpandTheRectBlackPixel(p, image, ref marker);
                if (bottomRightRect == null)
                {
                    throw new Exception(ErrorUtils.getError(ErrorUtils.CAN_NOT_FIND_THE_TOP_RIGHT_FLAG_RECT, "Can not detect the top right flag rectangle. Tried 2 attempts!!"));
                }
                else
                {
                    ValidateBottomRightFlagRect(bottomRightRect);
                    return(bottomRightRect);
                }
            }
            else
            {
                ValidateBottomRightFlagRect(bottomRightRect);
                return(bottomRightRect);
            }
        }
コード例 #2
0
ファイル: ASProcessor.cs プロジェクト: ngoclong1997/mctools
        private static Rect DetectTopRightFlagRect(Bitmap image)
        {
            //In case the points expanded not match the template rectangle. We need to mark the visited point, so we don't go to these point again
            var   marker           = new bool[image.Width, image.Height];
            Point p                = CommonImageProcessing.FindDifferentColorPoint(new Point(Constant.AS_RIGHT_BORDER, Constant.AS_TOP_BORDER), image, Constant.WHITE, ref marker);
            Rect  topRightFlagRect = CommonImageProcessing.ExpandTheRectBlackPixel(p, image, ref marker);

            if (topRightFlagRect == null)
            {
                p = CommonImageProcessing.FindDifferentColorPoint(new Point(Constant.AS_RIGHT_BORDER, Constant.AS_TOP_BORDER), image, Constant.WHITE, ref marker);
                topRightFlagRect = CommonImageProcessing.ExpandTheRectBlackPixel(p, image, ref marker);
                if (topRightFlagRect == null)
                {
                    throw new Exception(ErrorUtils.getError(ErrorUtils.CAN_NOT_FIND_THE_TOP_RIGHT_FLAG_RECT, "Can not detect the top right flag rectangle. Tried 2 attempts!!"));
                }
                else
                {
                    ValidateTopRightFlagRect(topRightFlagRect);
                    return(topRightFlagRect);
                }
            }
            else
            {
                ValidateTopRightFlagRect(topRightFlagRect);
                return(topRightFlagRect);
            }
        }
コード例 #3
0
ファイル: ASProcessor.cs プロジェクト: ngoclong1997/mctools
        private static List <Rect> GetBelowHorizontalFlagRect(Rect belowFlgRect, Bitmap image)
        {
            List <Rect> result = new List <Rect>();
            Rect        rect;

            bool[,] marker = new bool[image.Width, image.Height];
            int   y            = belowFlgRect.GetCenterPoint().y;
            int   x            = belowFlgRect.GetCenterPoint().x;
            int   totalFlgRect = Constant.BELOW_HORIZONTAL_FLAG_RECT;
            Point p;

            while (result.Count < totalFlgRect)
            {
                p = new Point(x, y);
                if (!p.IsValidPoint())
                {
                    throw new Exception(ErrorUtils.getError(ErrorUtils.CAN_NOT_GET_ENOUGH_HORIZONTAL_FLAG_RECT, "Can not get enough horizontal flag rect!!"));
                }
                if (!marker[x, y] && CommonImageProcessing.IsBlackColor(new Point(x, y), image))
                {
                    rect = CommonImageProcessing.ExpandTheRectBlackPixel(new Point(x, y), image, ref marker);
                    if (rect == null)
                    {
                        throw new Exception(ErrorUtils.getError(ErrorUtils.CAN_NOT_GET_ENOUGH_HORIZONTAL_FLAG_RECT, "Can not get enough horizontal flag rect!!"));
                    }
                    if (CommonImageProcessing.IsFlagRectangle(rect))
                    {
                        result.Add(rect);
                    }
                }
                x--;
            }
            return(result);
        }
コード例 #4
0
ファイル: ASProcessor.cs プロジェクト: ngoclong1997/mctools
        private static List <Rect> GetVerticalFlagRect(Rect aboveFlgRect, Bitmap image)
        {
            List <Rect> result = new List <Rect>();
            Rect        rect;

            bool[,] marker = new bool[image.Width, image.Height];
            int   y            = aboveFlgRect.GetCenterPoint().y;
            int   x            = aboveFlgRect.GetCenterPoint().x;
            int   totalFlgRect = TemplateUtils.GetNumberOfVerticalFLagRect(Globals.currentTemplate);
            Point p;

            while (result.Count < totalFlgRect)
            {
                p = new Point(x, y);
                if (!p.IsValidPoint())
                {
                    throw new Exception(ErrorUtils.getError(ErrorUtils.CAN_NOT_GET_ENOUGH_VERTICAL_FLAG_RECT, "Can not get enough vertical flag rect!!"));
                }
                if (!marker[x, y] && CommonImageProcessing.IsBlackColor(new Point(x, y), image))
                {
                    rect = CommonImageProcessing.ExpandTheRectBlackPixel(new Point(x, y), image, ref marker);
                    if (rect == null)
                    {
                        throw new Exception(ErrorUtils.getError(ErrorUtils.CAN_NOT_GET_ENOUGH_VERTICAL_FLAG_RECT, "Can not get enough vertical flag rect!!"));
                    }
                    if (CommonImageProcessing.IsFlagRectangle(rect))
                    {
                        result.Add(rect);
                    }
                }
                y++;
            }
            return(result);
        }