Hi Friends.
I need to load 600 pictures in the computer.
Use PIL to load original pictures spend about 45 seconds now.
It’s too long to load picitures.
I read the baseVisual.py。In def _createTexture it says “tex : Any Texture data. Value can be anything that resembles image data.”
And I find some codes about:
if type(tex) == numpy.ndarray:
But I use the numpy data,the screen shows strange pictures.Full screen are white only a litter space are red.
This is my code:
def ReadPicture(dirPath, win):
pic = []
# 对目录下的文件进行遍历
for file in os.listdir(dirPath):
# 判断是否是文件
if os.path.isfile(os.path.join(dirPath, file)) == True:
c = os.path.basename(file)
name = dirPath + '\\' + c
im1 = Image.open(name)
im = np.array(im1) # here I transfer the numpy data.
pic.append(visual.ImageStim(win, image=im, units='norm', size=2))
return pic
def demo(win):
time_start = time.time()
pic = ReadPicture("../img/pic/",win)
time_end = time.time()
print("time cost:",time_end-time_start)
loopFlag = True
while loopFlag:
for i in range(len(pic)):
pic[i].draw()
win.flip()
if keyboard.is_pressed('escape'):
loopFlag = False
continue
if __name__ == "__main__":
mon = monitors.Monitor(
name='my_monitor',
# width=53.704, # 显示器宽度,单位cm
# distance=45, # 被试距显示器距离,单位cm
gamma=None, # gamma值
verbose=False) # 是否输出详细信息
mon.setSizePix(utilSize) # 设置显示器分辨率
mon.save() # 保存显示器信息
win = visual.Window(monitor=mon, size=(1900,1000), fullscr=False,
screen=0, winType='pyglet', units='norm') # , allowGUI=False
# 退出
demo(win)
Are there have any way to increase the loading speed?
Or transfer the numpy data to imageStim is the best way to increase the loading speed?
Looking forward to receiving reply.
Thanks!