TrackingQuality.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. % TrackingQuality.m
  2. %
  3. % This function gets as input the position of a target and a time interval
  4. % during which the target was fixated. It then returns the divergence of gaze
  5. % from the target in degrees.
  6. %
  7. % NOTE: Be careful to provide a time interval in which gaze is not noisy
  8. %
  9. % input:
  10. % arffFile - path to ARFF file
  11. % targetStartTime - target diplay starting time in us
  12. % targetEndTime - target diplay starting time in us
  13. % targetPos - [x, y] equirectangular position
  14. %
  15. % output:
  16. % divergence - divergence from target in degrees
  17. function [divergence] = TrackingQuality(arffFile, targetStartTime, targetEndTime, targetPos)
  18. if (targetStartTime < 0 || targetEndTime < 0)
  19. divergence = -1;
  20. return;
  21. end
  22. c_timeName = 'time';
  23. c_xName = 'x';
  24. c_yName = 'y';
  25. c_confName = 'confidence';
  26. c_confThreshold = 0.8;
  27. [data, metadata, attributes, relation, comments] = LoadArff(arffFile);
  28. timeInd = GetAttPositionArff(attributes, c_timeName);
  29. xInd = GetAttPositionArff(attributes, c_xName);
  30. yInd = GetAttPositionArff(attributes, c_yName);
  31. confInd = GetAttPositionArff(attributes, c_confName);
  32. % convert target position to cartesian
  33. [horTargetRads, verTargetRads] = EquirectToSpherical(targetPos(1), targetPos(2), metadata.width_px, metadata.height_px);
  34. targetVec = SphericalToCart(horTargetRads, verTargetRads);
  35. % find start/end ime position
  36. indStart = find(data(:,timeInd) > targetStartTime);
  37. assert(~isempty(indStart), 'Could not find provided start time');
  38. indStart = indStart(1);
  39. indEnd = find(data(:,timeInd) > targetEndTime);
  40. assert(~isempty(indEnd), 'Could not find provided end time');
  41. indEnd = indEnd(1);
  42. % find mean gaze vector
  43. gazeVecMean = zeros(3,1);
  44. for ind=indStart:indEnd
  45. if (data(ind, confInd) < c_confThreshold)
  46. continue;
  47. end
  48. % convert gaze to reference vector
  49. [horGazeRads, verGazeRads] = EquirectToSpherical(data(ind, xInd), data(ind, yInd), metadata.width_px, metadata.height_px);
  50. gazeVec = SphericalToCart(horGazeRads, verGazeRads);
  51. gazeVecMean = gazeVecMean + gazeVec;
  52. end
  53. vecNum = indEnd - indStart + 1;
  54. gazeVecMean = gazeVecMean / norm(gazeVecMean);
  55. divergence = GetDispersion(targetVec, gazeVecMean');
  56. end