Reputation:
i want to update displayed image over loop, i am working in google colab, therefore my code is based on google colab
from google.colab import drive
drive.mount('/content/drive')
from PIL import Image
import glob
import time
from pylab import *
for filename in glob.iglob('/content/drive/My Drive/Colab Notebooks/Cats/*.jpg'):
#print(filename)
img = array(Image.open(filename))
imshow(img)
time.sleep(2)
but it displays only one image, how can i make so that image will be updated automatically?thanks in advance
Upvotes: 0
Views: 82
Reputation: 500
I think Ipython display and clear_output may help with the animation:
from google.colab import drive
drive.mount('/content/drive')
from PIL import Image
import matplotlib.pyplot as plt
import glob
import time
from pylab import *
from IPython.display import display, clear_output
for filename in glob.iglob('/content/drive/My Drive/Colab Notebooks/Cats/*.jpg'):
clear_output(wait=True)
img = array(Image.open(filename))
display(imshow(img))
plt.axis("off")
plt.show()
time.sleep(1)
Upvotes: 1