#!/usr/bin/python # show.py # Part of the "penpal" project # (Finds Gary Blehm's Identical Penmen) # http://web.mit.edu/wdaher/www/penpal/ # # Waseem Daher # Jan. 21, 2006 import Image, ImageDraw import os, sys import time outfile = 'show-image.jpg' filename = sys.argv[1] data = open(filename, 'r') lines = data.readlines() vars = lines[:11] # Import our variables again # Yeah, this is totally not secure, # but that's fine here for line in vars: exec(line) # Now, read in the penmen data penmen = [None] * num_penmen info = lines[13:] for line in info: num,x,y = eval(line) penmen[num] = (x,y) os.system('head -2 %s' % filename) im = Image.open(infile) im = im.convert('RGB') def goBound(image, centroid, width, height): draw = ImageDraw.Draw(im) imgx,imgy = im.size centroidx,centroidy = centroid tlx = max(0, centroidx - width/2) tly = max(0, centroidy - height/2) brx = min(imgx, centroidx + width/2) bry = min(imgy, centroidy + height/2) draw.rectangle([(tlx,tly),(brx,bry)], outline="red") freshImage = im.copy() while True: number = input("Draw on (-1 to reset," \ + " -2 to draw on all," \ + " -3 to quit," \ + " -4 to draw): ") if number == -3: break elif number == -1: im = freshImage elif number == -4: im.save(outfile) os.system('display %s &' % outfile) elif number == -2: for i in penmen: # Draw the bounding box goBound(im, i, bounding_box_width, bounding_box_height) else: goBound(im, penmen[number], bounding_box_width, bounding_box_height)