LoadCoordAndConf.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. % function LoadCoordAndConf:
  2. % This function Loads data from the given input file and returns a data matrix.
  3. %
  4. % input:
  5. % inputFile - file that holds data to load
  6. % output:
  7. % data - data matrix holding timestamp and coordinates nx3 where confidence > 0.1
  8. % pixelX - width in pixels
  9. % pixelY - height in pixels
  10. % width - width of monitor in meters
  11. % height - height of monitor in meters
  12. % distance - distance from monitor in meters
  13. % conf - confince of return data. In range [0,1]
  14. function [data, pixelX, pixelY, width, height, distance, conf] = LoadCoordAndConf(inputfile)
  15. pixelX = -1;
  16. pixelY = -1;
  17. width = -1;
  18. height = -1;
  19. distance = -1;
  20. inputfileClean = strtrim(inputfile);
  21. if (exist(inputfileClean) == 0)
  22. error('File does not exist.');
  23. endif
  24. % check if input file has header
  25. fid = fopen(inputfileClean);
  26. numOfHeaderLines = 0;
  27. for i=1:20
  28. l = fgetl(fid);
  29. if (!ischar(l)) % detect end of file
  30. break;
  31. end
  32. pos = strfind(l, 'geometry');
  33. if (size(pos,1) > 0)
  34. numOfHeaderLines = i;
  35. end
  36. end
  37. fclose(fid);
  38. if (numOfHeaderLines > 0)
  39. data = importdata(inputfileClean, ' ', numOfHeaderLines);
  40. matrix = data.data;
  41. s = strsplit(data.textdata{numOfHeaderLines}, ' ');
  42. distance = str2num(s{1,3});
  43. width = str2num(s{1,5});
  44. height = str2num(s{1,7});
  45. s = strsplit(data.textdata{numOfHeaderLines-1}, ' ');
  46. pixelX = str2num(s{1,2});
  47. pixelY = str2num(s{1,3});
  48. end
  49. data = importdata(inputfileClean, ' ', numOfHeaderLines);
  50. [rows, columns] = size(data.data);
  51. if (columns ~= 4 & columns ~= 13)
  52. error("Wrong type of input file.");
  53. end
  54. conf = data.data(:,4);
  55. data = data.data(:,1:3);
  56. end