def crop_and_anim(self):
video = imageio.get_reader(os.path.join(self.pathTo, self.videoFile), 'ffmpeg')
all_signs = self.parse_xml()
for sign in all_signs:
cropped_signs = []
for frame in sign:
image = video.get_data(int(frame[0]))
image_frame = Image.fromarray(image)
tags = [float(tag) for tag in frame[1:5]]
cropped = image_frame.crop(tags)
cropped = cropped.convert("RGB")
cropped_signs.append(cropped)
path_to_animated = os.path.join(self.pathTo, self.dir2, 'animated__%d.gif' % int(all_signs.index(sign)))
imageio.mimsave(path_to_animated, cropped_signs)