def __init__(self, display, logfile=LOGFILE, eventdetection=EVENTDETECTION, \ saccade_velocity_threshold=35, saccade_acceleration_threshold=9500, \ **args): """Initializes the EyeTribeTracker object arguments display -- a pygaze.display.Display instance keyword arguments logfile -- logfile name (string value); note that this is the name for the eye data log file (default = LOGFILE) """ # try to copy docstrings (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseEyeTracker, EyeTribeTracker) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # object properties self.disp = display self.screen = Screen() self.dispsize = DISPSIZE # display size in pixels self.screensize = SCREENSIZE # display size in cm self.kb = Keyboard(keylist=['space', 'escape', 'q'], timeout=1) self.errorbeep = Sound(osc='saw',freq=100, length=100) # output file properties self.outputfile = logfile # eye tracker properties self.connected = False self.recording = False self.errdist = 2 # degrees; maximal error for drift correction self.pxerrdist = 30 # initial error in pixels self.maxtries = 100 # number of samples obtained before giving up (for obtaining accuracy and tracker distance information, as well as starting or stopping recording) self.prevsample = (-1,-1) self.prevps = -1 # event detection properties self.fixtresh = 1.5 # degrees; maximal distance from fixation start (if gaze wanders beyond this, fixation has stopped) self.fixtimetresh = 100 # milliseconds; amount of time gaze has to linger within self.fixtresh to be marked as a fixation self.spdtresh = saccade_velocity_threshold # degrees per second; saccade velocity threshold self.accthresh = saccade_acceleration_threshold # degrees per second**2; saccade acceleration threshold self.eventdetection = eventdetection self.set_detection_type(self.eventdetection) self.weightdist = 10 # weighted distance, used for determining whether a movement is due to measurement error (1 is ok, higher is more conservative and will result in only larger saccades to be detected) # connect to the tracker self.eyetribe = EyeTribe(logfilename=logfile) # get info on the sample rate self.samplerate = self.eyetribe._samplefreq self.sampletime = 1000.0 * self.eyetribe._intsampletime # initiation report self.log("pygaze initiation report start") self.log("display resolution: %sx%s" % (self.dispsize[0],self.dispsize[1])) self.log("display size in cm: %sx%s" % (self.screensize[0],self.screensize[1])) self.log("samplerate: %.2f Hz" % self.samplerate) self.log("sampletime: %.2f ms" % self.sampletime) self.log("fixation threshold: %s degrees" % self.fixtresh) self.log("speed threshold: %s degrees/second" % self.spdtresh) self.log("acceleration threshold: %s degrees/second**2" % self.accthresh) self.log("pygaze initiation report end")
) # INIT elif "Initialize EyeTribe" in message: # get the file name try: # (message: "Initialize EyeTribe; logfilename=%s") logfilename = message[message.find('logfilename=') + 12:] except: print( "WARNING in Initialize EyeTribe: invalid logfilename, using default" ) logfilename = None # initialize the EyeTribe try: tracker = EyeTribe(logfilename=logfilename) conn.send('success') print("Initialize EyeTribe: success!") except: print( "ERROR in Initialize EyeTribe: could not initialize new EyeTribe object." ) conn.send( "ERROR in Initialize EyeTribe: could not initialize new EyeTribe object." ) # CALIBRATE elif message == "Calibration start": # check if there is an initialized tracker yet if tracker == None: print('ERROR in Calibration start: tracker was not initialized.')
# screen stuff RESOLUTION = (1280, 1024) BGC = (0, 0, 0) # files and paths DIR = os.path.dirname(os.path.abspath(__file__)) LOGFILE = os.path.join(DIR, 'example_data.txt') IMGDIR = os.path.join(DIR, 'imgs') IMGNAMES = os.listdir(IMGDIR) # # # # # # PREPARE # start communications with the EyeTribe tracker tracker = EyeTribe(logfilename=LOGFILE) # initialize PyGame pygame.init() # create a new display disp = pygame.display.set_mode(RESOLUTION, pygame.FULLSCREEN) # compile a list of images images = {} for filename in IMGNAMES: # check if the extension is a JPEG image if os.path.splitext(filename)[1] == '.jpg': # load the image, and add to the image dict images[filename] = pygame.image.load(os.path.join(IMGDIR, filename))