3d_accuracy.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import csv
  2. import os
  3. import numpy as np
  4. from matplotlib import pyplot as plt
  5. sum_distance_joints = np.zeros(18)
  6. counter = 0
  7. def vector_string_to_float(vector):
  8. """
  9. Convert vector string to float
  10. Parameters:
  11. vector: vector still in string
  12. Returns:
  13. vector: vector with type float
  14. """
  15. vector = vector.split(';')
  16. vector = list(map(float, vector))
  17. return vector
  18. fig, ax = plt.subplots(1, 3, sharey=True)
  19. for root, dir, files in os.walk(os.path.join(os.getcwd(), 'DataCSV\\Gary\\')):
  20. for file in files:
  21. if file.endswith(".csv"):
  22. path = os.path.join(root, file)
  23. with open(path, newline='') as csvfile:
  24. reader = csv.reader(csvfile)
  25. header = next(reader)
  26. for row in reader:
  27. for i in range(18):
  28. demo = vector_string_to_float(row[i])
  29. body = vector_string_to_float(row[i+18])
  30. distance = np.linalg.norm(np.subtract(demo, body))
  31. sum_distance_joints[i] += distance
  32. counter += 1
  33. x = [header[i][5:] for i in range(18)]
  34. y = [sum_distance_joints[i] / counter for i in range(18)]
  35. if "FirstPerson" in file:
  36. sc = ax[0].scatter(x, y)
  37. # for i in range(len(x)):
  38. # ax[0].annotate(file[22:], xy=(i,y[i]))
  39. if "ThirdPersonPerspective_" in file:
  40. ax[1].scatter(x, y)
  41. elif "MultipleViews" in file:
  42. ax[2].scatter(x, y)
  43. fig.autofmt_xdate(rotation=45)
  44. ax[0].set_title('First Person')
  45. ax[1].set_title('Third Person')
  46. ax[2].set_title('Third Person Multiple View')
  47. # plt.legend(files).set_draggable(True)
  48. plt.show()
  49. path = os.path.join(os.getcwd(
  50. ), 'DataCSV\\name\\FirstPersonPerspective_OneArm_Forward_HapticFeedback_Slow.csv')
  51. with open(path, newline='') as csvfile:
  52. reader = csv.reader(csvfile)
  53. header = next(reader)
  54. for row in reader:
  55. for i in range(18):
  56. demo = vector_string_to_float(row[i])
  57. body = vector_string_to_float(row[i+18])
  58. distance = np.linalg.norm(np.subtract(demo, body))
  59. sum_distance_joints[i] += distance
  60. counter += 1
  61. for i in range(sum_distance_joints.size):
  62. print("3d accuracy ", header[i][5:], ": ",
  63. sum_distance_joints[i] / counter)