MSAC
[imago.git] / src / gridf3.py
index 4f2a1e3..0ea26d9 100644 (file)
@@ -42,6 +42,18 @@ class Diagonal_model:
         else:
             return ransac.least_squares(sample)
 
         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
 def intersection((a1, b1, c1), (a2, b2, c2)):
     delim = float(a1 * b2 - b1 * a2)
     x = (b1 * c2 - c1 * b2) / delim
@@ -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.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()
         fig.canvas.draw()
         size_f = fig.canvas.get_width_height()
         buff = fig.canvas.tostring_rgb()