Hide
Don't get spied on – We respect your privacy and provide numerous options to protect it. Join Siafoo Now or Learn More

Image Point Printer Atom Feed 0

In Brief Prints the coordinates of clicks on an image.... more
# 's
 1import Tkinter
2import Image, ImageTk
3
4def callback(event):
5 print event.x, ',', event.y
6
7def markImage(filename):
8
9 im = Image.open(filename)
10
11 root = Tkinter.Tk()
12 root.geometry('%dx%d' % (im.size[0],im.size[1]))
13 root.title(filename)
14
15 tkpi = ImageTk.PhotoImage(im)
16
17 label_image = Tkinter.Label(root, image=tkpi)
18 label_image.place(x=0, y=0, width=im.size[0], height=im.size[1])
19 label_image.bind('<Button-1>', callback)
20
21 print filename
22
23 root.mainloop()
24
25if __name__ == '__main__':
26 for dir in ['s'+str(n+1) for n in range(5)]:
27 for im in [str(n+1)+'.pgm' for n in range(10)]:
28 markImage(dir+'/'+im)

Prints the coordinates of clicks on an image.

I needed the coordinates of 5 points in each of 50 images for testing a computer vision programming assignment. This snippet prints the name of the file and pops a window up with the image. The coordinates of every click are printed to standard output. When the window is closed, the next image is opened.

Note

While Tkinter and PIL were installed on my system by default, I had to install a package called python-imaging-tk for the ImageTk module.