Oct-18-2016, 09:28 AM
Well some more digging and I prised the answer out of a combination of several different places.
Larz60's approach is the way I was already doing it - loading a file, but I eventually found out that the data needs to be in ppm format which is pretty simple to generate. This approach goes twice as fast as writing / reading a file and isn't really stressing the PC either:
Larz60's approach is the way I was already doing it - loading a file, but I eventually found out that the data needs to be in ppm format which is pretty simple to generate. This approach goes twice as fast as writing / reading a file and isn't really stressing the PC either:
import tkinter import numpy import time #python2 version (original) -> 120fps #full physical file io and new image each cycle -> 130fps #reuse PIL Image instead of create new each time -> 160fps #and... direct image into tkinter using ppm byte array -> 240 fps class mainWindow(): times=1 timestart=time.clock() data=numpy.array(numpy.random.random((400,500))*900,dtype=numpy.uint16) def __init__(self): self.root = tkinter.Tk() self.frame = tkinter.Frame(self.root, width=500, height=400) self.frame.pack() self.canvas = tkinter.Canvas(self.frame, width=500,height=400) self.canvas.place(x=-2,y=-2) xdata = b'P5 500 400 255 ' + self.data.tobytes() self.photo = tkinter.PhotoImage(width=500, height=400, data=xdata, format='PPM') self.imid = self.canvas.create_image(0,0,image=self.photo,anchor=tkinter.NW) self.root.after(1,self.start) # INCREASE THE 0 TO SLOW IT DOWN self.root.mainloop() def start(self): global data xdata = b'P5 500 400 255 ' + numpy.clip(self.data,0,255).tobytes() self.photo = tkinter.PhotoImage(width=500, height=400, data=xdata, format='PPM') if True: self.canvas.itemconfig(self.imid, image = self.photo) else: self.canvas.delete(self.imid) self.imid = self.canvas.create_image(0,0,image=self.photo,anchor=tkinter.NW) self.times+=1 if self.times%33==0: print("%.02f FPS"%(self.times/(time.clock()-self.timestart))) self.root.update() self.root.after(0,self.start) self.data=numpy.roll(self.data,-1,1) if __name__ == '__main__': x=mainWindow()