3d_accuracy.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. ax[0].scatter(x, y)
  37. if "ThirdPersonPerspective_" in file:
  38. ax[1].scatter(x, y)
  39. elif "MultipleViews" in file:
  40. ax[2].scatter(x, y)
  41. # Reset values
  42. sum_distance_joints = np.zeros(18)
  43. counter = 0
  44. fig.autofmt_xdate(rotation=45)
  45. ax[0].set_title('First Person')
  46. ax[1].set_title('Third Person')
  47. ax[2].set_title('Third Person Multiple View')
  48. # plt.legend(files).set_draggable(True)
  49. plt.show()
  50. # ----------------------------------------
  51. sum_distance_joints = np.zeros(18)
  52. counter = 0
  53. path = os.path.join(os.getcwd(), 'DataCSV\\Gary\\FirstPersonPerspective_OneArm_Backward_ColorFeedback_Fast.csv')
  54. with open(path, newline='') as csvfile:
  55. reader = csv.reader(csvfile)
  56. header = next(reader)
  57. for row in reader:
  58. for i in range(18):
  59. demo = vector_string_to_float(row[i])
  60. body = vector_string_to_float(row[i+18])
  61. distance = np.linalg.norm(np.subtract(demo, body))
  62. sum_distance_joints[i] += distance
  63. counter += 1
  64. for i in range(sum_distance_joints.size):
  65. print("3d accuracy ", header[i][5:], ": ", sum_distance_joints[i] / counter)