2013-07-12 1 views
0

pyplot 애니메이션을 사용하여 CCD 카메라로 캡처 한 프레임을 실시간으로 표시하려고합니다. 나는 이것을 시험해보기 위해 짧은 파이썬 스크립트를 썼다. 그리고 그것이 작동하는 동안, 그것은 그렇게 이상하게한다. 애니메이션 프레임을 12 개 정도 빠르게 업데이트 한 다음 잠시 멈추고 다시 업데이트 한 다음 다시 일시 중지합니다. 줄거리를 계속 원활하게 업데이트하고 싶지만, 어디서 잘못 될지 잘 모르겠습니다.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 배열을 반환한다. 한 번에 처리 할 애니메이션이 너무 많을 것이라고 생각하지 않습니다.

+0

간격을 늘리면 더 잘 실행됩니까? 나는 10ms가 100fps라는 것을 지적 할 것이다. 나는 범인이 당신이 그 비율로 캔버스를 다시 그리지 못하는 것을 사용하고있는 GUI 프레임 워크라고 생각합니다. 질문이 있거나 그냥 징징 대는 것인지 확실하지 않습니다. – tacaswell

+0

간격을 변경해도 도움이되지 않습니다. 내 질문은 내가 설명했듯이 음모로 인해 음모가 업데이트되는 원인이다. 문제가 pyplot이고 다른 플롯 라이브러리가 더 잘 작동하거나 pyplot 내에 뭔가가 있으면이 문제를 해결할 수 있습니다. – camronm21

답변

1

문제는 다음 작품 잘, animation에없는 :

import numpy as np 
from matplotlib import pyplot as plt 
from matplotlib import animation 

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)  
ax.set_xlim([0, 2 *np.pi]) 
ax.set_ylim([-1, 1]) 

th = linspace(0, 2 * np.pi, 1000) 

line, = ax.plot([],[],'b-', animated=True) 
line.set_xdata(th) 
# 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(): 
    t = 0 
    while True: 
     t +=1 
     yield np.sin(th + t * np.pi/100) 

# call the animator 
anim = animation.FuncAnimation(fig, update, data_gen, interval=10, blit=True) 

choppyness 중 하나를 당신의 프레임 그래버, 당신이 그것을하고있는 계산, 또는 충분한 시간을 점점 GUI 문제에서 올 수 있습니다 주 스레드에서 다시 그릴 수 있습니다. time.sleep() required to keep QThread responsive?