Exemplo n.º 1
0
def make_gif(frames, out_fn):
    """
    :param frames: list of .png files representing frames in the animation
    :param out_fn: name of the output folder - create this folder inside the output folder
    :return: .gif file showing the simulated path as an animation
    """
    ofn = 'outputs/' + out_fn + '/'
    clip = ImageSequenceClip(frames, fps=4)
    clip.write_gif(ofn + out_fn + '.gif')
    clip.close()
Exemplo n.º 2
0
def generador(lista_estados, cf, cc):
    imagenes = []
    for md in lista_estados:
        mi = np.zeros([cf, cc, 3], dtype=np.uint8)
        for i in range(cf):
            for j in range(cc):
                mi[i, j] = [255, 128, 0] if (md[i, j] == True) else [0, 0, 255]
        imagenes.append(mi)
    clip = ImageSequenceClip(imagenes,
                             fps=1)  # fps = 1 indica un cuadro por segundo
    clip.write_gif('automata.gif')
    clip.close()
    return
Exemplo n.º 3
0
Arquivo: misc.py Projeto: luuil/Tools
def create_video(images: Union[np.ndarray, List[str]], video_out: str, fps=None, ismask=False):
    if isinstance(images, list):
        flag_load_image = True
    else:
        assert images.ndim == 3 or images.ndim == 4, f'only support 3 or 4 dimension inputs, now: {images.ndim}'
        flag_load_image = False

    logging.info(f'num of images to create video: {len(images)}')
    try:
        clip = ImageSequenceClip(images, fps=fps, ismask=ismask, load_images=flag_load_image)
        clip.write_videofile(video_out)
        clip.close()
    except Exception as e:
        logging.error(e)
    logging.info(f'saved video successful: {video_out}')
Exemplo n.º 4
0
 async def save_gif(gif_frames, dest, fps=10):
     """生成 gif
     将输入的帧数据合并成视频并输出为 gif
     参数
     gif_frames: list<numpy.ndarray>
     为每一帧的数据
     dest: str
     为输出路径
     fps: int, float
     为输出 gif 每秒显示的帧数
     返回
     None
     但是会输出一个符合参数的 gif
     """
     clip = ImageSequenceClip(gif_frames, fps=fps)
     clip.write_gif(dest)  # 使用 imageio
     clip.close()
Exemplo n.º 5
0
 def save_imgs_as_video(self, imgs, filename, fps):
     util.mkdir(self._opt.output_dir)
     clip = ImageSequenceClip(imgs, fps=fps)
     # clip.write_gif(os.path.join(self._opt.output_dir, filename))
     clip.write_videofile(os.path.join(self._opt.output_dir, filename))
     clip.close()
print("Plotting done. Time elapsed (sec): " + str(time.time() - startTime))

#%%
##########
# Make Gif
##########
#https://www.tutorialexample.com/python-create-gif-with-images-using-moviepy-a-complete-guide-python-tutorial/

images = []
for fileName in os.listdir(saveDirectory + '/' +
                           field):  #set in initial parameters
    images.append(saveDirectory + '/' + field + '/' + fileName)
print(images)
clip = ImageSequenceClip(images, fps=15)
clip.write_gif(saveDirectory + '/' + field + '.gif')  #saves in outside folder
clip.close()
#DANGER!!! The line below removes the directory.
# shutil.rmtree(saveDirectory + '/' + field) #delete images to save space

#%%
################
# Zoom CORRECTLY
################

ds = yt.load(directory + "parkerCRs_hdf5_plt_cnt_0000")
ad = ds.all_data()
# field = 'density'
field = 'cray'
tempThreshold = ".35*10e3"  #Format as string
conversion = 3.086e21
bounds = {