draw-graph-from-rosbag.py
Go to the documentation of this file.
1 import rosbag
2 import argparse
3 import matplotlib.pyplot, numpy, mpl_toolkits.mplot3d.axes3d
4 from BayesianCurveFitting import *
5 from math import *
6 
7 def parse_args():
8  parser = argparse.ArgumentParser(description='plot data from rosbag')
9  parser.add_argument('inbag', type=str, help='input bag file', metavar='bagfile')
10  parser.add_argument('-t', type=int, help='1 or 2', metavar='graph type', choices=[1, 2], default=2)
11  parser.add_argument('-u', type=int, help='step in u', default=80)
12  parser.add_argument('-v', type=int, help='step in v', default=80)
13  parser.add_argument('-d', type=float, help='step in depth', default=0.1)
14  parser.add_argument('--max_depth', type=float, help='maximum depth', default=1.5)
15  parser.add_argument('-D', type=int, help='D degree polynomial', default=2)
16  parser.add_argument('-a', type=float, help='ALPHA', default=0.005)
17  parser.add_argument('-b', type=float, help='BETA', default=11.1)
18  return parser.parse_args()
19 
20 def setup_data_list(v_num, u_num):
21  data_list = []
22  for v_i in range(0, v_num):
23  data_list.append([])
24  for u_i in range(0, u_num):
25  data_list[v_i].append([])
26  return data_list
27 
28 def process(args):
29  width = 640
30  height = 480
31  step_u = args.u
32  step_v = args.v
33  data_list = setup_data_list(height/step_v, width/step_u)
34  f, (axes_array) = matplotlib.pyplot.subplots(len(data_list), len(data_list[0]), sharex='col', sharey='row')
35  with rosbag.Bag(args.inbag) as b:
36  for topic, msg, t in b.read_messages():
37  u_i = msg.u / step_u
38  v_i = msg.v / step_v
39  if abs((msg.observed_depth - msg.true_depth) * 1000) < 1000: # for outlier
40  data_list[v_i][u_i].append([msg.observed_depth, # x, [m]
41  (msg.observed_depth - msg.true_depth) * 1000]) # y, [mm]
42  for x in range(0, len(axes_array[0])):
43  for y in range(0, len(axes_array)):
44  xlist = [tmp[0] for tmp in data_list[y][x]]
45  ylist = [tmp[1] for tmp in data_list[y][x]]
46  bcf = BayesianCurveFitting(args.D, args.a, args.b, xlist, ylist).main()
47  axes_array[y][x].plot(xlist, ylist, '.')
48  axes_array[y][x].plot(bcf[0], bcf[1], 'r-')
49  axes_array[y][x].plot(bcf[0], bcf[2], 'g--')
50  axes_array[y][x].plot(bcf[0], bcf[3], 'g--')
51  axes_array[y][x].set_title('u : %d~%d, v : %d~%d' % (x*step_u, (x+1)*step_u, y*step_v, (y+1)*step_v))
52  matplotlib.pyplot.show()
53 
54 
55 def setup_data_list2(d_num):
56  data_list = []
57  for d_i in range(d_num):
58  data_list.append([])
59  return data_list
60 
61 def process2(args):
62  max_depth = args.max_depth
63  step_d = args.d
64  data_list = setup_data_list2(int(max_depth / step_d))
65  fig = matplotlib.pyplot.figure(figsize=matplotlib.pyplot.figaspect(0.5))
66  axes_array = []
67  for i in range(len(data_list)):
68  axes_array.append(fig.add_subplot(int(sqrt(len(data_list))) + 1, int(sqrt(len(data_list))) + 1, i+1, projection='3d'))
69  with rosbag.Bag(args.inbag) as b:
70  for topic, msg, t in b.read_messages():
71  if msg.true_depth < step_d * len(data_list):
72  d_i = int(msg.true_depth / step_d)
73  if abs((msg.observed_depth - msg.true_depth) * 1000) < 1000: # for outlier
74  data_list[d_i].append([msg.u, msg.v,
75  (msg.observed_depth - msg.true_depth) * 1000])
76  for d in range(len(axes_array)):
77  xlist = numpy.array([tmp[0] for tmp in data_list[d]])
78  ylist = numpy.array([tmp[1] for tmp in data_list[d]])
79  X, Y = numpy.meshgrid(xlist, ylist)
80  zlist = numpy.array([tmp[2] for tmp in data_list[d]])
81  axes_array[d].scatter3D(xlist, ylist, zlist, c='b', marker='o')
82  # axes_array[d].plot_surface(X, Y, zlist)
83  # axes_array[d].plot_wireframe(xlist, ylist, zlist)
84  axes_array[d].set_title('d : %.2f~%.2f[m]' % (d*step_d, (d+1)*step_d))
85  matplotlib.pyplot.show()
86 
87 
88 
89 def main():
90  args = parse_args()
91  if args.t == 1:
92  process(args)
93  else:
94  process2(args)
95 
96 if __name__ == '__main__':
97  main()
def setup_data_list(v_num, u_num)


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