Пример #1
0
        public bool GetBoardParameters(Pixels pix, out BoardParameters bp)
        {
            bp                = new BoardParameters();
            bp.BoardRect      = System.Drawing.Rectangle.Empty;
            bp.LinedBoardRect = System.Drawing.Rectangle.Empty;
            bp.FieldHeight    = 0;
            bp.FieldWidth     = 0;
            bp.BlockSize      = 0;

            bp.BoardRect = FindBoard(pix);
            if (bp.BoardRect == System.Drawing.Rectangle.Empty)
            {
                return(false);
            }
            float[] grayCols, grayRows;
            bp.LinedBoardRect = FindLinedBoard(pix, bp.BoardRect, out grayCols, out grayRows);
            double blockWidth, blockHeight;
            bool   foundLines1 = CalculateFieldPosition(bp.LinedBoardRect.Left, bp.LinedBoardRect.Width, grayCols, out bp.FieldWidth, out blockWidth);
            bool   foundLines2 = CalculateFieldPosition(bp.LinedBoardRect.Top, bp.LinedBoardRect.Height, grayRows, out bp.FieldHeight, out blockHeight);

            if (Math.Abs(blockHeight - blockWidth) > 1)
            {
                return(false);
            }
            bp.BlockSize = (blockHeight + blockWidth) / 2;
            return(foundLines1 && foundLines2);
        }
Пример #2
0
        public BoardInfo ProcessImage(BoardParameters bp, Pixels pix)
        {
            BoardInfo boardInfo = null;

            boardInfo = new BoardInfo(bp.FieldWidth, bp.FieldHeight);
            int halfSize = (int)(bp.BlockSize / 2) + 1;

            int[,] circleRadiusData = CalculateRadii((dx, dy) => (int)Math.Sqrt(dx * dx + dy * dy), halfSize);
            int[,] squareRadiusData = CalculateRadii((dx, dy) => (int)Math.Max(Math.Abs(dx), Math.Abs(dy)), halfSize);

            for (int y = 0; y < bp.FieldHeight; y++)
            {
                for (int x = 0; x < bp.FieldWidth; x++)
                {
                    int        px      = (int)Math.Round(bp.LinedBoardRect.Left + bp.BlockSize * x);
                    int        py      = (int)Math.Round(bp.LinedBoardRect.Top + bp.BlockSize * y);
                    RawColor[] circles = RadiusColor(pix,
                                                     new Point(px, py),
                                                     circleRadiusData,
                                                     2 * halfSize
                                                     );
                    RawColor[] squares = RadiusColor(pix,
                                                     new Point(px, py),
                                                     squareRadiusData,
                                                     2 * halfSize
                                                     );

                    PointInfo info = new PointInfo();
                    info.StoneColor      = GetStoneColor(circles, bp.BlockSize);
                    info.SmallStoneColor = GetSmallStoneColor(circles, bp.BlockSize);
                    if (info.SmallStoneColor == info.StoneColor)                    //Small stone is part of the real stone
                    {
                        info.SmallStoneColor = StoneColor.None;
                    }
                    if (GetCircleMarker(circles, bp.BlockSize, info.StoneColor))
                    {
                        if (info.SmallStoneColor != StoneColor.Black)                        //Can't distinguish circle from small stone
                        {
                            info.Marker = Marker.Circle;
                        }
                    }
                    if (GetSquareMarker(squares, bp.BlockSize, info.StoneColor))
                    {
                        info.Marker = Marker.Square;
                    }
                    boardInfo.Board[x, y] = info;
                }
            }
            //MirrorBoardInfo(boardInfo);

            return(boardInfo);
        }
        public BoardInfo ProcessImage(BoardParameters bp, Pixels pix)
        {
            BoardInfo boardInfo = null;
            boardInfo = new BoardInfo(bp.FieldWidth, bp.FieldHeight);
            int halfSize = (int)(bp.BlockSize / 2) + 1;
            int[,] circleRadiusData = CalculateRadii((dx, dy) => (int)Math.Sqrt(dx * dx + dy * dy), halfSize);
            int[,] squareRadiusData = CalculateRadii((dx, dy) => (int)Math.Max(Math.Abs(dx), Math.Abs(dy)), halfSize);

            for (int y = 0; y < bp.FieldHeight; y++)
                for (int x = 0; x < bp.FieldWidth; x++)
                {
                    int px = (int)Math.Round(bp.LinedBoardRect.Left + bp.BlockSize * x);
                    int py = (int)Math.Round(bp.LinedBoardRect.Top + bp.BlockSize * y);
                    RawColor[] circles = RadiusColor(pix,
                        new Point(px, py),
                        circleRadiusData,
                        2 * halfSize
                        );
                    RawColor[] squares = RadiusColor(pix,
                        new Point(px, py),
                        squareRadiusData,
                        2 * halfSize
                        );

                    PointInfo info = new PointInfo();
                    info.StoneColor = GetStoneColor(circles, bp.BlockSize);
                    info.SmallStoneColor = GetSmallStoneColor(circles, bp.BlockSize);
                    if (info.SmallStoneColor == info.StoneColor)//Small stone is part of the real stone
                        info.SmallStoneColor = StoneColor.None;
                    if (GetCircleMarker(circles, bp.BlockSize, info.StoneColor))
                    {
                        if (info.SmallStoneColor != StoneColor.Black)//Can't distinguish circle from small stone
                            info.Marker = Marker.Circle;
                    }
                    if (GetSquareMarker(squares, bp.BlockSize, info.StoneColor))
                        info.Marker = Marker.Square;
                    boardInfo.Board[x, y] = info;
                }
            //MirrorBoardInfo(boardInfo);

            return boardInfo;
        }
        public bool GetBoardParameters(Pixels pix, out BoardParameters bp)
        {
            bp = new BoardParameters();
            bp.BoardRect = System.Drawing.Rectangle.Empty;
            bp.LinedBoardRect = System.Drawing.Rectangle.Empty;
            bp.FieldHeight = 0;
            bp.FieldWidth = 0;
            bp.BlockSize = 0;

            bp.BoardRect = FindBoard(pix);
            if (bp.BoardRect == System.Drawing.Rectangle.Empty)
                return false;
            float[] grayCols, grayRows;
            bp.LinedBoardRect = FindLinedBoard(pix, bp.BoardRect, out grayCols, out grayRows);
            double blockWidth, blockHeight;
            bool foundLines1 = CalculateFieldPosition(bp.LinedBoardRect.Left, bp.LinedBoardRect.Width, grayCols, out bp.FieldWidth, out blockWidth);
            bool foundLines2 = CalculateFieldPosition(bp.LinedBoardRect.Top, bp.LinedBoardRect.Height, grayRows, out bp.FieldHeight, out blockHeight);
            if (Math.Abs(blockHeight - blockWidth) > 1)
                return false;
            bp.BlockSize = (blockHeight + blockWidth) / 2;
            return foundLines1 && foundLines2;
        }