more work on gridf generation 3
authorTomas Musil <tomik.musil@gmail.com>
Wed, 2 Jul 2014 17:28:14 +0000 (19:28 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Wed, 2 Jul 2014 17:28:14 +0000 (19:28 +0200)
gridf3.py

index 9e87881..7fa91fd 100644 (file)
--- a/gridf3.py
+++ b/gridf3.py
@@ -2,16 +2,10 @@ import pickle
 import matplotlib.pyplot as pyplot
 import random
 
-lines = pickle.load(open('lines.pickle'))
-
 from src.intrsc import intersections_from_angl_dist
 import src.linef as linef
 import src.ransac as ransac
 
-points = intersections_from_angl_dist(lines, (520, 390))
-
-pyplot.scatter(*zip(*sum(points, [])))
-
 def plot_line(line, c):
     points = linef.line_from_angl_dist(line, (520, 390))
     pyplot.plot(*zip(*points), color=c)
@@ -54,6 +48,63 @@ def intersection((a1, b1, c1), (a2, b2, c2)):
     y = (c1 * a2 - a1 * c2) / delim
     return x, y
 
+class Point:
+    def __init__(self, (x, y)):
+        self.x = x
+        self.y = y
+
+    def __getitem__(self, key):
+        if key == 0:
+            return self.x
+        elif key == 1:
+            return self.y
+
+    def __iter__(self):
+        yield self.x
+        yield self.y
+
+    def __len__(self):
+        return 2
+
+class Line:
+    def __init__(self, (a, b, c)):
+        self.a, self.b, self.c = (a, b, c)
+        self.points = []
+
+    @classmethod
+    def from_ad(cls, (a, d), size):
+        p = linef.line_from_angl_dist((a, d), size)
+        return cls(ransac.points_to_line(*p))
+
+    def __iter__(self):
+        yield self.a
+        yield self.b
+        yield self.c
+
+    def __len__(self):
+        return 3
+
+lines = pickle.load(open('lines.pickle'))
+
+size = (520, 390)
+new_lines1 = map(lambda l: Line.from_ad(l, size), lines[0])
+new_lines2 = map(lambda l: Line.from_ad(l, size), lines[1])
+for l1 in new_lines1:
+    for l2 in new_lines2:
+        p = Point(intersection(l1, l2))
+        p.l1 = l1
+        p.l2 = l2
+        l1.points.append(p)
+        l2.points.append(p)
+
+points = [l.points for l in new_lines1]
+
+def gen_corners(d1, d2):
+    for c1 in d1.points:
+        if c1 in d2.points:
+            continue
+        pass
+    # TODO TODO TODO
 
 
 while True:
@@ -61,10 +112,15 @@ while True:
     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)
     center = intersection(line1, line2)
+    data = sum(points, [])
+    diag1 = Line(line1)
+    diag1.points = ransac.filter_near(data, diag1, 2)
+    diag2 = Line(line2)
+    diag2.points = ransac.filter_near(data, diag2, 2)
     
 
-    plot_line_g(line1, 520)
-    plot_line_g(line2, 520)
+    plot_line_g(diag1, 520)
+    plot_line_g(diag2, 520)
     pyplot.scatter(*zip(*sum(points, [])))
     pyplot.scatter([center[0]], [center[1]], color='r')
     pyplot.xlim(0, 520)