本文整理匯總了Python中pygaze.screen.Screen.draw_image方法的典型用法代碼示例。如果您正苦於以下問題:Python Screen.draw_image方法的具體用法?Python Screen.draw_image怎麽用?Python Screen.draw_image使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pygaze.screen.Screen
的用法示例。
在下文中一共展示了Screen.draw_image方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1:
# 需要導入模塊: from pygaze.screen import Screen [as 別名]
# 或者: from pygaze.screen.Screen import draw_image [as 別名]
# pause screen
scr.clear()
scr.draw_text(text="Press Space to continue.")
disp.fill(scr)
disp.show()
kb.get_key(keylist=["space"], timeout=None, flush=True)
# # # # #
# IMAGES
# loop through images
for imgpath in IMAGES:
# draw image
scr.clear(colour=(255,255,255))
scr.draw_image(imgpath)
disp.fill(scr)
# start recording
tracker.start_recording()
tracker.log("IMAGE_TRIALSTART")
tracker.log("imgname=%s" % (os.path.basename(imgpath)))
# show display
disp.show()
tracker.log("image_on")
# wait for a bit
clock.pause(IMGTIME)
# clear screen
scr.clear()
disp.fill(scr)
disp.show()
# stop recording
示例2: EyelinkGraphics
# 需要導入模塊: from pygaze.screen import Screen [as 別名]
# 或者: from pygaze.screen.Screen import draw_image [as 別名]
#.........這裏部分代碼省略.........
"""
Prints alert message.
Arguments:
msg -- The message to be played.
"""
print "eyelink_graphics.alert_printf(): %s" % msg
def setup_image_display(self, width, height):
"""
Initializes the buffer that will contain the camera image.
Arguments:
width -- The width of the image.
height -- The height of the image.
"""
self.size = width, height
self.clear_cal_display()
self.last_mouse_state = -1
self.imagebuffer = self.new_array()
def image_title(self, text):
"""
Sets the current image title.
Arguments:
text -- An image title.
"""
while ": " in text:
text = text.replace(": ", ":")
self.title = text.split()
def draw_image_line(self, width, line, totlines, buff):
"""
Draws a single eye video frame, line by line.
Arguments:
width -- Width of the video.
line -- Line nr of current line.
totlines -- Total lines in video.
buff -- Frame buffer.
imagesize -- The size of the image, which is (usually?) 192x160 px.
"""
# If the buffer hasn't been filled yet, add a line.
for i in range(width):
try:
self.imagebuffer.append(self.pal[buff[i]])
except:
pass
# If the buffer is full, push it to the display.
if line == totlines:
self.scale = totlines / 320.0
self._size = int(self.scale * self.size[0]), int(self.scale * self.size[1])
# Convert the image buffer to a pygame image, save it ...
self.cam_img = pygame.image.fromstring(self.imagebuffer.tostring(), self._size, "RGBX")
if self.extra_info:
self.draw_cross_hair()
self.draw_title()
pygame.image.save(self.cam_img, self.tmp_file)
# ... and then show the image.
self.screen.clear()
self.screen.draw_image(self.tmp_file, scale=1.5 / self.scale)
self.display.fill(self.screen)
self.display.show()
# Clear the buffer for the next round!
self.imagebuffer = self.new_array()
def set_image_palette(self, r, g, b):
"""
Sets the image palette.
TODO: What this function actually does is highly mysterious. Figure it
out!
Arguments:
r -- The red channel.
g -- The green channel.
b -- The blue channel.
"""
self.imagebuffer = self.new_array()
self.clear_cal_display()
sz = len(r)
i = 0
self.pal = []
while i < sz:
rf = int(b[i])
gf = int(g[i])
bf = int(r[i])
self.pal.append((rf << 16) | (gf << 8) | (bf))
i += 1
示例3: EyelinkGraphics
# 需要導入模塊: from pygaze.screen import Screen [as 別名]
# 或者: from pygaze.screen.Screen import draw_image [as 別名]
#.........這裏部分代碼省略.........
Arguments:
msg -- The message to be played.
"""
print "eyelink_graphics.alert_printf(): %s" % msg
def setup_image_display(self, width, height):
"""
Initializes the buffer that will contain the camera image.
Arguments:
width -- The width of the image.
height -- The height of the image.
"""
self.size = (width,height)
self.clear_cal_display()
self.last_mouse_state = -1
self.imagebuffer = array.array('l')
def image_title(self, text):
"""
TODO: What does this do?
Arguments:
text -- Unknown.
"""
pass
def draw_image_line(self, width, line, totlines, buff):
"""
Draws a single eye video frame, line by line.
Arguments:
width -- Width of the video.
line -- Line nr of current line.
totlines -- Total lines in video.
buff -- Frame buffer.
imagesize -- The size of the image, which is (usually?) 192x160 px.
"""
# If the buffer hasn't been filled yet, add a line.
for i in range(width):
try:
self.imagebuffer.append(self.pal[buff[i]])
except:
pass
# If the buffer is full, push it to the display.
if line == totlines:
# First create a PIL image, then convert it to a PyGame image, and
# then save it to a temporary file on disk. This juggling with
# formats is necessary to show the image without distortions under
# (so far) all conditions. Surprisingly, it doesn't cause any
# appreciable delays, relative to directly invoking PyGame or
# PsychoPy functions.
bufferv = self.imagebuffer.tostring()
img = Image.new("RGBX", self.size)
imgsz = self.xc, self.yc
img.fromstring(bufferv)
img = img.resize(imgsz)
示例4:
# 需要導入模塊: from pygaze.screen import Screen [as 別名]
# 或者: from pygaze.screen.Screen import draw_image [as 別名]
#scr.draw_fixation()
scr.clear()
scr.draw_text("There should be three fixation targets on the screen: \
\nred cross on the left, green X in the centre, and blue dot on the right", pos=(DISPSIZE[0]/2, DISPSIZE[1]/4))
scr.draw_fixation(fixtype='cross', colour=(255,0,0), pos=(DISPSIZE[0]*0.25,DISPSIZE[1]/2), pw=3, diameter=15)
scr.draw_fixation(fixtype='x', colour=(0,255,0), pos=(DISPSIZE[0]/2,DISPSIZE[1]/2), pw=3, diameter=15)
scr.draw_fixation(fixtype='dot', colour=(0,0,255), pos=(DISPSIZE[0]*0.75,DISPSIZE[1]/2), pw=3, diameter=15)
disp.fill(scr)
disp.show()
kb.get_key()
#scr.draw_image()
scr.clear()
scr.draw_text("There should be an image in the centre of the screen", pos=(DISPSIZE[0]/2, DISPSIZE[1]/10))
scr.draw_image(imagefile)
disp.fill(scr)
disp.show()
kb.get_key()
#scr.set_background_colour()
scr.set_background_colour(colour=(200,100,100))
scr.clear()
scr.draw_text("This screen should a different background colour than the previous screen", pos=(DISPSIZE[0]/2, DISPSIZE[1]/4))
disp.fill(scr)
disp.show()
kb.get_key()
scr.set_background_colour(BGC)
# # # # #
示例5: str
# 需要導入模塊: from pygaze.screen import Screen [as 別名]
# 或者: from pygaze.screen.Screen import draw_image [as 別名]
kb.get_key()
eventfuncs[i]()
scr.clear()
scr.draw_text("Function %s works! Press space to test the next" % str(eventfuncs[i]))
disp.fill(scr)
disp.show()
kb.get_key()
# # # # #
# test gaze contingency
# AOI
scr.clear()
scr.draw_text("There should be an image in the centre of the screen", pos=(DISPSIZE[0]/2, DISPSIZE[1]/10))
scr.draw_image(imagefile) # imginfo: 400x600 px; kitten head position relative to image x=40, y=160, w=130, h=140
x = (DISPSIZE[0]/2 - 200) + 40 # centre minus half of the image width, plus kitten head X position in image
y = (DISPSIZE[1]/2 - 300) + 160 # centre minus half of the image height, plus kitten head Y position in image
aoi = AOI('rectangle',(x,y),(130,140))
disp.fill(scr)
t1 = disp.show()
log.write(["AOI", t1])
key = None
tracker.start_recording()
while key != 'space':
# check for key input
key, presstime = kb.get_key(keylist=['space'],timeout=1)
# get gaze position
gazepos = tracker.sample()
# check if the gaze position is within the aoi
if aoi.contains(gazepos):