1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| import Tkinter
import ImageTk
import VideoCapture
import time
import threading
import PIL.ImageEnhance
##### CONSTANTS #####
QUANTUM = 1.0/25
###### CLASSES #######
class Cam(threading.Thread):
def __init__(self,master=None,cam=0,size=(320,240)):
threading.Thread.__init__(self)
print "Thread inited"
self.can = Tkinter.Canvas(master,width=size[0],height=size[1])
self.can.pack()
print "Can created"
self.cam = VideoCapture.Device(cam,0)
print "Cam created"
self.img = self.cam.getImage()
print "Firs image getted"
self.size = size
self.photo = ImageTk.PhotoImage(self.img,self.size,master=self.can)
print "First image getted"
self.id = self.can.create_image(size[0]/2+1,size[1]/2+1,image=self.photo)
print "Image drawed"
print "can updated"
self.alive = True
def run(self):
while self.alive:
t1 = time.time()
self.can.update()
t2 = time.time()
self.img = PIL.ImageEnhance.Color(self.cam.getImage()).enhance(0)
t3 = time.time()
self.photo = ImageTk.PhotoImage(self.img,self.size,master=self.can)
self.can.itemconfigure(self.id,image=self.photo)
t4 = time.time()
self.can.master.title("upt= %.3f, get =%.3f, work= %.3f" %(t2-t1,t3-t2,t4-t3))
time.sleep(QUANTUM)
api = Cam()
api.start() |
Partager