コード例 #1
0
    def play_movie(self, ns, eyetracker, mouse, gaze_debug):
        self.images['l'].pos = [-self.peripheral_offset, 0]
        self.images['r'].pos = [self.peripheral_offset, 0]

        # Play movie
        self.win.callOnFlip(self.add_event, ns, eyetracker, 'mov1', 'movie start', self.code_table)

        attending_frames = 0
        while not self.video_stim.stim.status == visual.FINISHED:

            # Draw video frames and stimuli
            self.video_stim.stim.draw()
            for image in self.images.values():
                image.draw()
            draw_eye_debug(gaze_debug, eyetracker, mouse)

            self.win.flip()

            # Get gaze position from eyetracker or mouse
            gaze_position = (0, 0)
            if eyetracker is not None:
                gaze_position = eyetracker.getCurrentGazePosition()
                gaze_position = (0.5 * (gaze_position[0] + gaze_position[2]),
                                 0.5 * (gaze_position[1] + gaze_position[3]))
            elif mouse is not None:
                gaze_position = mouse.getPos()

            # Check if looking at face
            if fixation_within_tolerance(gaze_position, self.init_frame.pos, 10, self.win):
                if gaze_debug is not None:
                    gaze_debug.fillColor = (-1, -1, 1)
                attending_frames += 1
                if attending_frames == 1:
                    self.win.callOnFlip(self.add_event, ns, eyetracker, 'att2', 'attn face', self.code_table)
            else:
                if gaze_debug is not None:
                    gaze_debug.fillColor = (1, -1, -1)
        if gaze_debug is not None:
            gaze_debug.fillColor = (1, -1, -1)
コード例 #2
0
    def highlight_peripheral_stimulus_click(self, ns, eyetracker, mouse, gaze_debug):
        # Set which stimulus to highlight
        self.highlight.pos = self.images[self.attention].pos

        resp = None
        mouse.clickReset()

        highlight_on = False
        idx = 0
        attending_frames = 0
        self.win.callOnFlip(self.add_event, ns, eyetracker, 'ima2', 'attn start', self.code_table)
        while resp is None and idx < self.max_attending_frames:
            # Draw init frame of movie and two stimuli
            self.init_frame.draw()
            current_pos = self.images[self.attention].pos
            if idx % 5 == 0:
                new_pos = current_pos
                if current_pos[1] == 0 or current_pos[1] == -1:
                    new_pos[1] = 1
                else:
                    new_pos[1] = -1
                self.images[self.attention].setPos(new_pos)
                self.highlight.setPos(self.images[self.attention].pos)

            for image in self.images.values():
                image.draw()

            # Highlight stimulus
            if idx % 5 == 0:
                if highlight_on:
                    highlight_on = False
                else:
                    highlight_on = True
                if highlight_on:
                    self.highlight.draw()

            draw_eye_debug(gaze_debug, eyetracker, mouse)

            self.win.flip()
            idx += 1

            # Get gaze position from eyetracker or mouse
            gaze_position = (0, 0)
            if eyetracker is not None:
                gaze_position = eyetracker.getCurrentGazePosition()
                gaze_position = (0.5 * (gaze_position[0] + gaze_position[2]),
                                 0.5 * (gaze_position[1] + gaze_position[3]))
            elif mouse is not None:
                gaze_position = mouse.getPos()

            # Check if looking at right stimulus
            if fixation_within_tolerance(gaze_position, self.images[self.attention].pos,
                                         self.images[self.attention].size[0] / 2.0+3, self.win):
                if gaze_debug is not None:
                    gaze_debug.fillColor = (-1, -1, 1)
                attending_frames += 1
                if attending_frames == 1:
                    self.win.callOnFlip(self.add_event, ns, eyetracker, 'att1', 'attn stim', self.code_table)
            else:
                if gaze_debug is not None:
                    gaze_debug.fillColor = (1, -1, -1)
                attending_frames = 0

            buttons, times = mouse.getPressed(getTime=True)
            if buttons[0]:
                resp='l'
            elif buttons[2]:
                resp = 'r'

            # Check user input
            all_keys = event.getKeys()
            if len(all_keys):
                if all_keys[0].upper() in ['Q', 'ESCAPE'] or all_keys[0].upper() == 'P' or all_keys[0].upper() == 'E' or\
                                all_keys[0].upper() == 'G' or all_keys[0].upper() == 'D':
                    return all_keys[0].upper()
                event.clearEvents()

        if gaze_debug is not None:
            gaze_debug.fillColor = (1, -1, -1)

        if idx>=self.max_attending_frames and resp is None:
            return ''

        return None
コード例 #3
0
    def highlight_peripheral_stimulus_gaze(self, ns, eyetracker, mouse, gaze_debug):
        # Set which stimulus to highlight
        self.highlight.pos = self.images[self.attention].pos
        # Show initial frame of video until highlighted stimulus if fixated on or abort
        attending_frames = 0
        highlight_on = False
        idx = 0
        self.win.callOnFlip(self.add_event, ns, eyetracker, 'ima2', 'attn start', self.code_table)
        while attending_frames < self.min_attending_frames and idx < self.max_attending_frames:
            # Draw init frame of movie and two stimuli
            self.init_frame.draw()
            current_pos = self.images[self.attention].pos
            if idx % 5 == 0:
                new_pos = current_pos
                if current_pos[1] == 0 or current_pos[1] == -1:
                    new_pos[1] = 1
                else:
                    new_pos[1] = -1
                self.images[self.attention].setPos(new_pos)
                self.highlight.setPos(self.images[self.attention].pos)

            for image in self.images.values():
                image.draw()

            # Highlight stimulus
            if idx % 5 == 0:
                if highlight_on:
                    highlight_on = False
                else:
                    highlight_on = True
                if highlight_on:
                    self.highlight.draw()

            draw_eye_debug(gaze_debug, eyetracker, mouse)

            self.win.flip()
            idx += 1

            # Get gaze position from eyetracker or mouse
            gaze_position = (0, 0)
            if eyetracker is not None:
                gaze_position = eyetracker.getCurrentGazePosition()
                gaze_position = (0.5 * (gaze_position[0] + gaze_position[2]),
                                 0.5 * (gaze_position[1] + gaze_position[3]))
            elif mouse is not None:
                gaze_position = mouse.getPos()

            # Check if looking at right stimulus
            if fixation_within_tolerance(gaze_position, self.images[self.attention].pos,
                                         self.images[self.attention].size[0] / 2.0+3, self.win):
                if gaze_debug is not None:
                    gaze_debug.fillColor = (-1, -1, 1)
                attending_frames += 1
                if attending_frames == 1:
                    self.win.callOnFlip(self.add_event, ns, eyetracker, 'att1', 'attn stim', self.code_table)
            else:
                if gaze_debug is not None:
                    gaze_debug.fillColor = (1, -1, -1)
                attending_frames = 0
        if gaze_debug is not None:
            gaze_debug.fillColor = (1, -1, -1)

        return attending_frames