public static FinderPattern findFinderPattern(bool[][] image) { Line[] lineCross = FinderPattern.FindLineCross(FinderPattern.FindLineAcross(image)); Point[] center; try { center = FinderPattern.GetCenter(lineCross); } catch (FinderPatternNotFoundException ex) { throw ex; } int[] angle = FinderPattern.GetAngle(center); Point[] pointArray = FinderPattern.Sort(center, angle); int[] width = FinderPattern.GetWidth(image, pointArray, angle); int[] moduleSize = new int[3] { (width[0] << QRCodeImageReader.DECIMAL_POINT) / 7, (width[1] << QRCodeImageReader.DECIMAL_POINT) / 7, (width[2] << QRCodeImageReader.DECIMAL_POINT) / 7 }; int version = FinderPattern.calcRoughVersion(pointArray, width); if (version > 6) { try { version = FinderPattern.CalcExactVersion(pointArray, angle, moduleSize, image); } catch (VersionInformationException ex) { } } return(new FinderPattern(pointArray, version, angle, width, moduleSize)); }
internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters) { int moduleSize = finderPattern.GetModuleSize(); Axis axis = new Axis(finderPattern.GetAngle(), moduleSize); int length = logicalCenters.Length; Point[][] pointArray = new Point[length][]; for (int index = 0; index < length; ++index) { pointArray[index] = new Point[length]; } axis.Origin = finderPattern.GetCenter(0); pointArray[0][0] = axis.translate(3, 3); AlignmentPattern.canvas.DrawCross(pointArray[0][0], Color_Fields.BLUE); axis.Origin = finderPattern.GetCenter(1); pointArray[length - 1][0] = axis.translate(-3, 3); AlignmentPattern.canvas.DrawCross(pointArray[length - 1][0], Color_Fields.BLUE); axis.Origin = finderPattern.GetCenter(2); pointArray[0][length - 1] = axis.translate(3, -3); AlignmentPattern.canvas.DrawCross(pointArray[0][length - 1], Color_Fields.BLUE); Point p1 = pointArray[0][0]; for (int index1 = 0; index1 < length; ++index1) { for (int index2 = 0; index2 < length; ++index2) { if ((index2 != 0 || index1 != 0) && (index2 != 0 || index1 != length - 1) && (index2 != length - 1 || index1 != 0)) { Point point1 = (Point)null; if (index1 == 0) { if (index2 > 0 && index2 < length - 1) { point1 = axis.translate(pointArray[index2 - 1][index1], logicalCenters[index2][index1].X - logicalCenters[index2 - 1][index1].X, 0); } pointArray[index2][index1] = new Point(point1.X, point1.Y); AlignmentPattern.canvas.DrawCross(pointArray[index2][index1], Color_Fields.RED); } else if (index2 == 0) { if (index1 > 0 && index1 < length - 1) { point1 = axis.translate(pointArray[index2][index1 - 1], 0, logicalCenters[index2][index1].Y - logicalCenters[index2][index1 - 1].Y); } pointArray[index2][index1] = new Point(point1.X, point1.Y); AlignmentPattern.canvas.DrawCross(pointArray[index2][index1], Color_Fields.RED); } else { Point point2 = axis.translate(pointArray[index2 - 1][index1], logicalCenters[index2][index1].X - logicalCenters[index2 - 1][index1].X, 0); Point point3 = axis.translate(pointArray[index2][index1 - 1], 0, logicalCenters[index2][index1].Y - logicalCenters[index2][index1 - 1].Y); pointArray[index2][index1] = new Point((point2.X + point3.X) / 2, (point2.Y + point3.Y) / 2 + 1); } if (finderPattern.Version > 1) { Point precisionCenter = AlignmentPattern.getPrecisionCenter(image, pointArray[index2][index1]); if (pointArray[index2][index1].DistanceOf(precisionCenter) < 6) { AlignmentPattern.canvas.DrawCross(pointArray[index2][index1], Color_Fields.RED); int num1 = precisionCenter.X - pointArray[index2][index1].X; int num2 = precisionCenter.Y - pointArray[index2][index1].Y; AlignmentPattern.canvas.Print("Adjust AP(" + (object)index2 + "," + (object)index1 + ") to d(" + (object)num1 + "," + (object)num2 + ")"); pointArray[index2][index1] = precisionCenter; } } AlignmentPattern.canvas.DrawCross(pointArray[index2][index1], Color_Fields.BLUE); AlignmentPattern.canvas.DrawLine(new Line(p1, pointArray[index2][index1]), Color_Fields.LIGHTBLUE); p1 = pointArray[index2][index1]; } } } return(pointArray); }
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], MessagingToolkit.QRCode.Helper.Color_Fields.BLUE); axis.Origin = finderPattern.GetCenter(FinderPattern.UR); centers[sqrtCenters - 1][0] = axis.translate(- 3, 3); canvas.DrawCross(centers[sqrtCenters - 1][0], MessagingToolkit.QRCode.Helper.Color_Fields.BLUE); axis.Origin = finderPattern.GetCenter(FinderPattern.DL); centers[0][sqrtCenters - 1] = axis.translate(3, - 3); canvas.DrawCross(centers[0][sqrtCenters - 1], MessagingToolkit.QRCode.Helper.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], MessagingToolkit.QRCode.Helper.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], MessagingToolkit.QRCode.Helper.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], MessagingToolkit.QRCode.Helper.Color_Fields.RED); int dx = precisionCenter.X - centers[x][y].X; int dy = precisionCenter.Y - centers[x][y].Y; canvas.Print("Adjust AP(" + x + "," + y + ") to d(" + dx + "," + dy + ")"); centers[x][y] = precisionCenter; } } canvas.DrawCross(centers[x][y], MessagingToolkit.QRCode.Helper.Color_Fields.BLUE); canvas.DrawLine(new Line(tmpPoint, centers[x][y]), MessagingToolkit.QRCode.Helper.Color_Fields.LIGHTBLUE); tmpPoint = centers[x][y]; } } return centers; }