Ejemplo n.º 1
0
    def __init__(self):
        super().__init__()

        self.detector = DwellSelect(float(settings.gazeValue('dwellDuration')),
                                    float(settings.gazeValue('dwellRange')))
        self.gazePosition = [-99, -99]
        self.eyePositions = [[-99, -99], [-99, -99]]
        self.staleTimerStart = None
        self.attentionStalePeriod = float(
            settings.gazeValue('attentionPeriod'))
        self.lastFixation = None
        self.sawEyesLastTime = None

        self.timer = QtCore.QTimer()
        self.timer.setSingleShot(False)
        self.timer.timeout.connect(self._poll)

        self.pointStarted = False

        self.tracker = EyeTribe()
        self.server = EyeTribeServer()
        self.server.ready.connect(self.connectToServer)
        self.server.error.connect(self.error.emit)
        #		self.tracker.pullmode()
        self.server.start()
        self.isReady = self.server.isReady
Ejemplo n.º 2
0
 def connect():
     if GazeInterface.__tracker is not None:
         GazeInterface.__tracker.pushmode()
         return GazeInterface.__tracker
     tracker = EyeTribe(host="localhost", port=6555)
     tracker.connect()
     tracker.pushmode()
     GazeInterface.__tracker = tracker
     return tracker
Ejemplo n.º 3
0
    OpenPrograms()

    def handle_data():
        """Function called to handle EyeX SampleGaze and SampleFixation events"""
        global eyetrack_on
        if eyetrack_on:
            startRecording()
            print("start rec")
        else:
            stopRecording()
            print("end record")

    # eye_api = EyeXInterface() # Thread one
    # eye_api_f = EyeXInterface(fixation=True)
    # eye_api.on_event += [handle_data]
    tracker = EyeTribe()
    tracker.connect()
    frameq = tracker._frameq

    def startRecording():
        frameq.queue.clear()
        tracker.pushmode()

    def stopRecording():
        tracker.pullmode()
        while True:
            try:
                frame = frameq.get(False)
            except Queue.Empty:
                break
            alldata.put(frame)
Ejemplo n.º 4
0
from peyetribe import EyeTribe
import time

tracker = EyeTribe(host="localhost", port=6555)
tracker.connect()
n = tracker.next()

print(
    "eT;dT;aT;Fix;State;Rwx;Rwy;Avx;Avy;LRwx;LRwy;LAvx;LAvy;LPSz;LCx;LCy;RRwx;RRwy;RAvx;RAvy;RPSz;RCx;RCy"
)

tracker.pushmode()
count = 0
while count < 500:
    n = tracker.next()
    print(n.righteye.avg)
    # print(n.lefteye)
    count += 1

tracker.pullmode()

tracker.close()
Ejemplo n.º 5
0
class _GazeDevice(QtCore.QObject):
    ready = QtCore.Signal()
    error = QtCore.Signal(object)

    eyesAppeared = QtCore.Signal(object)
    eyesDisappeared = QtCore.Signal()
    moved = QtCore.Signal(object)
    fixated = QtCore.Signal(object)

    def __init__(self):
        super().__init__()

        self.detector = DwellSelect(float(settings.gazeValue('dwellDuration')),
                                    float(settings.gazeValue('dwellRange')))
        self.gazePosition = [-99, -99]
        self.eyePositions = [[-99, -99], [-99, -99]]
        self.staleTimerStart = None
        self.attentionStalePeriod = float(
            settings.gazeValue('attentionPeriod'))
        self.lastFixation = None
        self.sawEyesLastTime = None

        self.timer = QtCore.QTimer()
        self.timer.setSingleShot(False)
        self.timer.timeout.connect(self._poll)

        self.pointStarted = False

        self.tracker = EyeTribe()
        self.server = EyeTribeServer()
        self.server.ready.connect(self.connectToServer)
        self.server.error.connect(self.error.emit)
        #		self.tracker.pullmode()
        self.server.start()
        self.isReady = self.server.isReady

    def connectToServer(self):
        logging.debug("Eyetribe server ready - connecting tracker!")
        self.tracker.connect()
        self.ready.emit()

    def getDwellDuration(self):
        return self.detector.minimumDelay

    def getDwellRange(self):
        return self.detector.range

    def setDwellDuration(self, duration):
        self.detector.setDuration(duration)
        settings.setGazeValue('dwellDuration', duration)

    def setDwellRange(self, rangeInPixels):
        self.detector.setRange(rangeInPixels)
        settings.setGazeValue('dwellRange', rangeInPixels)

    def setAttentionStalePeriod(self, duration):
        self.attentionStalePeriod = duration
        settings.setGazeValue('attentionPeriod', duration)

    def getAttentionStalePeriod(self):
        return self.attentionStalePeriod

    def isRunning(self):
        return self.timer.isActive()

    def startPolling(self):
        if self.server.isReady():
            self._startPolling()
        else:
            self.server.ready.connect(self._startPolling)
            self.server.start()

    def _startPolling(self):
        if not self.isRunning():
            self.timer.start(1000 / 30)

    def _poll(self):
        try:
            gazeFrame = self.tracker.next()
            if (gazeFrame.state & STATES['STATE_TRACKING_GAZE']) != 0:
                self.eyePositions = [[
                    gazeFrame.lefteye.pcenter.x, gazeFrame.lefteye.pcenter.y
                ], [
                    gazeFrame.righteye.pcenter.x, gazeFrame.righteye.pcenter.y
                ]]

                if True:
                    self.gazePosition = [gazeFrame.avg.x, gazeFrame.avg.y]
                    self.moved.emit(self.gazePosition)
                    if not self.sawEyesLastTime or self.sawEyesLastTime is None:
                        self.eyesAppeared.emit(self.gazePosition)
                    self.sawEyesLastTime = True

                    currentTime = time.time()
                    wasInsideDwell = self.detector.inDwell
                    self.detector.addPoint(
                        Point(gazeFrame.avg.x, gazeFrame.avg.y, 0, currentTime,
                              gazeFrame.avg))
                    if self.detector.selection != None:
                        self.lastFixation = self.detector.clearSelection()
                        self.fixated.emit(self.lastFixation)

                    if wasInsideDwell and not self.detector.inDwell:
                        self.staleTimerStart = time.time()
                    elif self.staleTimerStart is not None and (
                            time.time() -
                            self.staleTimerStart) > self.attentionStalePeriod:
                        self.staleTimerStart = None
                        self.fixationInvalidated.emit(self.lastFixation)

            else:
                raise (Exception('not tracking: %d' % gazeFrame.state))
        except Exception as exc:
            if self.sawEyesLastTime:
                self.eyesDisappeared.emit()
            self.sawEyesLastTime = False

    def getLastFixation(self):
        return self.lastFixation

    def getGaze(self):
        return self.gazePosition

    def getAttentiveGaze(self, clear=False):
        gaze = self.gazePosition
        if self.staleTimerStart is not None:
            if self.lastFixation is not None and (
                    time.time() -
                    self.staleTimerStart) < self.attentionStalePeriod:
                gaze = [self.lastFixation.x, self.lastFixation.y]

        if clear:
            self.lastFixation = None

        return gaze

    def clearLastFixation(self):
        self.lastFixation = None
        self.staleTimeStart = None

    def reset(self):
        self.clearLastFixation()
        self.detector.reset()

    def getEyePositions(self):
        return self.eyePositions

    def exit(self):
        self.timer.stop()

    def redoCalibration(self, points):
        self.points = points
        return self.points[-1]

    def cancelCalibration(self):
        if self.tracker.is_calibrating():
            logging.debug("sending abort")
            self.tracker.calibration_abort()

    def isCalibrating(self):
        return self.tracker.is_calibrating()

    def startCalibration(self, xPoints, yPoints, screenWidth, screenHeight):
        self.points = []
        margin = 100
        for y in range(yPoints):
            for x in range(xPoints):
                self.points.append([
                    x * ((screenWidth - margin * 2) / (xPoints - 1)) + margin,
                    y * ((screenHeight - margin * 2) / (yPoints - 1)) + margin
                ])
        random.shuffle(self.points)
        self.tracker.calibration_start(xPoints * yPoints)

        return self.points[-1]

    def beginPointCapture(self):
        point = self.points.pop()
        try:
            self.tracker.calibration_point_start(point[0], point[1])
            self.pointStarted = True
        except Exception as exc:
            logging.error(exc)

    def endPointCapture(self):
        if self.pointStarted:
            self.tracker.calibration_point_end()

        self.pointStarted = False
        if len(self.points) > 0:
            return self.points[-1]

    def getCalibration(self):
        return self.tracker.latest_calibration_result()

    def stop(self):
        self.timer.stop()
        try:
            self.tracker.close()
        except:
            pass
        if self.server.isRunning():
            self.server.stop()
Ejemplo n.º 6
0
            ## load('block3.avi') ##
            t1 = time.time()
            if time.time() - t1 > 5:
                starttime.append(n.time)

    if block == 4: ## elliptical
        t0 = time.time()
        showFixation('o', 25, '0.5')
        if press.event() == 'enter' or time.time() - t0 > 15:
            showFixation('+', 25, 'b')
            ## load('block4.avi') ##
            t1 = time.time()
            if time.time() - t1 > 5:
                starttime.append(n.time)

tracker = EyeTribe() #create object tracker for connection
tracker.connect()
n = tracker.next()

numberoftrials = 6
fps = 60
spf = 1. / fps #Seconds Per Frame
targetFrequency = 0.4 #Hz

#initialize empty arrays <-- this is process i found necessary to read in the data from the eye tracker heart beat
timestamp = [] #time in msec
lefteye = [] #left in rawx, rawy, avgx, avgy
righteye = [] #right eye in rawx, rawy, avgx, avgy
starttime = [] #timestamp (msec) for sync beginnning

tracker.pushmode() #begin pushing
Ejemplo n.º 7
0



if __name__ == "__main__":

    from peyetribe import EyeTribe
    import time

    tracker = EyeTribe()
    tracker.connect()

    frameq = tracker._frameq

    print frameq.empty()

    print("eT;dT;aT;Fix;State;Rwx;Rwy;Avx;Avy;LRwx;LRwy;LAvx;LAvy;LPSz;LCx;LCy;RRwx;RRwy;RAvx;RAvy;RPSz;RCx;RCy")

    tracker.pushmode()
    count = 0
    time.sleep(2)
    tracker.pullmode()
    print frameq.qsize()
    while not frameq.empty():
        n = frameq.get(True)
        #print n

    tracker.pushmode()
    time.sleep(3)
    print frameq.qsize()
Ejemplo n.º 8
0
from peyetribe import EyeTribe
import time
import pickle
import json
from pythonosc import osc_message_builder
from pythonosc import udp_client
import argparse

tracker = EyeTribe()
tracker._hbinterval = 5
tracker.connect()
n = tracker.next()

parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1",help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=12345,help="The port the OSC server is listening on")
args = parser.parse_args()

client = udp_client.UDPClient(args.ip, args.port)


print("eT;dT;aT;Fix;State;Rwx;Rwy;Avx;Avy;LRwx;LRwy;LAvx;LAvy;LPSz;LCx;LCy;RRwx;RRwy;RAvx;RAvy;RPSz;RCx;RCy")
frame = []
totalData = []
attributes = "eT;dT;aT;Fix;State;Rwx;Rwy;Avx;Avy;LRwx;LRwy;LAvx;LAvy;LPSz;LCx;LCy;RRwx;RRwy;RAvx;RAvy;RPSz;RCx;RCy".split(';')

tracker.pushmode()
count = 0
while True: #count < 60:
    n = tracker.next()
    print(n)