How to update matplotlib's imshow() window interactively?

后端 未结 4 1531
孤独总比滥情好
孤独总比滥情好 2020-11-30 05:19

I\'m working on some computer vision algorithm and I\'d like to show how a numpy array changes in each step.

What works now is that if I have a simple imshow(

4条回答
  •  执念已碎
    2020-11-30 06:04

    I implemented a handy script that just suits your needs. Try it out here

    An example that shows images in a custom directory is like this:

      import os
      import glob
      from scipy.misc import imread
    
      img_dir = 'YOUR-IMAGE-DIRECTORY'
      img_files = glob.glob(os.path.join(video_dir, '*.jpg'))
    
      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)
    

提交回复
热议问题