- lines = linef.find_lines(image, show_all, do_something, verbose)
-
- image_g = image.copy()
- draw = ImageDraw.Draw(image_g)
- for line in [l for s in lines for l in s]:
- draw.line(linef.line_from_angl_dist(line, image.size), fill=(120, 255, 120))
- if show_all:
- do_something(image_g, "the grid")
-
- intersections = intersections_from_angl_dist(lines, image.size)
- image_g = image.copy()
- draw = ImageDraw.Draw(image_g)
- for line in intersections:
- for (x, y) in line:
- draw.point((x , y), fill=(120, 255, 120))
+ if args.l_cache:
+ filename = ("saved/cache/" + args.files[0][:-4] + "_" +
+ str(image.size[0]))
+ cache_dir = "/".join(filename.split('/')[:-1])
+ if os.path.exists(filename):
+ lines, l1, l2, bounds, hough = pickle.load(open(filename))
+ print >> sys.stderr, "using cached results"
+ im_h = None
+ else:
+ lines, l1, l2, bounds, hough, im_h = linef.find_lines(image, show_all, do_something, verbose)
+ if not os.path.isdir(cache_dir):
+ os.makedirs(cache_dir)
+ d_file = open(filename, 'wb')
+ pickle.dump((lines, l1, l2, bounds, hough), d_file)
+ d_file.close()
+ else:
+ lines, l1, l2, bounds, hough, im_h = linef.find_lines(image, show_all, do_something, verbose)
+
+ grid, lines = gridf.find(lines, image.size, l1, l2, bounds, hough,
+ do_something, im_h)
+ if show_all:
+ im_g = image.copy()
+ draw = ImageDraw.Draw(im_g)
+ for l in grid[0] + grid[1]:
+ draw.line(l, fill=(64, 255, 64), width=1)
+ do_something(im_g, "grid", name="grid")
+
+ board, board_raw = intrsc.board(image, lines, show_all, do_something)
+
+ ### Show color distribution
+ #import matplotlib.pyplot as pyplot
+ #luma = [(0.30 * s[0] + 0.59 * s[1] + 0.11 * s[2]) / 255.
+ # for s in sum(board_raw, [])]
+ #pyplot.scatter(luma,
+ # [(max(s) - min(s)) / (255 - abs(max(s) + min(s) - 255))
+ # for s in sum(board_raw, [])],
+ # color=[(s[0]/255., s[1]/255., s[2]/255., 1.) for s in sum(board_raw, [])])
+ #pyplot.show()
+ ###
+
+ #simple ASCII output:
+ for line in board:
+ print ' '.join(line)