- lines = linef.find_lines(image, show_all, do_something, verbose)
-
- 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 = intrsc.board(image, lines, show_all, do_something)
+
+ #simple ASCII output:
+ for line in board:
+ print ' '.join(line)