MSAC
[imago.git] / src / gridf3.py
index 92f07c4..0ea26d9 100644 (file)
@@ -42,6 +42,18 @@ class Diagonal_model:
         else:
             return ransac.least_squares(sample)
 
+    def score(self, est, dist):
+        cons = []
+        score = 0
+        a, b, c = est
+        dst = lambda (x, y): abs(a * x + b * y + c) / sqrt(a*a+b*b)
+        for p in self.data:
+            d = dst(p)
+            if d <= dist:
+                cons.append(p)
+            score += min(d, dist)
+        return score, cons
+
 def intersection((a1, b1, c1), (a2, b2, c2)):
     delim = float(a1 * b2 - b1 * a2)
     x = (b1 * c2 - c1 * b2) / delim
@@ -105,7 +117,7 @@ def gen_corners(d1, d2):
             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]
         except IndexError:
-            pass
+            continue
             # there is not a corresponding intersection
             # TODO create an intersection?
         try:
@@ -167,6 +179,7 @@ def find(lines, size, l1, l2, bounds, hough, show_all, do_something, logger):
         pyplot.scatter([center[0]], [center[1]], color='r')
         pyplot.xlim(0, size[0])
         pyplot.ylim(0, size[1])
+        pyplot.gca().invert_yaxis()
         fig.canvas.draw()
         size_f = fig.canvas.get_width_height()
         buff = fig.canvas.tostring_rgb()