首页 > 解决方案 > 在python中显示numpy的帧堆栈

问题描述

我有一个形状为 (1,64,96,4) 的 numpy 堆栈,其中 (64,96) 是对应于从屏幕(帧)捕获的图像的像素,4 是堆叠的帧数。所以基本上堆栈有4个二维数组(64,96)。该堆栈用作 Deep q 网络的输入。

我想用 matplotlib 显示不同的帧,但我没有设法访问正确的元素。

这是创建帧堆栈的代码:

frame = self.preprocess_frame(frame)  # (64,96)
state = np.stack([frame] * 4, axis=-1)
state = state.reshape(1, state.shape[0], state.shape[1], state.shape[2])  # 1*64*96*4, the extra dimension is only used for Keras library

return state

问题是如何从堆栈中访问不同的帧,以便将它们送入matplotlib.imshow

我试过这个只得到一帧,但没有成功:

plt.imshow(state[1], state[2])
plt.show()

先感谢您 !!!

标签: pythonmatplotlib

解决方案


推荐阅读