简体   繁体   English

列出 numpy arror 以使用 imageio 作为视频写入

[英]List to numpy arror to write with imageio as video

I have a list as all_frames.我有一个作为 all_frames 的列表。 I want to write this as a video with imageio but I got the error that you can find in below.我想用 imageio 把它写成一个视频,但我得到了你可以在下面找到的错误。 How can I change all_frame from list to np.array?如何将 all_frame 从 list 更改为 np.array?

错误

You can find imageio code in below:您可以在下面找到 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)

Try this edit:试试这个编辑:

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

That must converts images to numpy arrays.这必须将图像转换为 numpy arrays。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM