예제 #1
0
        internal static Point getPrecisionCenter(bool[][] image, Point targetPoint)
        {
            int tx = targetPoint.X;
            int ty = targetPoint.Y;

            if (tx < 0 || ty < 0 || tx > image.Length - 1 || ty > image[0].Length - 1)
            {
                throw new AlignmentPatternNotFoundException("Alignment Pattern finder exceeded out of image");
            }
            if (!image[targetPoint.X][targetPoint.Y])
            {
                int  scope = 0;
                bool found = false;
                while (!found)
                {
                    scope++;
                    for (int dy = scope; dy > -scope; dy--)
                    {
                        for (int dx = scope; dx > -scope; dx--)
                        {
                            int x = targetPoint.X + dx;
                            int y = targetPoint.Y + dy;
                            if (x < 0 || y < 0 || x > image.Length - 1 || y > image[0].Length - 1)
                            {
                                throw new AlignmentPatternNotFoundException("Alignment Pattern finder exceeded out of image");
                            }
                            if (image[x][y])
                            {
                                targetPoint = new Point(targetPoint.X + dx, targetPoint.Y + dy);
                                found       = true;
                            }
                        }
                    }
                }
            }
            int rx;
            int x2;
            int lx = x2 = (rx = targetPoint.X);
            int dy2;
            int y2;
            int uy = y2 = (dy2 = targetPoint.Y);

            while (lx >= 1 && !AlignmentPattern.targetPointOnTheCorner(image, lx, y2, lx - 1, y2))
            {
                lx--;
            }
            while (rx < image.Length - 1 && !AlignmentPattern.targetPointOnTheCorner(image, rx, y2, rx + 1, y2))
            {
                rx++;
            }
            while (uy >= 1 && !AlignmentPattern.targetPointOnTheCorner(image, x2, uy, x2, uy - 1))
            {
                uy--;
            }
            while (dy2 < image[0].Length - 1 && !AlignmentPattern.targetPointOnTheCorner(image, x2, dy2, x2, dy2 + 1))
            {
                dy2++;
            }
            return(new Point((lx + rx + 1) / 2, (uy + dy2 + 1) / 2));
        }
예제 #2
0
        internal static Point getPrecisionCenter(bool[][] image, Point targetPoint)
        {
            int x1 = targetPoint.X;
            int y1 = targetPoint.Y;

            if (x1 < 0 || y1 < 0 || (x1 > image.Length - 1 || y1 > image[0].Length - 1))
            {
                throw new AlignmentPatternNotFoundException("Alignment Pattern finder exceeded out of image");
            }
            if (!image[targetPoint.X][targetPoint.Y])
            {
                int  num  = 0;
                bool flag = false;
                while (!flag)
                {
                    ++num;
                    for (int index1 = num; index1 > -num; --index1)
                    {
                        for (int index2 = num; index2 > -num; --index2)
                        {
                            int index3 = targetPoint.X + index2;
                            int index4 = targetPoint.Y + index1;
                            if (index3 < 0 || index4 < 0 || (index3 > image.Length - 1 || index4 > image[0].Length - 1))
                            {
                                throw new AlignmentPatternNotFoundException("Alignment Pattern finder exceeded out of image");
                            }
                            if (image[index3][index4])
                            {
                                targetPoint = new Point(targetPoint.X + index2, targetPoint.Y + index1);
                                flag        = true;
                            }
                        }
                    }
                }
            }
            int x2;
            int x3   = x2 = targetPoint.X;
            int x4   = x2;
            int num1 = x2;
            int y2;
            int y3   = y2 = targetPoint.Y;
            int y4   = y2;
            int num2 = y2;

            while (x4 >= 1 && !AlignmentPattern.targetPointOnTheCorner(image, x4, num2, x4 - 1, num2))
            {
                --x4;
            }
            while (x3 < image.Length - 1 && !AlignmentPattern.targetPointOnTheCorner(image, x3, num2, x3 + 1, num2))
            {
                ++x3;
            }
            while (y4 >= 1 && !AlignmentPattern.targetPointOnTheCorner(image, num1, y4, num1, y4 - 1))
            {
                --y4;
            }
            while (y3 < image[0].Length - 1 && !AlignmentPattern.targetPointOnTheCorner(image, num1, y3, num1, y3 + 1))
            {
                ++y3;
            }
            return(new Point((x4 + x3 + 1) / 2, (y4 + y3 + 1) / 2));
        }