Skip to content

Commit 8c1af09

Browse files
authored
Merge pull request opencv#18083 from IanMaquignaz:fix_gen_pattern_centering
* Fixed centering issue with make_cicle_pattern and make_acircle_pattern() * Fixed issue where asymmetric circles were not at 45 degree angles. Also fixed support for inch measurement by converting parsing to usage of floating points for page size * Fixed copy-paste error from experimental workspace
1 parent f53ff0d commit 8c1af09

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

doc/pattern_tools/gen_pattern.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,27 @@ def __init__(self, cols, rows, output, units, square_size, radius_rate, page_wid
3636
def make_circles_pattern(self):
3737
spacing = self.square_size
3838
r = spacing / self.radius_rate
39-
for x in range(1, self.cols + 1):
40-
for y in range(1, self.rows + 1):
41-
dot = SVG("circle", cx=x * spacing, cy=y * spacing, r=r, fill="black", stroke="none")
39+
pattern_width = ((self.cols - 1.0) * spacing) + (2.0 * r)
40+
pattern_height = ((self.rows - 1.0) * spacing) + (2.0 * r)
41+
x_spacing = (self.width - pattern_width) / 2.0
42+
y_spacing = (self.height - pattern_height) / 2.0
43+
for x in range(0, self.cols):
44+
for y in range(0, self.rows):
45+
dot = SVG("circle", cx=(x * spacing) + x_spacing + r,
46+
cy=(y * spacing) + y_spacing + r, r=r, fill="black", stroke="none")
4247
self.g.append(dot)
4348

4449
def make_acircles_pattern(self):
4550
spacing = self.square_size
4651
r = spacing / self.radius_rate
47-
for i in range(0, self.rows):
48-
for j in range(0, self.cols):
49-
dot = SVG("circle", cx=((j * 2 + i % 2) * spacing) + spacing, cy=self.height - (i * spacing + spacing),
50-
r=r, fill="black", stroke="none")
52+
pattern_width = ((self.cols-1.0) * 2 * spacing) + spacing + (2.0 * r)
53+
pattern_height = ((self.rows-1.0) * spacing) + (2.0 * r)
54+
x_spacing = (self.width - pattern_width) / 2.0
55+
y_spacing = (self.height - pattern_height) / 2.0
56+
for x in range(0, self.cols):
57+
for y in range(0, self.rows):
58+
dot = SVG("circle", cx=(2 * x * spacing) + (y % 2)*spacing + x_spacing + r,
59+
cy=(y * spacing) + y_spacing + r, r=r, fill="black", stroke="none")
5160
self.g.append(dot)
5261

5362
def make_checkerboard_pattern(self):
@@ -84,9 +93,9 @@ def main():
8493
parser.add_argument("-R", "--radius_rate", help="circles_radius = square_size/radius_rate", default="5.0",
8594
action="store", dest="radius_rate", type=float)
8695
parser.add_argument("-w", "--page_width", help="page width in units", default="216", action="store",
87-
dest="page_width", type=int)
96+
dest="page_width", type=float)
8897
parser.add_argument("-h", "--page_height", help="page height in units", default="279", action="store",
89-
dest="page_width", type=int)
98+
dest="page_width", type=float)
9099
parser.add_argument("-a", "--page_size", help="page size, supersedes -h -w arguments", default="A4", action="store",
91100
dest="page_size", choices=["A0", "A1", "A2", "A3", "A4", "A5"])
92101
args = parser.parse_args()

0 commit comments

Comments
 (0)