下面附有一些代码,显示一定数量的帧的激励。
from psychopy import visual, logging, event, core
#create a window to draw in
myWin = visual.Window((600,600), allowGUI=False, blendMode='add', useFBO=True)
logging.console.setLevel(logging.DEBUG)
#INITIALISE SOME STIMULI
grating1 = visual.GratingStim(myWin,mask="gauss",
color=[1.0,1.0,1.0],contrast=0.5,
size=(1.0,1.0), sf=(4,0), ori = 45,
autoLog=False)#this stim changes too much for autologging to be useful
grating2 = visual.GratingStim(myWin,mask="gauss",
color=[1.0,1.0,1.0],opacity=0.5,
size=(1.0,1.0), sf=(4,0), ori = -45,
autoLog=False)#this stim changes too much for autologging to be useful
for frameN in range(300):
grating1.draw()
grating2.draw()
win.flip()
myWin.flip() #update the screen
在60Hz帧刷新率下,300帧应约为5秒。当我测试它时 - 它肯定比那更长。
在我的实验中,我需要的帧数少至2帧 - 似乎我的代码不会准确显示。
我想知道是否有更好的方法来显示帧数?比如在for循环之前使用grating1.draw()
和grating1.draw()
可能吗?
我感谢任何帮助 - 谢谢!
答案 0 :(得分:0)
时序差异可能是由于帧速率不完全是60Hz。尝试使用myWin.getActualFrameRate()(PsychoPy documentation)来获取实际帧速率。将实际帧速率乘以5.0秒理论上可以让您精确绘制5.0秒。
frame_rate = myWin.getActualFrameRate(nIdentical=60, nMaxFrames=100,
nWarmUpFrames=10, threshold=1)
# The number of frames you want to display is equal to
# the product of frame-rate and the number of seconds to display
# the stimulus.
# n_frames = frame_rate * n_seconds
for frameN in range(frame_rate*5.0):
grating1.draw()
grating2.draw()
myWin.flip()