pred_brain.exp.markers#
Utilities for generating PsychoPy stimuli from ArUco and AprilTag markers.
- pred_brain.exp.markers.create_fiducial_marker_stimuli(win: psychopy.visual.Window, marker_family: str, marker_ids: Iterable[int], marker_size_pixels: int, auto_layout: bool = True, margin: float = 0.1) list[psychopy.visual.ImageStim]#
Generate PsychoPy stimuli for a collection of fiducial markers.
Markers are generated from one of OpenCV’s predefined ArUco or AprilTag dictionaries. Each marker is returned as an independent
psychopy.visual.ImageStim.marker_size_pixelsspecifies the total width and height of the displayed stimulus, including a white outer quiet zone. The detectable ArUco or AprilTag marker occupies the remaining central area.The approximate width and height of the detectable marker are calculated as:
detectable_size_pixels = ( marker_size_pixels - 2 * marker_size_pixels * margin )
For example, with
marker_size_pixels=200andmargin=0.10, the total stimulus is 200 × 200 pixels and the detectable marker is approximately 160 × 160 pixels, with approximately 20 pixels of white margin on each side.When automatic layout is enabled, 4, 6, or 8 markers are positioned around the perimeter of the window. Marker IDs are assigned clockwise, beginning at the top-left:
Four markers:
0 -------- 1 | | 3 -------- 2
Six markers:
0 ---- 1 ---- 2 | | 5 ---- 4 ---- 3
Eight markers:
0 ---- 1 ---- 2 | | 7 3 | | 6 ---- 5 ---- 4
- Parameters:
- winpsychopy.visual.Window
Window in which the marker stimuli will be drawn.
- marker_familystr
Marker dictionary to use. Supported values are:
AprilTag families:
"16h5","25h9","36h10", and"36h11".ArUco dictionaries in
"{size}_{number}"format, such as"4x4_50"or"6x6_250".The original ArUco dictionary:
"aruco_original".
Family names are case-insensitive, and surrounding whitespace is ignored.
- marker_idsIterable[int]
Marker identifiers to generate. Each identifier must be valid for the selected dictionary. When automatic layout is enabled, their order determines their clockwise placement, beginning at the top-left.
- marker_size_pixelsint
Total width and height of each square stimulus, in pixels, including the white outer margin.
- auto_layoutbool, default=True
If
True, automatically position the complete marker stimuli around the perimeter of the window. Automatic layout supports exactly 4, 6, or 8 markers. IfFalse, all markers are initially centered at(0, 0).- marginfloat, default=0.10
Width of the white quiet zone on each side, expressed as a fraction of the total stimulus size. Must be greater than or equal to 0 and less than 0.5. For example,
margin=0.10gives a white margin equal to 10% of the total stimulus width on each side.
- Returns:
- list of psychopy.visual.ImageStim
Generated marker stimuli in the same order as
marker_ids.
- Raises:
- TypeError
If an argument has an invalid type.
- ValueError
If the marker family, marker IDs, total marker size, margin, or automatic layout is invalid.
- RuntimeError
If the installed OpenCV build does not provide the
arucomodule.