gif_transforms.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:pytorch-seq2seq 作者: rowanz 项目源码 文件源码
def load_frames(folder_name, offset=0, desired_fps=3, max_frames=40):
    """
    :param folder_name: Filename with a gif
    :param offset: How many frames into the gif we want to start at
    :param desired_fps: How many fps we'll sample from the image
    :return: [T, h, w, 3] GIF
    """
    coll = ImageCollection(folder_name + '/out-*.jpg', mode='RGB')

    try:
        duration_path = folder_name + '/duration.txt'
        with open(duration_path,'r') as f:
            durs = f.read().splitlines()
            fps = 100.0/durs[0]
    except:
        # Some error occurs
        fps = 10

    # want to scale it to desired_fps
    keep_ratio = max(1., fps/desired_fps)

    frames = np.arange(offset, len(coll), keep_ratio).astype(int)[:max_frames]

    def _add_chans(img):
        if img.ndim == 3:
            return img
        return np.stack([img]*3,-1)

    imgs_concat = concatenate_images([_add_chans(coll[f]) for f in frames])
    assert imgs_concat.ndim == 4
    return imgs_concat
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号