3d_accuracy.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. name = 'Pieter'
  20. for root, dir, files in os.walk(os.path.join(os.getcwd(), f'DataCSV\\{name}\\')):
  21. for file in files:
  22. if file.endswith(".csv"):
  23. path = os.path.join(root, file)
  24. with open(path, newline='') as csvfile:
  25. reader = csv.reader(csvfile)
  26. header = next(reader)
  27. for row in reader:
  28. for i in range(18):
  29. demo = vector_string_to_float(row[i])
  30. body = vector_string_to_float(row[i+18])
  31. distance = np.linalg.norm(np.subtract(demo, body))
  32. sum_distance_joints[i] += distance
  33. counter += 1
  34. x = [header[i][5:] for i in range(18)]
  35. y = [sum_distance_joints[i] / counter for i in range(18)]
  36. if "FirstPerson" in file:
  37. ax[0].scatter(x, y)
  38. elif "ThirdPersonPerspective_" in file:
  39. ax[1].scatter(x, y)
  40. elif "MultipleViews" in file:
  41. ax[2].scatter(x, y)
  42. # Reset values
  43. sum_distance_joints = np.zeros(18)
  44. counter = 0
  45. fig.autofmt_xdate(rotation=45)
  46. ax[0].set_title('First Person')
  47. ax[1].set_title('Third Person')
  48. ax[2].set_title('Third Person Multiple View')
  49. # plt.legend(files).set_draggable(True)
  50. plt.show()
  51. # ----------------------------------------
  52. sum_distance_joints = np.zeros(18)
  53. counter = 0
  54. path = os.path.join(os.getcwd(), 'DataCSV\\Gary\\FirstPersonPerspective_OneArm_Backward_ColorFeedback_Fast.csv')
  55. with open(path, newline='') as csvfile:
  56. reader = csv.reader(csvfile)
  57. header = next(reader)
  58. for row in reader:
  59. for i in range(18):
  60. demo = vector_string_to_float(row[i])
  61. body = vector_string_to_float(row[i+18])
  62. distance = np.linalg.norm(np.subtract(demo, body))
  63. sum_distance_joints[i] += distance
  64. counter += 1
  65. for i in range(sum_distance_joints.size):
  66. print("3d accuracy ", header[i][5:], ": ", sum_distance_joints[i] / counter)