3 """Go image recognition"""
11 import Image, ImageDraw
12 except ImportError, msg:
13 print >> sys.stderr, msg
22 """Main function of the program."""
24 parser = argparse.ArgumentParser(description=__doc__)
25 parser.add_argument('file', metavar='file', nargs=1,
26 help="image to analyse")
27 parser.add_argument('-w', type=int, default=640,
28 help="scale image to the specified width before analysis")
29 parser.add_argument('-m', '--manual', dest='manual_mode', action='store_true',
30 help="manual grid selection")
31 parser.add_argument('-d', '--debug', dest='show_all', action='store_true',
32 help="show every step of the computation")
33 parser.add_argument('-s', '--save', dest='saving', action='store_true',
34 help="save images instead of displaying them")
35 parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
36 help="report progress")
37 args = parser.parse_args()
39 show_all = args.show_all
40 verbose = args.verbose
43 image = Image.open(args.file[0])
45 print >> sys.stderr, msg
48 image = image.convert('RGB')
50 if image.size[0] > args.w:
51 image = image.resize((args.w, int((float(args.w)/image.size[0]) *
52 image.size[1])), Image.ANTIALIAS)
53 do_something = im_debug.show
55 do_something = imsave("saved/" + args.file[0][:-4] + "_" +
56 str(image.size[0]) + "/").save
60 lines = manual.find_lines(image)
61 except manual.UserQuitError:
62 #TODO ask user to try again
65 lines = linef.find_lines(image, show_all, do_something, verbose)
67 board = intrsc.board(image, lines, show_all, do_something)
76 def __init__(self, saving_dir):
77 self.saving_dir = saving_dir
80 def save(self, image, title=''):
81 filename = self.saving_dir + "{0:0>2}".format(self.saving_num) + '.jpg'
82 if not os.path.isdir(self.saving_dir):
83 os.makedirs(self.saving_dir)
84 image.save(filename, 'JPEG')
87 if __name__ == '__main__':
90 except KeyboardInterrupt: