do_something(im_c, "first hough x lines")
lines = hough1.all_lines(im_c)
+ intersections = intersections_from_angl_dist(lines)
draw = ImageDraw.Draw(image)
- for line in lines:
- draw.line(line_from_angl_dist(line, image.size), fill=(120, 255, 120))
+ for (x, y) in intersections:
+ draw.point((x + image.size[0] / 2, y + image.size[1] / 2), fill=(120, 255, 120))
+
+ print(len(intersections))
do_something(image, "the grid")
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
+ 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
+ y2 = int(round((x2 * math.sin(angle) - distance) / math.cos(angle))) + size[1] / 2
return [(0, y1), (size[0] - 1, y2)]
+def intersections_from_angl_dist(lines):
+ intersections = set()
+ for (angl1, dist1) in lines:
+ for (angl2, dist2) in lines:
+ if abs(angl1 - angl2) > 0.3:
+ x = - ((dist2 / math.cos(angl2))-(dist1 / math.cos(angl1))) / (math.tan(angl1) - math.tan(angl2))
+ y = (math.tan(angl1) * x) - (dist1 / math.cos(angl1))
+ intersections.add((int(x), int(y)))
+ return intersections
+
if __name__ == '__main__':
sys.exit(main())