X-Git-Url: http://git.tomasm.cz/imago.git/blobdiff_plain/890c6fc05c289fa41d3db2f17037f3b7428151fb..f2f525ee1484b0d7f361f9b3f0dab302a94a1d47:/linef.py?ds=sidebyside diff --git a/linef.py b/linef.py index ebfdbea..37690cc 100755 --- 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 @@ -83,6 +83,7 @@ def find_lines(image, show_all, do_something, verbose): lines = [] im_c = im_h2.convert('RGB').convert('RGB', (1, 0.5, 0.5, 0)) draw_c = ImageDraw.Draw(im_c) + bounds = [] for line_l in lines_m: im_line = Image.new('L', im_h2.size) @@ -96,6 +97,9 @@ def find_lines(image, show_all, do_something, verbose): for point in line_points: draw_c.point(point, fill=(120, 255, 120)) lines.append(hough1.lines_from_list(line_points)) + line_points = list(line_points) + line_points.sort() + bounds += [line_points[0], line_points[-1]] if show_all: do_something(im_c, "hough x lines") @@ -105,9 +109,9 @@ def find_lines(image, show_all, do_something, verbose): for line in [l for s in lines for l in s]: draw.line(line_from_angl_dist(line, image.size), fill=(120, 255, 120)) if show_all: - do_something(image_g, "the grid") - - return lines + do_something(image_g, "lines") + + return lines, lines_m[0][0], lines_m[1][0], bounds, hough1 def combine(image1, image2): im_l1 = image1.load() @@ -122,8 +126,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)]