grid-drawing bug fixed
authorTomas Musil <tomik.musil@gmail.com>
Wed, 3 Oct 2012 11:49:42 +0000 (13:49 +0200)
committerTomas Musil <tomik.musil@gmail.com>
Wed, 3 Oct 2012 11:49:42 +0000 (13:49 +0200)
hough.py
linef.py

index 9d44bcb..0e9fe2d 100644 (file)
--- a/hough.py
+++ b/hough.py
@@ -30,7 +30,7 @@ class Hough:
                                     size[0] / 2)
                         # column of the matrix closest to the distance
                         column = int(round(distance)) 
-                        if column >= 0 and column < size[0]:
+                        if 0 <= column < size[0]:
                             matrix[column][a] += 1
 
         new_image = Image.new('L', size)
index ebfdbea..f46d92c 100755 (executable)
--- a/linef.py
+++ b/linef.py
@@ -3,7 +3,7 @@
 """Go image recognition lines-finding module"""
 
 import sys
-import math
+from math import sin, cos, pi
 
 try:
     import Image, ImageDraw
@@ -122,8 +122,15 @@ def combine(image1, image2):
     return on_both
 
 def line_from_angl_dist((angle, distance), size):
-    x1 = - size[0] / 2
-    y1 = int(round((x1 * math.sin(angle) - distance) / math.cos(angle))) + size[1] / 2
-    x2 = size[0] / 2 
-    y2 = int(round((x2 * math.sin(angle) - distance) / math.cos(angle))) + size[1] / 2
-    return [(0, y1), (size[0] - 1, y2)]
+    if pi / 4 < angle < 3 * pi / 4:
+        y1 = - size[1] / 2
+        x1 = int(round((y1 * cos(angle) + distance) / sin(angle))) + size[0] / 2
+        y2 = size[1] / 2 
+        x2 = int(round((y2 * cos(angle) + distance) / sin(angle))) + size[0] / 2
+        return [(x1, 0), (x2, size[1])]
+    else:
+        x1 = - size[0] / 2
+        y1 = int(round((x1 * sin(angle) - distance) / cos(angle))) + size[1] / 2
+        x2 = size[0] / 2 
+        y2 = int(round((x2 * sin(angle) - distance) / cos(angle))) + size[1] / 2
+        return [(0, y1), (size[0], y2)]