def __len__(self):
return 2
+ def to_tuple(self):
+ return (self.x, self.y)
+
class Line:
def __init__(self, (a, b, c)):
self.a, self.b, self.c = (a, b, c)
c2 = [p for p in d2.points if p in c1.l1.points][0]
c3 = [p for p in d1.points if p in c2.l2.points][0]
c4 = [p for p in d2.points if p in c3.l1.points][0]
- yield [c1, c2, c3, c4]
+ try:
+ yield manual.lines(map(lambda p: p.to_tuple(), [c2, c1, c3, c4]))
+ except TypeError:
+ pass
+ # the square was too small to fit 17 lines inside
+ # TODO define SquareTooSmallError or something
def dst(p, l):
(x, y), (a, b, c) = p, ransac.points_to_line(*l)
s = min(map(lambda l: dst(p, l), lines))
s = min(s, 2)
score += s
- print score
return score
diag2 = Line(line2)
diag2.points = ransac.filter_near(data, diag2, 2)
- grids = map(manual.lines, list(gen_corners(diag1, diag2)))
+ grids = list(gen_corners(diag1, diag2))
sc, grid = min(map(lambda g: (score(sum(g, []), data), g), grids))
grid_lines = [[l2ad(l, size) for l in grid[0]],
[l2ad(l, size) for l in grid[1]]]
+ grid_lines[0].sort(key=lambda l: l[1])
+ grid_lines[1].sort(key=lambda l: l[1])
+ if grid_lines[0][0][0] > grid_lines[1][0][0]:
+ grid_lines = grid_lines[1], grid_lines[0]
return grid, grid_lines