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 read_file
function to read the NumPy array from the file.
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.
Code snippet which does the aforementioned:
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()
Here, img_list
and annot_list
variables contain the names of the image files and the names of the respective annotation files.
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 thread 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.
Thank You and I appreciate any help I can get.