python 画3维轨迹图并进行比较的实例

yipeiwu_com6年前Python基础

一. 数据的格式

首先我们需要x,y,z三个数据进行画图。从本实验用到的数据集KITTI 00.txt中举例:

1.000000e+00 9.043680e-12 2.326809e-11 5.551115e-17 9.043683e-12 1.000000e+00 2.392370e-10 3.330669e-16 2.326810e-11 2.392370e-10 9.999999e-01 -4.440892e-16

一组有12个数据,相当于T={R,t},R是3×3的矩阵,t是3×1的矩阵。我们需要的是t的数据。

有些groundtruth是8个数据,第一个是时间戳,在三个是x,y,z,后面四个是是四元数的数据。

代码如下:

# import necessary module
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

# load data from file
# you can replace this using with open
data1 = np.loadtxt("./dataset/poses/00.txt")

first_2000 = data1[:, 3]
second_2000 = data1[:, 7]
third_2000 = data1[:, 11]
data2 = np.loadtxt("../temp/kittiseq00_imu.txt")
first_1000 = data2[:, 1]
second_1000 = data2[:, 2]
third_1000 = data2[:, 3]
# print to check data
#print first_2000
#print second_2000
#print third_2000

# new a figure and set it into 3d
fig = plt.figure()
ax = fig.gca(projection='3d')

# set figure information
ax.set_title("3D_Curve")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")

# draw the figure, the color is r = read
figure1 = ax.plot(first_2000, second_2000, third_2000, c='r')
figure2 = ax.plot(first_1000, second_1000, third_1000, c='b')
plt.show()

效果图(电脑比较垃圾,后面的轨迹跟踪的时候提取的特征点太少):

以上这篇python 画3维轨迹图并进行比较的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python tkinter组件使用详解

python tkinter组件使用详解

这篇文章主要介绍了python tkinter组件使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.按钮 # 按钮 #...

numpy添加新的维度:newaxis的方法

numpy添加新的维度:newaxis的方法

numpy中包含的newaxis可以给原数组增加一个维度 np.newaxis放的位置不同,产生的新数组也不同 一维数组 x = np.random.randint(1, 8, si...

Python中的ctime()方法使用教程

 ctime()方法转换,因为历元到表示本地时间的字符串表示以秒为单位的时间。如果不设置秒时或None,所返回的时间的当前time()被使用。使用asctime(localti...

基于python if 判断选择结构的实例详解

代码执行结构为顺序结构、选择结构、循环结构。 python判断选择结构【if】 if 判断条件 #进行判断条件满足之后执行下方语句 执行语句 elif 判断条件 #在不满足上面所有...

详解python持久化文件读写

持久化文件读写: f=open('info.txt','a+') f.seek(0) str1=f.read() if len(str1)==0: f1 = open('info...