예제 #1
0
        internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
        {
            int moduleSize = finderPattern.getModuleSize();

            Axis axis        = new Axis(finderPattern.getAngle(), moduleSize);
            int  sqrtCenters = logicalCenters.Length;

            Point[][] centers = new Point[sqrtCenters][];
            for (int i = 0; i < sqrtCenters; i++)
            {
                centers[i] = new Point[sqrtCenters];
            }

            axis.Origin   = finderPattern.getCenter(FinderPattern.UL);
            centers[0][0] = axis.translate(3, 3);
            canvas.drawCross(centers[0][0], QRStudio.Engine.Codec.Util.Color_Fields.BLUE);

            axis.Origin = finderPattern.getCenter(FinderPattern.UR);
            centers[sqrtCenters - 1][0] = axis.translate(-3, 3);
            canvas.drawCross(centers[sqrtCenters - 1][0], QRStudio.Engine.Codec.Util.Color_Fields.BLUE);

            axis.Origin = finderPattern.getCenter(FinderPattern.DL);
            centers[0][sqrtCenters - 1] = axis.translate(3, -3);
            canvas.drawCross(centers[0][sqrtCenters - 1], QRStudio.Engine.Codec.Util.Color_Fields.BLUE);

            Point tmpPoint = centers[0][0];

            for (int y = 0; y < sqrtCenters; y++)
            {
                for (int x = 0; x < sqrtCenters; x++)
                {
                    if ((x == 0 && y == 0) || (x == 0 && y == sqrtCenters - 1) || (x == sqrtCenters - 1 && y == 0))
                    {
                        continue;
                    }
                    Point target = null;
                    if (y == 0)
                    {
                        if (x > 0 && x < sqrtCenters - 1)
                        {
                            target = axis.translate(centers[x - 1][y], logicalCenters[x][y].X - logicalCenters[x - 1][y].X, 0);
                        }
                        centers[x][y] = new Point(target.X, target.Y);
                        canvas.drawCross(centers[x][y], QRStudio.Engine.Codec.Util.Color_Fields.RED);
                    }
                    else if (x == 0)
                    {
                        if (y > 0 && y < sqrtCenters - 1)
                        {
                            target = axis.translate(centers[x][y - 1], 0, logicalCenters[x][y].Y - logicalCenters[x][y - 1].Y);
                        }
                        centers[x][y] = new Point(target.X, target.Y);
                        canvas.drawCross(centers[x][y], QRStudio.Engine.Codec.Util.Color_Fields.RED);
                    }
                    else
                    {
                        Point t1 = axis.translate(centers[x - 1][y], logicalCenters[x][y].X - logicalCenters[x - 1][y].X, 0);
                        Point t2 = axis.translate(centers[x][y - 1], 0, logicalCenters[x][y].Y - logicalCenters[x][y - 1].Y);
                        centers[x][y] = new Point((t1.X + t2.X) / 2, (t1.Y + t2.Y) / 2 + 1);
                    }
                    if (finderPattern.Version > 1)
                    {
                        Point precisionCenter = getPrecisionCenter(image, centers[x][y]);

                        if (centers[x][y].distanceOf(precisionCenter) < 6)
                        {
                            canvas.drawCross(centers[x][y], QRStudio.Engine.Codec.Util.Color_Fields.RED);
                            int dx = precisionCenter.X - centers[x][y].X;
                            int dy = precisionCenter.Y - centers[x][y].Y;
                            canvas.println("Adjust AP(" + x + "," + y + ") to d(" + dx + "," + dy + ")");

                            centers[x][y] = precisionCenter;
                        }
                    }
                    canvas.drawCross(centers[x][y], QRStudio.Engine.Codec.Util.Color_Fields.BLUE);
                    canvas.drawLine(new Line(tmpPoint, centers[x][y]), QRStudio.Engine.Codec.Util.Color_Fields.LIGHTBLUE);
                    tmpPoint = centers[x][y];
                }
            }
            return(centers);
        }
        internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
        {
            int  modulePitch = finderPattern.getModuleSize();
            Axis axis        = new Axis(finderPattern.getAngle(), modulePitch);
            int  length      = logicalCenters.Length;

            Point[][] pointArray = new Point[length][];
            for (int i = 0; i < length; i++)
            {
                pointArray[i] = new Point[length];
            }
            axis.Origin      = finderPattern.getCenter(0);
            pointArray[0][0] = axis.translate(3, 3);
            canvas.drawCross(pointArray[0][0], Color_Fields.BLUE);
            axis.Origin = finderPattern.getCenter(1);
            pointArray[length - 1][0] = axis.translate(-3, 3);
            canvas.drawCross(pointArray[length - 1][0], Color_Fields.BLUE);
            axis.Origin = finderPattern.getCenter(2);
            pointArray[0][length - 1] = axis.translate(3, -3);
            canvas.drawCross(pointArray[0][length - 1], Color_Fields.BLUE);
            Point point = pointArray[0][0];

            for (int j = 0; j < length; j++)
            {
                for (int k = 0; k < length; k++)
                {
                    if ((((k != 0) || (j != 0)) && ((k != 0) || (j != (length - 1)))) && ((k != (length - 1)) || (j != 0)))
                    {
                        Point point2 = null;
                        if (j == 0)
                        {
                            if ((k > 0) && (k < (length - 1)))
                            {
                                point2 = axis.translate(pointArray[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                            }
                            pointArray[k][j] = new Point(point2.X, point2.Y);
                            canvas.drawCross(pointArray[k][j], Color_Fields.RED);
                        }
                        else if (k == 0)
                        {
                            if ((j > 0) && (j < (length - 1)))
                            {
                                point2 = axis.translate(pointArray[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                            }
                            pointArray[k][j] = new Point(point2.X, point2.Y);
                            canvas.drawCross(pointArray[k][j], Color_Fields.RED);
                        }
                        else
                        {
                            Point point3 = axis.translate(pointArray[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                            Point point4 = axis.translate(pointArray[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                            pointArray[k][j] = new Point((point3.X + point4.X) / 2, ((point3.Y + point4.Y) / 2) + 1);
                        }
                        if (finderPattern.Version > 1)
                        {
                            Point other = getPrecisionCenter(image, pointArray[k][j]);
                            if (pointArray[k][j].distanceOf(other) < 6)
                            {
                                canvas.drawCross(pointArray[k][j], Color_Fields.RED);
                                int num6 = other.X - pointArray[k][j].X;
                                int num7 = other.Y - pointArray[k][j].Y;
                                canvas.println(string.Concat(new object[] { "Adjust AP(", k, ",", j, ") to d(", num6, ",", num7, ")" }));
                                pointArray[k][j] = other;
                            }
                        }
                        canvas.drawCross(pointArray[k][j], Color_Fields.BLUE);
                        canvas.drawLine(new Line(point, pointArray[k][j]), Color_Fields.LIGHTBLUE);
                        point = pointArray[k][j];
                    }
                }
            }
            return(pointArray);
        }
예제 #3
0
        internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
        {
            int  moduleSize = finderPattern.getModuleSize();
            Axis axis       = new Axis(finderPattern.getAngle(), moduleSize);
            int  num        = logicalCenters.Length;

            Point[][] array = new Point[num][];
            for (int i = 0; i < num; i++)
            {
                array[i] = new Point[num];
            }
            axis.Origin = finderPattern.getCenter(0);
            array[0][0] = axis.translate(3, 3);
            canvas.drawCross(array[0][0], Color_Fields.BLUE);
            axis.Origin       = finderPattern.getCenter(1);
            array[num - 1][0] = axis.translate(-3, 3);
            canvas.drawCross(array[num - 1][0], Color_Fields.BLUE);
            axis.Origin       = finderPattern.getCenter(2);
            array[0][num - 1] = axis.translate(3, -3);
            canvas.drawCross(array[0][num - 1], Color_Fields.BLUE);
            Point p = array[0][0];

            for (int j = 0; j < num; j++)
            {
                for (int k = 0; k < num; k++)
                {
                    if ((k == 0 && j == 0) || (k == 0 && j == num - 1) || (k == num - 1 && j == 0))
                    {
                        continue;
                    }
                    Point point = null;
                    if (j == 0)
                    {
                        if (k > 0 && k < num - 1)
                        {
                            point = axis.translate(array[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                        }
                        array[k][j] = new Point(point.X, point.Y);
                        canvas.drawCross(array[k][j], Color_Fields.RED);
                    }
                    else if (k == 0)
                    {
                        if (j > 0 && j < num - 1)
                        {
                            point = axis.translate(array[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                        }
                        array[k][j] = new Point(point.X, point.Y);
                        canvas.drawCross(array[k][j], Color_Fields.RED);
                    }
                    else
                    {
                        Point point2 = axis.translate(array[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                        Point point3 = axis.translate(array[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                        array[k][j] = new Point((point2.X + point3.X) / 2, (point2.Y + point3.Y) / 2 + 1);
                    }
                    if (finderPattern.Version > 1)
                    {
                        Point precisionCenter = getPrecisionCenter(image, array[k][j]);
                        if (array[k][j].distanceOf(precisionCenter) < 6)
                        {
                            canvas.drawCross(array[k][j], Color_Fields.RED);
                            int num2 = precisionCenter.X - array[k][j].X;
                            int num3 = precisionCenter.Y - array[k][j].Y;
                            canvas.println("Adjust AP(" + k + "," + j + ") to d(" + num2 + "," + num3 + ")");
                            array[k][j] = precisionCenter;
                        }
                    }
                    canvas.drawCross(array[k][j], Color_Fields.BLUE);
                    canvas.drawLine(new Line(p, array[k][j]), Color_Fields.LIGHTBLUE);
                    p = array[k][j];
                }
            }
            return(array);
        }