title: Recording a video from images and the respective annotation files
body: <p>I have images stored in the another format in a folder. In a separate folder, I have text files that contain the coordinates of the rectangles which are supposed to be drawn over the image. I use the <code>read_file</code> function to read the NumPy array from the file.</p>
  <p>From the script given below, I can successfully plot the coordinates over the image one after the other. But this just generates images one after the other, whereas I want a video of the aforementioned images, i.e. Images produced by the script given below.</p>
  <p>Code snippet which does the aforementioned:</p>
  <pre><code>for idx, val in enumerate(img_list):
      image = read_file(img_list[idx])
      with open(annot_list[idx], 'r') as f:
          lines = [idx.rstrip('\n') for idx in f.readlines()]
          annots = [list(map(int, idx.split(','))) for idx in lines]
      plt.figure()
      plt.imshow(image, cmap='gray')
      for jdx, annot in enumerate(annots):
          x1 = annots[jdx][0]
          y1 = annots[jdx][1]
          w = annots[jdx][2] - x1
          h = annots[jdx][3] - y1
          rect = patches.Rectangle((x1, y1), w, h, linewidth=3, edgecolor='r', facecolor='none')
          plt.gca().add_patch(rect)
      plt.show()
  </code></pre>
  <p>Here, <code>img_list</code>and <code>annot_list</code> variables contain the names of the image files and the names of the respective annotation files.</p>
  <p>This generates an array of images one after the other. How do I generate a video of these frames? What should I tweak? I have looked at this <a href="https://stackoverflow.com/questions/4092927/generating-movie-from-python-without-saving-individual-frames-to-files">thread</a> but I can't seem to figure out what I need to change so as to generate a video. I don't necessarily have to save the video and I don't want to save the frames in the frame list because I have around 5000 images.</p>
  <p>Thank You and I appreciate any help I can get.</p>