+ image = Image.open(args.files[0])
+ except IOError, msg:
+ print >> sys.stderr, msg
+ return 1
+ if image.mode == 'P':
+ image = image.convert('RGB')
+
+ if image.size[0] > args.w:
+ image = image.resize((args.w, int((float(args.w)/image.size[0]) *
+ image.size[1])), Image.ANTIALIAS)
+ do_something = im_debug.show
+ if args.saving:
+ do_something = Imsave("saved/" + args.files[0][:-4] + "_" +
+ str(image.size[0]) + "/").save
+
+ if args.manual_mode:
+ try:
+ lines = manual.find_lines(image)
+ except manual.UserQuitError:
+ #TODO ask user to try again
+ return 1
+ else:
+ 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)
+
+ if len(args.files) > 1:
+ for f in args.files[1:]: