From: Tomas Musil Date: Tue, 24 Jun 2014 14:32:47 +0000 (+0200) Subject: comments for manual and linef X-Git-Url: http://git.tomasm.cz/imago.git/commitdiff_plain/f662aac90eb7fb03ddca08366b83f0fd063b9e86 comments for manual and linef --- diff --git a/imago_pack/linef.py b/imago_pack/linef.py index eda82ce..06483a3 100644 --- a/imago_pack/linef.py +++ b/imago_pack/linef.py @@ -1,4 +1,4 @@ -"""Go image recognition lines-finding module""" +"""Lines finding module.""" from functools import partial import sys @@ -14,6 +14,8 @@ import filters from hough import Hough def find_lines(image, show_all, do_something, verbose): + """Find lines in the *image*.""" + # TODO refactor into smaller functions if verbose: print >> sys.stderr, "preprocessing" @@ -112,6 +114,7 @@ def find_lines(image, show_all, do_something, verbose): return lines, lines_m[0][0], lines_m[1][0], bounds, im_hough def combine(image1, image2): + """Return a list of points that are present in both images.""" im_l1 = image1.load() im_l2 = image2.load() @@ -124,6 +127,8 @@ def combine(image1, image2): return on_both def line_from_angl_dist((angle, distance), size): + """Take *angle* and *distance* (from the center of the image) of a line and + size of the image. Return the line represented by two points.""" if pi / 4 < angle < 3 * pi / 4: y1 = - size[1] / 2 x1 = int(round((y1 * cos(angle) + distance) / sin(angle))) + size[0] / 2 diff --git a/imago_pack/manual.py b/imago_pack/manual.py index c185525..f6f3807 100644 --- a/imago_pack/manual.py +++ b/imago_pack/manual.py @@ -10,6 +10,7 @@ class UserQuitError(Exception): pass class Screen: + # TODO isn't this a duplicate of something? def __init__(self, res): pygame.init() pygame.display.set_mode(res) @@ -22,12 +23,12 @@ class Screen: pygame.display.flip() def find_lines(im_orig): + # TODO rename, refactor, comment im = im_orig.copy() screen = Screen(im.size) - done = False clock = pygame.time.Clock() draw = ImageDraw.Draw(im) hoshi = lambda c: draw.ellipse((c[0] - 1, c[1] - 1, c[0] + 1, c[1] + 1), @@ -37,7 +38,7 @@ def find_lines(im_orig): line_width = 1 lines_r = [] - while not done: + while True: for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.KEYDOWN: pygame.quit() @@ -60,7 +61,7 @@ def find_lines(im_orig): draw.line(l, fill=color, width=line_width) for l in l_hor: draw.line(l, fill=color, width=line_width) - #TODO sort by distance + # TODO sort by distance l_vert.sort() l_hor.sort() for i in [3, 9, 15]: @@ -74,7 +75,7 @@ def find_lines(im_orig): clock.tick(15) def lines(corners): - #TODO Error on triangle + # TODO Error on triangle cor_d = [(corners[0], (c[0] - corners[0][0], c[1] - corners[0][1]), c) for c in corners[1:]] cor_d = [(float(a[0] * b[0] + a[1] * b[1]) / (sqrt(a[0] ** 2 + a[1] ** 2) * @@ -87,6 +88,7 @@ def lines(corners): [(corners[0], corners[1]), (corners[2], corners[3])]) def _lines(corners, n): + # TODO what is this? if n == 0: x = half_line(corners) return (_lines([corners[0], x[0], x[1], corners[3]], n + 1) + [x] + @@ -113,6 +115,7 @@ def _lines(corners, n): def half_line(corners): + # TODO what is this? c = center(corners) d = intersection(line(corners[0], corners[3]), line(corners[1], corners[2])) if d: @@ -124,7 +127,7 @@ def half_line(corners): p2 = intersection(l, line(corners[2], corners[3])) return (p1, p2) - def center(corners): + """Given a list of four corner points, return the center of the square.""" return intersection(line(corners[0], corners[2]), line(corners[1], corners[3]))