Display sequence of images using matplotlib

后端 未结 3 1968
梦谈多话
梦谈多话 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:14

    I have implemented a handy script based on matplotlib that just suits your need and much more. Check it here

    In your case, the following snippet should work:

    import os
    from scipy.misc import imread
    
    img_files = [for f in os.listdir('.') if f[-3:] == 'png']
    
    # redraw_fn draw frame f in a image sequence
    def redraw_fn(f, axes):
        img_file = img_files[f]
        img = imread(img_file)
        if not redraw_fn.initialized:
            redraw_fn.im = axes.imshow(img, animated=True)
            redraw_fn.initialized = True
        else:
            redraw_fn.im.set_array(img)
    redraw_fn.initialized = False
    
    videofig(len(img_files), redraw_fn, play_fps=30)
    

提交回复
热议问题