- global Saving_dir
- Saving_dir = "saved/" + args.file[0][:-4] + "_" + str(image.size[0]) + "/"
-
- if show_all:
- do_something(image, "original image")
-
- im_l = image.convert('L')
- if show_all:
- do_something(im_l, "ITU-R 601-2 luma transform")
-
- im_edges = filters.edge_detection(im_l)
- if show_all:
- do_something(im_edges, "edge detection")
-
- im_h = filters.high_pass(im_edges, 100)
- if show_all:
- do_something(im_h, "high pass filters")
+ 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)
+
+ board = intrsc.board(image, lines, show_all, do_something)
+
+ #simple ASCII output:
+ for line in board:
+ print ' '.join(line)