gpt4 book ai didi

Python数组3D转视频

转载 作者:行者123 更新时间:2023-12-01 07:57:08 25 4
gpt4 key购买 nike

是否有一种简单的方法可以将 500x500x60 数组转换为 60 帧视频并另存为 avi?

我成功地获得了一个 plt.imshow 窗口,以便与动画环境一起制作动画。但我怎样才能正确保存它呢?

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()

最佳答案

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

ani.save('cube_movie.avi', writer="ffmpeg", fps=15)

而不是plt.show

关于Python数组3D转视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55921364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com