stimuli.visuals.Text

class stimuli.visuals.Text(window_name='Visual', window_size=None)

Class to display a text.

Parameters:
window_namestr

Name of the window in which the visual is displayed.

window_sizetuple | None

Either None to automatically select a window size based on the available monitors, or a 2-length of positive integer sequence as (width, height) in pixels.

Attributes

background

Background color in BGR color space.

img

Image array.

window_center

Window's center position.

window_name

Window's name.

window_size

Window's size (width x height).

Methods

close()

Close the visual.

draw_background(color)

Draw a uniform single color background.

putText(text[, fontFace, fontScale, color, ...])

Add text to the visual.

show([wait])

Show the visual with cv2.imshow() and cv2.waitKey().

close()

Close the visual.

draw_background(color)

Draw a uniform single color background.

Replace all the pixels with this color, thus this method erases any prior work.

Parameters:
colorstr | tuple

Color used to draw the background.

Notes

A color is provided as matplotlib string or as (B, G, R) tuple of int8 set between 0 and 255.

putText(text, fontFace=2, fontScale=2, color='white', thickness=2, lineType=16, position='centered')

Add text to the visual.

Parameters:
textstr

Text to display.

fontFaceint cv2.FONT

Font to use to write the text.

fontScaleint

Font scale factor multiplied by the font-specific base size.

colorstr | tuple

Color used to write the text.

thicknessint

Text line thickness in pixel.

lineTypeint cv2.LINE

Type of line to use.

positionstr | tuple

Position of the bottom left corner of the text. See notes for additional information.

Notes

A color is provided as matplotlib string or as (B, G, R) tuple of int8 set between 0 and 255. The position of the object can be either defined as the string ‘center’ or ‘centered’ to position the object in the center of the window; or as a 2-length tuple of positive integer. The position is defined in pixels in opencv coordinates, with (0, 0) being the top left corner of the window.

show(wait=1)

Show the visual with cv2.imshow() and cv2.waitKey().

Parameters:
waitint

Wait timer passed to cv2.waitKey() [ms].

property background

Background color in BGR color space.

property img

Image array.

property window_center

Window’s center position.

property window_name

Window’s name.

property window_size

Window’s size (width x height).