首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python数组3D转视频

Python数组3D转视频
EN

Stack Overflow用户
提问于 2019-04-30 20:51:47
回答 1查看 721关注 0票数 1

有没有一种简单的方法可以将500x500x60阵列转换为60帧的视频并保存为avi?

我设法获得了一个plt.imshow窗口,以便与动画环境一起进行动画。但是我如何正确地保存它呢?

代码语言:javascript
复制
def animate_cube(cube_array, cut=True, mn=0, sd=0, interval=75, cmap='hot'):
    '''
    animates a python cube for quick visualisation. CANNOT BE SAVED.

    INPUT:
        cube_array  : name of 3D numpy array that needs to be animated.
        cut         : trims pixels off of the images edge to remove edge detector effects.
                      Default = True as 0 returns empty array.
        mn          : mean of the cube | Used for contrast
        sd          : std of the cube  | Used for contrast
        interval    : #of ms between each frame.
        cmap        : colormap. Default='hot'

    OUTPUT:
        animated window going through the cube.

    '''

    fig = plt.figure()
    std = np.std(cube_array[0])
    mean = np.mean(cube_array[0])
    if mn==sd and mn==0:
        img = plt.imshow(cube_array[0][cut:-cut, cut:-cut], animated=True, vmax=mean+3*std, vmin=mean-3*std, cmap=cmap)
    else:
        img = plt.imshow(cube_array[0][cut:-cut, cut:-cut], animated=True, vmax=mn+3*sd, vmin=mn-3*sd, cmap=cmap)

    def updatefig(i):
        img.set_array(cube_array[i][cut:-cut, cut:-cut])
        return img,

    ani = animation.FuncAnimation(fig, updatefig, frames=cube_array.shape[0],                                  interval=interval, blit=True)
    plt.colorbar()
    plt.show()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-30 22:39:13

您是否尝试过插入类似以下内容的内容:

代码语言:javascript
复制
ani.save('cube_movie.avi', writer="ffmpeg", fps=15)

代替plt.show

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55921364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档