简易版
import matplotlib.pyplot as plt
def draw_compare_graph():
"""
修改root_path为txt所在文件夹路径
修改两个txt文件名称
修改plt.title为想要的名称
保存图片是记得最大化窗口后保存,这样保存下的图片尺寸更大
:return: void
"""
root_path = "Y:/dataset/input/xyz_result/"
file_pc = open(root_path + 'cpu_ref.txt')
data_pc = file_pc.readlines()
file_amba = open(root_path + 'lk3_fast10000_nms.txt')
data_amba = file_amba.readlines()
pc_para_0 = []
pc_para_6 = []
pc_para_7 = []
pc_para_8 = []
for num in data_pc:
nums = num.split(' ')
pc_para_0.append(float(nums[0]))
pc_para_6.append(float(nums[5]))
pc_para_7.append(float(nums[6]))
pc_para_8.append(float(nums[7]))
amba_para_0 = []
amba_para_6 = []
amba_para_7 = []
amba_para_8 = []
for num in data_amba:
nums = num.split(' ')
amba_para_0.append(float(nums[0]))
amba_para_6.append(float(nums[5]))
amba_para_7.append(float(nums[6]))
amba_para_8.append(float(nums[7]))
plt.figure()
plt.title("cpu&dsp")
plt.plot(pc_para_0, pc_para_6, "r", label='cpu-x', linestyle='--')
plt.plot(pc_para_0, pc_para_7, "g", label='cpu-y', linestyle='--')
plt.plot(pc_para_0, pc_para_8, "b", label='cpu-z', linestyle='--')
plt.plot(amba_para_0, amba_para_6, "m", label='dsp-x')
plt.plot(amba_para_0, amba_para_7, "c", label='dsp-y')
plt.plot(amba_para_0, amba_para_8, "y", label='dsp-z')
plt.legend()
plt.show()
if __name__ == '__main__':
draw_compare_graph()
复杂版
import matplotlib.pyplot as plt
def draw_one_graph():
"""
修改root_path为txt所在文件夹路径
修改两个txt文件名称
修改plt.title为想要的名称
保存图片是记得最大化窗口后保存,这样保存下的图片尺寸更大
:return: void
"""
root_path = "F:/vio_dataset/data1015_online5/"
file_pc = open(root_path + 'pc-stereo_vio_results-14090.txt')
data_pc = file_pc.readlines()
pc_para_0 = []
pc_para_6 = []
pc_para_7 = []
pc_para_8 = []
for num in data_pc:
nums = num.split(' ')
pc_para_0.append(float(nums[0]))
pc_para_6.append(float(nums[5]))
pc_para_7.append(float(nums[6]))
pc_para_8.append(float(nums[7]))
plt.figure()
plt.title("pc&amba_harris")
plt.plot(pc_para_0, pc_para_6, "r", label='pc-x', linestyle='--')
plt.plot(pc_para_0, pc_para_7, "g", label='pc-y', linestyle='--')
plt.plot(pc_para_0, pc_para_8, "b", label='pc-z', linestyle='--')
plt.legend()
plt.show()
def draw_compare_graph():
"""
修改root_path为txt所在文件夹路径
修改两个txt文件名称
修改plt.title为想要的名称
保存图片是记得最大化窗口后保存,这样保存下的图片尺寸更大
:return: void
"""
root_path = "F:/vio_dataset/data1015_online7/EKF_Map_mem-debug/"
file_pc = open(root_path + 'amba_stereo_vio_results-hpc-2612dede.txt')
data_pc = file_pc.readlines()
file_amba = open(root_path + 'amba_stereo_vio_results-origin.txt')
data_amba = file_amba.readlines()
pc_para_0 = []
pc_para_6 = []
pc_para_7 = []
pc_para_8 = []
for num in data_pc:
nums = num.split(' ')
pc_para_0.append(float(nums[0]))
pc_para_6.append(float(nums[5]))
pc_para_7.append(float(nums[6]))
pc_para_8.append(float(nums[7]))
amba_para_0 = []
amba_para_6 = []
amba_para_7 = []
amba_para_8 = []
for num in data_amba:
nums = num.split(' ')
amba_para_0.append(float(nums[0]))
amba_para_6.append(float(nums[5]))
amba_para_7.append(float(nums[6]))
amba_para_8.append(float(nums[7]))
plt.figure()
plt.title("data1015_online9--amba_compare_vpu")
plt.plot(pc_para_0, pc_para_6, "r", label='pc-x', linestyle='--')
plt.plot(pc_para_0, pc_para_7, "g", label='pc-y', linestyle='--')
plt.plot(pc_para_0, pc_para_8, "b", label='pc-z', linestyle='--')
plt.plot(amba_para_0, amba_para_6, "m", label='amba-x')
plt.plot(amba_para_0, amba_para_7, "c", label='amba-y')
plt.plot(amba_para_0, amba_para_8, "y", label='amba-z')
plt.legend()
plt.show()
def get_space_num(line, pos):
space_num = 0
for i in range(0, 50):
if line[pos] == ' ':
pos += 1
space_num += 1
else:
break
return space_num
def get_vio_result_from_txt_file(fn, key):
amba_para_0 = []
amba_para_6 = []
amba_para_7 = []
amba_para_8 = []
with open(fn) as f:
lines = f.readlines()
for line in lines:
pos = line.find(key)
if pos > 0:
pos += len(key)
end_pos = line.find(' ', pos)
time_str = line[pos: end_pos]
space_num1 = get_space_num(line, end_pos)
end_pos2 = line.find(' ', end_pos + space_num1)
x_str = line[end_pos + space_num1: end_pos2]
space_num2 = get_space_num(line, end_pos2)
end_pos3 = line.find(' ', end_pos2 + space_num2)
y_str = line[end_pos2 + space_num2: end_pos3]
space_num3 = get_space_num(line, end_pos3)
end_pos4 = line.find(' ', end_pos3 + space_num3)
z_str = line[end_pos3 + space_num3: end_pos4]
try:
time_float = float(time_str)
x_float = float(x_str)
y_float = float(y_str)
z_float = float(z_str)
amba_para_0.append(time_float)
amba_para_6.append(x_float)
amba_para_7.append(y_float)
amba_para_8.append(z_float)
except Exception:
print("error")
continue
root_path = "F:/vio_dataset/data1015_online7/"
file_pc = open(root_path + 'amba_stereo_vio_results-hpc-2612dede.txt')
data_pc = file_pc.readlines()
pc_para_0 = []
pc_para_6 = []
pc_para_7 = []
pc_para_8 = []
for num in data_pc:
nums = num.split(' ')
pc_para_0.append(float(nums[0]))
pc_para_6.append(float(nums[5]))
pc_para_7.append(float(nums[6]))
pc_para_8.append(float(nums[7]))
plt.figure()
plt.title("data1015_online7--pc&amba-multi_thread-lk_vpu")
plt.plot(pc_para_0, pc_para_6, "r", label='pc-x', linestyle='--')
plt.plot(pc_para_0, pc_para_7, "g", label='pc-y', linestyle='--')
plt.plot(pc_para_0, pc_para_8, "b", label='pc-z', linestyle='--')
plt.plot(amba_para_0, amba_para_6, "m", label='amba-x')
plt.plot(amba_para_0, amba_para_7, "c", label='amba-y')
plt.plot(amba_para_0, amba_para_8, "y", label='amba-z')
plt.legend()
plt.show()
def get_vio_result_from_two_txt_file(fn1, fn2, key):
amba_para_0 = []
amba_para_6 = []
amba_para_7 = []
amba_para_8 = []
with open(fn2) as f:
lines = f.readlines()
for line in lines:
pos = line.find(key)
if pos > 0:
pos += len(key)
end_pos = line.find(' ', pos)
time_str = line[pos: end_pos]
space_num1 = get_space_num(line, end_pos)
end_pos2 = line.find(' ', end_pos + space_num1)
x_str = line[end_pos + space_num1: end_pos2]
space_num2 = get_space_num(line, end_pos2)
end_pos3 = line.find(' ', end_pos2 + space_num2)
y_str = line[end_pos2 + space_num2: end_pos3]
space_num3 = get_space_num(line, end_pos3)
end_pos4 = line.find(' ', end_pos3 + space_num3)
z_str = line[end_pos3 + space_num3: end_pos4]
try:
time_float = float(time_str)
x_float = float(x_str)
y_float = float(y_str)
z_float = float(z_str)
amba_para_0.append(time_float)
amba_para_6.append(x_float)
amba_para_7.append(y_float)
amba_para_8.append(z_float)
except Exception:
print("error")
continue
pc_para_0 = []
pc_para_6 = []
pc_para_7 = []
pc_para_8 = []
with open(fn1) as f:
lines = f.readlines()
for line in lines:
pos = line.find(key)
if pos > 0:
pos += len(key)
end_pos = line.find(' ', pos)
time_str = line[pos: end_pos]
space_num1 = get_space_num(line, end_pos)
end_pos2 = line.find(' ', end_pos + space_num1)
x_str = line[end_pos + space_num1: end_pos2]
space_num2 = get_space_num(line, end_pos2)
end_pos3 = line.find(' ', end_pos2 + space_num2)
y_str = line[end_pos2 + space_num2: end_pos3]
space_num3 = get_space_num(line, end_pos3)
end_pos4 = line.find(' ', end_pos3 + space_num3)
z_str = line[end_pos3 + space_num3: end_pos4]
try:
time_float = float(time_str)
x_float = float(x_str)
y_float = float(y_str)
z_float = float(z_str)
pc_para_0.append(time_float)
pc_para_6.append(x_float)
pc_para_7.append(y_float)
pc_para_8.append(z_float)
except Exception:
print("error")
continue
plt.figure()
plt.title("data1015_online7-55ad3d6c")
plt.plot(pc_para_0, pc_para_6, "r", label='pc-x', linestyle='--')
plt.plot(pc_para_0, pc_para_7, "g", label='pc-y', linestyle='--')
plt.plot(pc_para_0, pc_para_8, "b", label='pc-z', linestyle='--')
plt.plot(amba_para_0, amba_para_6, "m", label='amba-x')
plt.plot(amba_para_0, amba_para_7, "c", label='amba-y')
plt.plot(amba_para_0, amba_para_8, "y", label='amba-z')
plt.legend()
figure = plt.gcf()
figure.set_size_inches(24, 13.5)
plt.savefig('output.png', bbox_inches='tight')
plt.show()
def get_time_and_z_curve_from_txt_file(fn, key_result, key_time):
amba_para_0 = []
amba_para_6 = []
amba_para_7 = []
amba_para_8 = []
with open(fn) as f:
lines = f.readlines()
for line in lines:
pos = line.find(key_result)
if pos > 0:
pos += len(key_result)
end_pos = line.find(' ', pos)
time_str = line[pos: end_pos]
space_num1 = get_space_num(line, end_pos)
end_pos2 = line.find(' ', end_pos + space_num1)
x_str = line[end_pos + space_num1: end_pos2]
space_num2 = get_space_num(line, end_pos2)
end_pos3 = line.find(' ', end_pos2 + space_num2)
y_str = line[end_pos2 + space_num2: end_pos3]
space_num3 = get_space_num(line, end_pos3)
end_pos4 = line.find(' ', end_pos3 + space_num3)
z_str = line[end_pos3 + space_num3: end_pos4]
try:
time_float = float(time_str)
x_float = float(x_str)
y_float = float(y_str)
z_float = float(z_str)
amba_para_0.append(time_float)
amba_para_6.append(x_float)
amba_para_7.append(y_float)
amba_para_8.append(z_float)
except Exception:
print("error")
continue
res = []
with open(fn) as f:
lines = f.readlines()
for line in lines:
pos = line.find(key_time)
if pos > 0:
pos += len(key_time)
end_pos = line.find('/n', pos)
str = line[pos: end_pos]
try:
res_tmp = float(str)
res.append(res_tmp)
except Exception:
continue
print("time number: ", len(res))
plt.figure()
plt.title("data1015_online7 time, key: " + key_time)
for i in range(0, len(amba_para_8)):
amba_para_8[i] = amba_para_8[i] * 5
plt.plot(amba_para_0, amba_para_8, "r", label='z', linestyle='--')
plt.plot(amba_para_0, res, ".", label='time')
plt.legend()
plt.show()
if __name__ == '__main__':
path = "F:/lk_level4/"
get_vio_result_from_two_txt_file(path + "level3_double_eye_log.txt",
path + "level6_double_eye_log_new.txt", "--------translation: ")