在python中,最有效的刷图像方式是什么?
目前我有一个无限的while循环,它在最后调用睡眠,然后使用matplotlib来显示图像。但是我无法让 matplotlib 替换当前图像,而是必须关闭然后再次显示,这很慢。我想以设定的频率尽可能精确地闪烁图像序列。
我对使用其他库进行就地替换的解决方案持开放态度。
使用 openCV,您可以使用它来迭代图像并显示它们
for img in images:
# Show the image (will replace previously displayed images
# with the same title)
cv2.imshow('window title', img)
# Wait 1000ms before showing the next image and if the user
# pressed 'q', close the window and stop looping through the dataset
if cv2.waitKey(1000) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
使用一个名为 PsychoPy 的库。它可以保证绘制所有内容,并允许您使用 window.frame(( 函数控制何时绘制窗口(框架(。