def saveVideo3D(self, filename, sequence, showPC=True, showGT=False, niceColors=True, plotFrameNumbers=False,
height=400, width=400):
"""
Create a video with 3D annotations
:param filename: name of file to save
:param sequence: sequence data
:return: None
"""
txt = 'Saving {}'.format(filename)
pbar = pb.ProgressBar(maxval=self.joints.shape[0], widgets=[txt, pb.Percentage(), pb.Bar()])
pbar.start()
# Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC(*'DIVX')
video = cv2.VideoWriter('{}/depth_{}.avi'.format(self.subfolder, filename), fourcc, self.fps, (height, width))
if not video:
raise EnvironmentError("Error in creating video writer")
for i in range(self.joints.shape[0]):
jt = self.joints[i]
img = self.plotResult3D_OS(sequence.data[i].dpt, sequence.data[i].T, sequence.data[i].gt3Dorig, jt,
showPC=showPC, showGT=showGT, niceColors=niceColors, width=width, height=height)
img = numpy.flipud(img)
img = img[:, :, [2, 1, 0]] # change color channels for OpenCV
img = cv2.resize(img, (height, width))
if plotFrameNumbers:
if sequence.data[i].subSeqName == 'ref':
cv2.putText(img, "Reference Frame {}".format(i), (20, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255))
# plot frame number
cv2.putText(img, "{}".format(i), (height-50, width-10), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 0, 255))
# write frame
video.write(img)
pbar.update(i)
video.release()
del video
cv2.destroyAllWindows()
pbar.finish()
评论列表
文章目录