+from linef import line_from_angl_dist
+
+class GridFittingFailedError(Exception):
+ pass
+
+class MyGaussianBlur(ImageFilter.Filter):
+ name = "GaussianBlur"
+
+ def __init__(self, radius=2):
+ self.radius = radius
+ def filter(self, image):
+ return image.gaussian_blur(self.radius)
+
+class V():
+ def __init__(self, x, y):
+ self.x = x
+ self.y = y
+
+ def __add__(self, other):
+ return V(self.x + other.x, self.y + other.y)
+
+ def __sub__(self, other):
+ return V(self.x - other.x, self.y - other.y)
+
+ def __rmul__(self, other):
+ return V(other * self.x, other * self.y)
+
+ def t(self):
+ return (self.x, self.y)
+
+def find(lines, size, l1, l2, bounds, hough, do_something):
+ a, b, c, d = [V(*a) for a in bounds]
+ l1 = line_from_angl_dist(l1, size)
+ l2 = line_from_angl_dist(l2, size)
+ v1 = V(*l1[0]) - V(*l1[1])
+ v2 = V(*l2[0]) - V(*l2[1])
+ grid = get_grid(a, b, c, d, hough, size)
+ dist = distance(lines, grid, size)
+ print dist
+
+ s = 0.02
+ while True:
+ ts1 = [(s, 0), (-s, 0), (s, s), (-s, -s), (-s, s), (s, -s), (0, s), (0, -s)]
+ grids = [(get_grid(a + t[0] * v1, b + t[1] * v1,
+ c, d, hough, size), t) for t in ts1]
+ distances = [(distance(lines, grid, size),
+ grid, t) for grid, t in grids]
+ distances.sort(reverse=True)
+ if distances[0][0] > dist:
+ dist = distances[0][0]
+ grid = distances[0][1]
+ t = distances[0][2]
+ a, b = a + t[0] * v1, b + t[1] * v1
+ print dist
+ s *= 0.75
+ else:
+ break