brownhci / WebGazer

WebGazer.js: Scalable Webcam EyeTracking Using User Interactions
https://webgazer.cs.brown.edu
Other
3.51k stars 528 forks source link

Precision percentage calculation #301

Open haejunejung opened 1 year ago

haejunejung commented 1 year ago

I wonder the calculate precision method, the function calculatePrecisionPercentages divide three parts. But distance alwasy larger than 0 I think... This function is included in www/js/precision_calculation.js

current code :

/*
 * Calculate percentage accuracy for each prediction based on distance of
 * the prediction point from the centre point (uses the window height as
 * lower threshold 0%)
 */
function calculatePrecisionPercentages(precisionPercentages, windowHeight, x50, y50, staringPointX, staringPointY) {
  for (x = 0; x < 50; x++) {
    // Calculate distance between each prediction and staring point
    var xDiff = staringPointX - x50[x];
    var yDiff = staringPointY - y50[x];
    var distance = Math.sqrt((xDiff * xDiff) + (yDiff * yDiff));

    // Calculate precision percentage
    var halfWindowHeight = windowHeight / 2;
    var precision = 0;
    if (distance <= halfWindowHeight && distance > -1) {
      precision = 100 - (distance / halfWindowHeight * 100);
    } else if (distance > halfWindowHeight) {
      precision = 0;
    } else if (distance > -1) {
      precision = 100;
    }

    // Store the precision
    precisionPercentages[x] = precision;
  }
}

so, I think below code is more correct. is it right ?

/*
 * Calculate percentage accuracy for each prediction based on distance of
 * the prediction point from the centre point (uses the window height as
 * lower threshold 0%)
 */
function calculatePrecisionPercentages(precisionPercentages, windowHeight, x50, y50, staringPointX, staringPointY) {
  for (x = 0; x < 50; x++) {
    // Calculate distance between each prediction and staring point
    var xDiff = staringPointX - x50[x];
    var yDiff = staringPointY - y50[x];
    var distance = Math.sqrt((xDiff * xDiff) + (yDiff * yDiff));

    // Calculate precision percentage
    var halfWindowHeight = windowHeight / 2;
    var precision = 0;
    if (distance <= halfWindowHeight) {
      precision = 100 - (distance / halfWindowHeight * 100);
    } else {
      precision = 0;
    } 

    // Store the precision
    precisionPercentages[x] = precision;
  }
}
jeffhuang commented 1 year ago

Thanks for reporting @haejunejung . I'll take a look shortly

jeffhuang commented 1 year ago

Yes @haejunejung you are right, it's a slightly simpler but identical bit of code. If you submit a PR and do a quick test to ensure that the result is identical, then I'll merge it. Thanks for finding this.