0

pyplot アニメーションを使用して、CCD カメラでキャプチャされたフレームをリアルタイムで表示しようとしています。これをテストするためだけに短い python スクリプトを書きましたが、動作している間は不規則に動作します。1ダースほどのアニメーション フレームをすばやく更新し、1 秒間一時停止してから、もう一度更新してから、再び一時停止するという動作を繰り返します。プロットを継続的かつスムーズに更新したいのですが、どこが間違っているのかわかりません。

カメラのフレーム バッファを呼び出す部分ではないことはわかっています。ループでそれを呼び出すだけでテストしましたが、遅くなることはなかったので、アニメーションフレームの実際の処理のどこかにあると思います。

私のコードは以下の通りです:

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:].sum(axis=0)[::-1] は 1x1338 の整数配列を返します。アニメーションが一度に処理するには、これが多すぎるとは思いません。

4

1 に答える 1