예제 #1
0
        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
        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);
            }
        }