Created
December 16, 2014 12:33
-
-
Save skihero/24bc350b0c1dfab7489b to your computer and use it in GitHub Desktop.
buff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Tkinter import * | |
from PIL import Image, ImageTk, ImageDraw | |
import urllib2 | |
IMG_URI = "https://raw.githubusercontent.com/skihero/cor3/master/image_sample.jpg" | |
IMG_NAME = "image_sample.jpg" | |
bbox = [ (16, 17, 118, 152), | |
(131, 17, 223, 151), | |
(237, 16, 337, 154), | |
(350, 18, 448, 151), | |
(462, 17, 561, 152), | |
(575, 16, 674, 152), | |
(682, 14, 780, 149), | |
(790, 14, 886, 148), | |
(900, 16, 998, 149), | |
(1009, 15, 1095, 149) ] | |
class UI(Label): | |
def __init__(self, master, im): | |
if im.mode == "1": | |
# bitmap image | |
self.image = ImageTk.BitmapImage(im, foreground="white") | |
Label.__init__(self, master, image=self.image, bg="black", bd=0) | |
else: | |
# photo image | |
self.image = ImageTk.PhotoImage(im) | |
Label.__init__(self, master, image=self.image, bd=0) | |
if __name__ == "__main__": | |
try: | |
open(IMG_NAME) | |
except: | |
res = urllib2.urlopen(IMG_URI, IMG_NAME) | |
# what a waste of a write | |
output = open(IMG_NAME, 'wb') | |
output.write(res.read()) | |
output.close() | |
im = Image.open(IMG_NAME) | |
filename = im | |
draw = ImageDraw.Draw(im) | |
for b in bbox: | |
draw.rectangle(b, outline=128) | |
# extract here: | |
# TODO: | |
root = Tk() | |
root.title(filename) | |
UI(root, im).pack() | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment