Last active
August 4, 2019 16:31
-
-
Save hiwonjoon/eba0222f505dd766fefacf977bb28cc3 to your computer and use it in GitHub Desktop.
Code Snippets for displaying image frames (NWHC format, numpy array) in Jupyter Notebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from matplotlib import pyplot as plt | |
from matplotlib import animation, rc | |
from IPython.core.display import display, HTML | |
%matplotlib inline | |
%load_ext autoreload | |
%autoreload 2 | |
def display_frames_as_gif(frames): | |
fig, ax = plt.subplots() | |
patch = ax.imshow(frames[0]) | |
title_obj = ax.set_title(0) | |
def animate(i): | |
patch.set_data(frames[i]) | |
plt.setp(title_obj,color='k', text=('Time: %d' % (i))) | |
anim = animation.FuncAnimation(fig, animate, range(len(frames)), interval=50) | |
display(HTML(anim.to_html5_video())) | |
plt.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import moviepy.editor as mpy | |
clip = mpy.ImageSequenceClip([(ob*255.).astype(np.uint8) for ob in obs],fps=30) | |
clip.write_videofile('video.mp4', verbose=False,ffmpeg_params=['-y'],progress_bar=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment