0
我試圖使用pyplot動畫實時顯示由CCD相機捕獲的幀。我寫了一個簡短的python腳本來測試這個,並且在它工作的時候,它的確是不正常的。它會快速更新十幾個動畫幀,然後暫停一秒鐘,然後再次更新,然後再次暫停,依此類推。我希望能夠持續平穩地更新劇情,但我不確定我出錯的位置。Pyplot動畫不連續更新
我知道它不是調用相機幀緩衝區的部分;我測試過只是在一個循環中調用它,並且它永遠不會放慢速度,所以我認爲它在動畫幀的實際處理中處於某個位置。
我的代碼是下面:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
import Pixis100
import time
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = fig.add_subplot(111)
# Create ccd object
ccd = Pixis100.device()
ccd.snapshot()
ccd.focusStart()
# focusStart() tells the camera to start putting captured frames into the buffer
line, = ax.plot(ccd.getFrame()[:,2:].sum(axis=0)[::-1],'b-')
# getFrame() makes a call to the CCD frame buffer and retrieves the most recent frame
# animation function
def update(data):
line.set_ydata(data)
return line,
def data_gen():
while True: yield ccd.getFrame()[:,2:].sum(axis=0)[::-1]
# call the animator
anim = animation.FuncAnimation(fig, update, data_gen,interval=10,blit=True)
plt.show()
ccd.focusStop()
# focusStop() just tells the camera to stop capturing frames
作爲參考,ccd.getFrame()[:,2:]。總和(軸= 0)[:: - 1]返回整數的1x1338陣列。我不認爲這對動畫一次處理太多了。
如果您增加間隔,它會運行得更好嗎?我會指出10ms是100fps。我懷疑這裏的罪魁禍首是你正在使用的gui-frame工作,不能以此速度重畫畫布。這也不清楚你是否有問題或只是抱怨。 – tacaswell
更改間隔時間不起作用。正如我所描述的,我的問題是什麼會導致情節更新不正常,如果這是pyplot的問題,並且不同的繪圖庫會更好地工作,或者如果pyplot內有某些東西可以解決此問題。 – camronm21