plot_depth_error.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import numpy as np
5 import csv
6 import sys
7 import matplotlib.pyplot as plt
8 from sklearn import linear_model, datasets
9 
10 if __name__ == "__main__":
11  csv_files = sys.argv[1:]
12  xs = []
13  ys = []
14  es = []
15  for csv_file in csv_files:
16  with open(csv_file) as f:
17  reader = csv.reader(f)
18  (true_depths, observed_depths) = zip(*[(float(row[0]), float(row[1])) for row in reader])
19  errs = [a - b for (a, b) in zip(true_depths, observed_depths)]
20  true_mean = np.mean(true_depths)
21  observed_mean = np.mean(observed_depths)
22  err_mean = np.mean(errs, axis=0)
23  err_stddev = np.std(errs, axis=0)
24  xs.append(true_mean)
25  ys.append(observed_mean)
26  #es.append(err_mean)
27  es.append(err_stddev)
28  #plt.errorbar(xs, ys, es, linestyle='None', marker='^')
29  plt.scatter(xs, es)
30  model_ransac = linear_model.RANSACRegressor(linear_model.LinearRegression(), min_samples=2,
31  residual_threshold=0.1)
32  X = np.array(xs).reshape((len(xs), 1))
33  Y = np.array(es)
34  model_ransac.fit(X, Y)
35  line_y_ransac = model_ransac.predict(X)
36  plt.plot(X, line_y_ransac, "r--",
37  label="{0} x + {1}".format(model_ransac.estimator_.coef_[0][0],
38  model_ransac.estimator_.intercept_[0]))
39  print("{0} x + {1}".format(model_ransac.estimator_.coef_[0][0],
40  model_ransac.estimator_.intercept_[0]))
41  plt.grid()
42  plt.xlabel("Distance [m]")
43  plt.ylabel("Standard Deviation [m]")
44  # plt.legend(prop={'size': '8'})
45  plt.show()


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Mon May 3 2021 03:03:47