From e34ac48a7387f7c359c1987f3a58ebcca154697e Mon Sep 17 00:00:00 2001 From: Tomas Musil Date: Tue, 7 Aug 2012 17:56:00 +0200 Subject: [PATCH 1/1] intersections --- imago.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/imago.py b/imago.py index f3a9eb7..127ddd9 100755 --- a/imago.py +++ b/imago.py @@ -110,9 +110,12 @@ def main(): 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") @@ -142,10 +145,20 @@ def combine(image1, image2): 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()) -- 2.4.2