Display sequence of images using matplotlib

后端 未结 3 1961
梦谈多话
梦谈多话 2021-02-01 10:22

I have this simple python script using OpenCV to load images from a folder and display them in a loop. I want to reproduce this effect using matplotlib.

<         


        
3条回答
  •  一生所求
    2021-02-01 11:08

    I like the following way of doing this which is really straight-forward and allows the whole figure to be updated, including title, labels etc. rather than just the image.

    import numpy as np
    from matplotlib import pyplot as plt
    
    for j in range(0,3):
        img = np.random.normal(size=(100,150))
        plt.figure(1); plt.clf()
        plt.imshow(img)
        plt.title('Number ' + str(j))
        plt.pause(3)
    

    A random image is formed.

    plt.figure creates the figure the first time round if it does not already exist, and thereafter just makes figure 1 the current figure.

    plt.clf clears the figure so subsequent updates don't overlay each other. The image is then displayed with a title.

    The plt.pause statement is the key, since this causes the display to be updated - including title, labels etc.

提交回复
热议问题