【问题标题】:List to numpy array to write with imageio as video列出要使用 imageio 作为视频写入的 numpy 数组
【发布时间】:2022-08-12 21:47:02
【问题描述】:

我有一个作为 all_frames 的列表。我想用 imageio 把它写成一个视频,但我得到了你可以在下面找到的错误。如何将 all_frame 从 list 更改为 np.array?

您可以在下面找到 imageio 代码:

all_frames = []

 for j, image in enumerate(image_batch): 
        image_index = (i * batch_size) + j
        if not self.use_tf:
            image = (image.permute(1, 2, 0) * 127.5 + 128).clamp(0, 255).to(torch.uint8).squeeze(0)
        array = np.array(image)

        for effect in self.custom_effects:
            array = effect.apply_effect(array = array, 
                                        index = image_index)

        final_image = Image.fromarray(array, \'RGB\')

        if resolution:
            final_image = final_image.resize((resolution, resolution))


        
        all_frames.append(final_image)

imageio.mimwrite(\'tmp.mp4\', all_frames, quality=8, fps=self.sr/self.frame_duration)
  • 由于您的代码 all_frames 列表为空,但必须是二维数组的列表。
  • 必须有一些循环使用图像填充“all_frames”。
  • 问题在于all_frames 列表包含的元素。所以贴出相关的代码。
  • 我发布了@Hihikomori
  • all_frames 包含 PIL 图像,它们不是 numpy 数组。我相信您可以将array 添加到all_frames

标签: python arrays numpy video-processing python-imageio


【解决方案1】:

试试这个编辑:

all_frames.append(np.array(final_image,np.uint8))

那必须将图像转换为 numpy 数组。

【讨论】:

  • 你做到了!谢谢!
猜你喜欢
  • 1970-01-01
  • 2021-06-17
  • 2019-12-07
  • 2014-04-26
  • 2020-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-09
相关资源
最近更新 更多