コード例 #1
0
 def computeEvents(self):
     inSaccade = False
     event = []
     for i in range(0, len(self.window)):
         if not inSaccade and self.marker[i] == 0:
             event.append(self.window[i])
             continue
         if inSaccade and self.marker[i] == 1:
             event.append(self.window[i])
             continue
         if inSaccade and self.marker[i] == 0:
             inSaccade = False
             if len(event) > 0:
                 e = ESaccade(len(event), event[0], event[-1])
                 self.events.append(e)
             event = [self.window[i]]
             continue
         if not inSaccade and self.marker[i] == 1:
             inSaccade = True
             if len(event) > 0:
                 c = self.centroid(event)
                 e = EFixation(c, len(event), event[0], event[-1])
                 self.events.append(e)
             event = [self.window[i]]
             continue
     # Whatever is left over
     if not inSaccade and len(event) > 0:
         c = self.centroid(event)
         e = EFixation(c, len(event), event[0], event[-1])
         self.events.append(e)
         return
     if inSaccade and len(event) > 0:
         e = ESaccade(len(event), event[0], event[-1])
         self.events.append(e)
         return
コード例 #2
0
ファイル: velocity.py プロジェクト: sarmadm/eventdetect
    def next(self):
        fixation = []

        for curr in self.input:
            v = curr.velocity

            if v < self.threshold:
                fixation.append(self.prev)
                self.prev = curr
            elif len(fixation) == 0 and v >= self.threshold:
                # We're probably in a saccade.  Quietly discard.
                self.prev = curr
                continue
            else:
                # We have reached the end of a saccade.

                c = self.centroid(fixation)
                prev = self.prev
                self.prev = curr
                return EFixation(c, len(fixation), fixation[0], prev)

        # We have broken out of the iteration, which means we've reached end of input
        # We have to deal with any remaining samples in 'fixation'

        if len(fixation) == 0:
            raise StopIteration
        else:
            c = self.centroid(fixation)
            return EFixation(c, len(fixation), fixation[0], fixation.pop())
コード例 #3
0
    def next(self):
        while True:
            # Fill the window with samples.
            self.fillWindow()

            if len(self.window) == 0:
                if len(self.event) == 0:
                    raise StopIteration
                else:
                    if self.inSaccade:
                        e = ESaccade(len(self.event), self.event[0],
                                     self.event[-1])
                        self.event = []
                        return e
                    else:
                        c = self.centroid(self.event)
                        e = EFixation(c, len(self.event), self.event[0],
                                      self.event[-1])
                        self.event = []
                        return e

            ac = self.windowAccel()
            vc = self.windowVelocity()

            if self.inSaccade:
                # Currently in a saccade. Have we dropped below the thresholds?
                if ac < self.accelThresh or vc < self.velThresh:
                    self.onsetCount += 1
                self.event.append(self.window[0])
            else:
                # Currently not in a saccade. Are we over the thresholds?
                if ac > self.accelThresh and vc > self.velThresh:
                    self.onsetCount += 1
                self.event.append(self.window[0])

            self.window = self.window[1:]

            if self.onsetCount >= self.onsetDelay:
                self.onsetCount = 0
                if self.inSaccade:
                    self.inSaccade = False
                    e = ESaccade(len(self.event), self.event[0],
                                 self.event[-1])
                    self.event = []
                    return e
                else:
                    self.inSaccade = True
                    c = self.centroid(self.event)
                    e = EFixation(c, len(self.event), self.event[0],
                                  self.event[-1])
                    self.event = []
                    return e
コード例 #4
0
ファイル: engbertkliegl.py プロジェクト: sarmadm/eventdetect
    def next(self):
        self.fillWindow()

        if len(self.window) <= 3:
            raise StopIteration

        v = self.windowVelocity()

        # print "Velocity: " + str(v.vx) + " / " + str(v.vy)

        mx = self.medianEstimatorX(v.vx)
        my = self.medianEstimatorY(v.vy)

        # print "Median: " + str(mx) + " / " + str(my)

        # sdx = (v.vx * v.vx) - (mx * mx)
        sdx = (v.vx * v.vx) - mx
        # sdy = (v.vy * v.vy) - (my * my)
        sdy = (v.vy * v.vy) - my

        # print "Std.Dev: " + str(sdx * self.threshold) + " / " + str(sdy * self.threshold)

        samp = self.window[2]

        r = None

        print "x"
        print v.vx
        print sdx
        print "y"
        print v.vy
        print sdy
        if v.vx >= sdx * self.threshold and v.vy >= sdy * self.threshold:
            self.inSacc = True

            if self.inFix and len(self.buf) > 1:
                self.inFix = False
                c = self.centroid(self.window)
                r = EFixation(c, len(self.buf), self.buf[0], self.buf[-1])
                self.buf = []

            self.buf.append(samp)
        else:
            self.inFix = True

            if self.inSacc:
                self.inSacc = False
                if len(self.buf) > 3:
                    r = ESaccade(len(self.buf), self.buf[0], self.buf[-1])
                self.buf = []

        self.window = self.window[1:]

        if r != None:
            return r
        else:
            return self.next()
コード例 #5
0
ファイル: aoi.py プロジェクト: sarmadm/eventdetect
    def next(self):

        samples = []
        currentArea = None

        for s in self.input:
            a = self.inArea(s)
            if a != None:
                if currentArea == None:
                    currentArea = a
                    samples.append(s)
                elif currentArea == a:
                    samples.append(s)
                else:
                    end = samples.pop()
                    p = self.centroid(samples)
                    length = len(samples)

                    if length < self.threshold:
                        samples = []
                        currentArea = None
                        continue
                    else:
                        return EFixation(p, length, samples[0], end)

            else:
                # Outside an area of interest
                currentArea = None
                if len(samples) > self.threshold:
                    end = samples.pop()
                    p = self.centroid(samples)
                    return EFixation(p, len(samples), samples[0], end)
                else:
                    samples = []
                    continue

        raise StopIteration
コード例 #6
0
    def next(self):
        # Fill the window with samples.
        self.fillWindow()

        if len(self.window) == 0:
            raise StopIteration

        d = self.dispersion()

        if d <= self.threshold:
            # We are in a fixation, but need to grow it
            # until we move above the threshold.

            start = self.window[0]

            while d <= self.threshold:
                try:
                    self.window.append(self.input.next())
                except StopIteration:
                    break

                d = self.dispersion()

                #print ("Window (%f): %s" % (d,str(self.window)))

            end = self.window.pop()
            p = self.centroid(self.window)

            length = len(self.window)
            self.window = []

            return EFixation(p, length, start, end)

        else:
            # Remove the first element
            self.window = self.window[1:]
            # Recurse.
            return self.next()
コード例 #7
0
ファイル: hmm.py プロジェクト: sarmadm/eventdetect
    def next(self):
        # Check if there is pre-computed output that can be returned.
        if len(self.output) > 0:
            return self.output.pop(0)

        # 'exhausted' is used to signal there is no more output,
        # and to prevent it from trying to recompute more.
        if self.exhausted:
            raise StopIteration

        # Calls to 'next' should only reach this point *once*.
        obs = []  # Observations
        inp = []  # Input buffer

        states = ('fix', 'sacc')

        for curr in self.input:
            v = self.intersampleVelocity(self.prev, curr)
            obs.append(v)
            inp.append(self.prev)
            self.prev = curr

        (pr, V) = self.viterbi(obs)

        inFix = True
        event = []

        for i in range(0, len(V)):
            if V[i] == 'fix' and inFix:
                event.append(inp[i])

            elif V[i] == 'sac' and not inFix:
                event.append(inp[i])

            elif V[i] == 'fix' and not inFix:
                e = ESaccade(len(event), event[0], event[len(event) - 1])
                self.output.append(e)
                event = [inp[i]]
                inFix = True

            elif V[i] == 'sac' and inFix:
                c = self.centroid(event)
                e = EFixation(c, len(event), event[0], event[len(event) - 1])
                self.output.append(e)
                event = [inp[i]]
                inFix = False

        # Remaining samples need to be parsed out into an event.
        if len(event) > 0:
            if not inFix:
                e = ESaccade(len(event), event[0], event[len(event) - 1])
                self.output.append(e)

            else:
                c = self.centroid(event)
                e = EFixation(c, len(event), event[0], event[len(event) - 1])
                self.output.append(e)

        self.exhausted = True

        if len(self.output) > 0:
            return self.output.pop(0)
        else:
            raise StopIteration