def saveVideoFrames(self, filename, images):
"""
Create a video with synthesized images
:param filename: name of file to save
:param images: video data
:return: None
"""
txt = 'Saving {}'.format(filename)
pbar = pb.ProgressBar(maxval=images.shape[0], widgets=[txt, pb.Percentage(), pb.Bar()])
pbar.start()
height = width = 128
# Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC(*'DIVX')
video = cv2.VideoWriter('{}/synth_{}.avi'.format(self.subfolder, filename), fourcc, self.fps, (height, width))
if not video:
raise EnvironmentError("Error in creating video writer")
for i in range(images.shape[0]):
img = images[i]
img = cv2.normalize(img, alpha=0, beta=255, norm_type=cv2.cv.CV_MINMAX, dtype=cv2.cv.CV_8UC1)
img = cv2.cvtColor(img, cv2.cv.CV_GRAY2BGR)
img = cv2.resize(img, (height, width))
# write frame
video.write(img)
pbar.update(i)
video.release()
del video
cv2.destroyAllWindows()
pbar.finish()
评论列表
文章目录