2 import matplotlib.pyplot as pyplot
5 lines = pickle.load(open('lines.pickle'))
7 from src.intrsc import intersections_from_angl_dist
8 import src.linef as linef
9 import src.ransac as ransac
11 points = intersections_from_angl_dist(lines, (520, 390))
13 pyplot.scatter(*zip(*sum(points, [])))
15 def plot_line(line, c):
16 points = linef.line_from_angl_dist(line, (520, 390))
17 pyplot.plot(*zip(*points), color=c)
19 def plot_line_g((a, b, c), max_x):
20 find_y = lambda x: - (c + a * x) / b
21 pyplot.plot([0, max_x], [find_y(0), find_y(max_x)], color='b')
24 def __init__(self, data):
25 self.data = [p for p in sum(data, []) if p]
27 self.gen = self.initial_g()
30 l1, l2 = random.sample(self.lines, 2)
31 for i in xrange(len(l1)):
32 for j in xrange(len(l2)):
40 return self.gen.next()
42 self.gen = self.initial_g()
43 return self.gen.next()
45 def get(self, sample):
47 return ransac.points_to_line(*sample)
49 return ransac.least_squares(sample)
51 def intersection((a1, b1, c1), (a2, b2, c2)):
52 delim = float(a1 * b2 - b1 * a2)
53 x = (b1 * c2 - c1 * b2) / delim
54 y = (c1 * a2 - a1 * c2) / delim
60 line1, cons = ransac.estimate(points, 2, 800, Diagonal_model)
61 points2 = map(lambda l: [(p if not p in cons else None) for p in l], points)
62 line2, cons2 = ransac.estimate(points2, 2, 800, Diagonal_model)
63 center = intersection(line1, line2)
66 plot_line_g(line1, 520)
67 plot_line_g(line2, 520)
68 pyplot.scatter(*zip(*sum(points, [])))
69 pyplot.scatter([center[0]], [center[1]], color='r')
74 #map(lambda l: plot_line(l, 'g'), sum(lines, []))