I am converting numpy arrays (webcamera footage loaded with OpenCV) into Tkinter PhotoImage objects to display them on Tkinter GUI. However, the function PIL.ImageTk.PhotoImage()
experiences around 800 ms peaks that result in serious drops in frame rate. Here's the snippet:
ar = Image.fromarray(frame)
itk = ImageTk.PhotoImage(ar) # *
lbl = Label()
lbl.configure(image=itk)
lbl.image = itk
I have measured the execution time of the row marked with *
:
Number of runs: 72
Total duration: 11.97 seconds
Longest run: 967.05 milliseconds
Shortest run: 1.03 milliseconds
Average run: 166.25 milliseconds
Median run: 1.2 milliseconds
Standard deviation: 315.63 milliseconds
Additionally, here's a plot of the performance:
The pixel count of the image is always the same and I cannot generate conditions where the performance would be consistently low.
Any ideas on how to prevent the spikes? It's not a problem to skip frames if it can be predicted.
PIL version 4.0.0 OpenCV version 3.0.0 Numpy version 1.12.0 Python version: 2.7.12