esdalmaijer / PyGaze

an open-source, cross-platform toolbox for minimal-effort programming of eye tracking experiments
www.pygaze.org
GNU General Public License v3.0
671 stars 211 forks source link

tobii data output calculates average gaze position incorrectly #55

Closed onesandzeroes closed 8 years ago

onesandzeroes commented 8 years ago

I'm helping out someone who's trying to run a simple eyetracking experiment using Pygaze with a Tobii TX300. They were a bit confused by the data their experiment produced, since the GazePointX and GazePointY values recorded were often outside the 0.0-1.0 range that the tracker should produce (not sure if this is common across all makes of tracker but Tobii records coordinates in a 0.0-1.0 range where (0.0, 0.0) represents the top-left and (1.0, 1.0) the bottom right).

Examining the libtobii source code, it seems that someone already noticed an issue with how these values were calculated and recorded it as a comment, but wasn't sure enough to apply the fix. Currently when there are valid samples from both eyes, GazePointX and GazePointY are calculated as:

# if we have both samples, use both samples
else:
    # shouldn't these additions be divided by 2?
    ave = (g.LeftGazePoint2D.x+g.RightGazePoint2D.x,
           g.LeftGazePoint2D.y+g.RightGazePoint2D.y)

but I agree with the comment that they should instead be:

# if we have both samples, use both samples
else:
    ave = ((g.LeftGazePoint2D.x + g.RightGazePoint2D.x) / 2.0,
           (g.LeftGazePoint2D.y + g.RightGazePoint2D.y) / 2.0)

this makes the data from the current experiment look much more sensible. I've included a very small sample of (uncorrected) data, note the difference between samples with both eyes valid and the initial samples with only one eye valid

TimeStamp  GazePointXLeft      GazePointYLeft ValidityLeft    GazePointXRight     GazePointYRight ValidityRight GazePointX GazePointY 
      108.3              -1                -1          4           911.6937             613.3255             0     0.4748     0.5679
      116.6              -1                -1          4           942.5177              568.297             0     0.4909     0.5262
        125        990.9151          520.1005          0           922.5432             520.3522             0     0.9966     0.9634
      133.4        968.9799          526.1385          0           934.8946             459.9867             0     0.9916     0.9131
      141.7          977.76          479.3348          0           942.9805             418.0528             0     1.0004     0.8309
      149.9        999.6558          418.1523          0           960.1643             380.9476             0     1.0207     0.7399
      158.3       1001.4722          403.9405          0           946.8408             408.0108             0     1.0147     0.7518
      166.7          996.08           414.319          0           951.7222             412.8808             0     1.0145     0.7659
esdalmaijer commented 8 years ago

You're absolutely right, thanks for spotting that!