我发现为不同的程序运行vispy非常快,但不幸的是没有教程。
如何使用vispy创建图像动画?
发布于 2020-09-30 21:06:21
如果需要,我可以稍后尝试将一些代码组合在一起,但一般的想法是使用(目前是私有的,我将在下一个版本中修复它) vispy.gloo.util._screenshot方法(请参阅here)来获得您需要的各个帧。
要创建动画,您需要执行某种for循环(或类似于计时器),获取画布的屏幕截图numpy数组,然后使用imageio等库将帧写入某种输出格式。
编辑:
这就是了:
https://gist.github.com/93a70d94aec69db9dd74c99673f0a2bc
我从vispy存储库获取了rotating_cube.py示例,并添加了一个基于计时器创建动画的非常基本的形式。这可以在没有可视化的情况下完成,但需要像EGL这样的特定后端,并且如果事情不能正常工作,可能需要更长的答案。
以下是我对原始旋转立方体示例所做的更改:
diff --git a/examples/basics/gloo/rotate_cube.py b/examples/basics/gloo/rotate_cube.py
index e9c54f49..01306497 100644
--- a/examples/basics/gloo/rotate_cube.py
+++ b/examples/basics/gloo/rotate_cube.py
@@ -9,6 +9,8 @@ You should see a colored outlined spinning cube.
import numpy as np
from vispy import app, gloo
from vispy.util.transforms import perspective, translate, rotate
+from vispy.gloo.util import _screenshot
+import imageio
vert = """
// Uniforms
@@ -126,11 +128,24 @@ class Canvas(app.Canvas):
gloo.set_polygon_offset(1, 1)
self._timer = app.Timer('auto', connect=self.on_timer, start=True)
+ self._animation_timer = app.Timer(0.1, connect=self.on_animation, start=True)
+ self._animation_writer = imageio.get_writer("rotating_cube.mp4", fps=5)
+ self._animation_counter = 0
self.show()
+ def on_animation(self, event):
+ frame = _screenshot()
+ self._animation_writer.append_data(frame)
+ self._animation_counter += 1
+ if self._animation_counter >= 25:
+ self._animation_timer.stop()
+ self._animation_writer.close()
+ self.close()
+https://stackoverflow.com/questions/63603005
复制相似问题