X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/6171054cca1b1120afad2d70a50b6efc0441a831..1e417ec51105662e1d1d7a7e2350dbe724f76a2d:/src/gridf3.py diff --git a/src/gridf3.py b/src/gridf3.py index 0697b92..5852115 100644 --- a/src/gridf3.py +++ b/src/gridf3.py @@ -12,6 +12,9 @@ from geometry import l2ad class GridFittingFailedError(Exception): pass +class BadGenError(Exception): + pass + def plot_line(line, c, size): points = linef.line_from_angl_dist(line, size) pyplot.plot(*zip(*points), color=c) @@ -32,12 +35,16 @@ class Diagonal_model: if l1[i] and l2[j]: yield (l1[i], l2[j]) + def remove(self, data): + self.data = list(set(self.data) - set(data)) + def initial(self): try: - return self.gen.next() + nxt = self.gen.next() except StopIteration: self.gen = self.initial_g() - return self.gen.next() + nxt = self.gen.next() + return nxt def get(self, sample): if len(sample) == 2: @@ -50,11 +57,18 @@ class Diagonal_model: score = 0 a, b, c = est dst = lambda (x, y): abs(a * x + b * y + c) / sqrt(a*a+b*b) + l1 = None + l2 = None for p in self.data: d = dst(p) if d <= dist: cons.append(p) + if p.l1 == l1 or p.l2 == l2: + return float("inf"), [] + else: + l1, l2 = p.l1, p.l2 score += min(d, dist) + return score, cons def intersection((a1, b1, c1), (a2, b2, c2)): @@ -158,9 +172,9 @@ def find(lines, size, l1, l2, bounds, hough, show_all, do_something, logger): points = [l.points for l in new_lines1] for trial in xrange(3): - line1, cons = ransac.estimate(points, 2, 800, Diagonal_model) - points2 = map(lambda l: [(p if not p in cons else None) for p in l], points) - line2, cons2 = ransac.estimate(points2, 2, 800, Diagonal_model) + model = Diagonal_model(points) + diag_lines = ransac.ransac_multi(2, points, 2, 800, model=model) + [(line1, cons), (line2, cons2)] = diag_lines center = intersection(line1, line2) data = sum(points, []) diag1 = Line(line1)