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中实现对list做减法操作介绍

问题描述:假设我有这样两个list,           一个是list1,list1 = [1...

Django文件上传与下载(FileFlid)

Django文件上传与下载(FileFlid)

本文实例为大家分享了Django文件上传与下载的具体代码,供大家参考,具体内容如下 Django1.4 首先是上传: #settings.py MEDIA_ROOT = HERE#定义一...

Python中使用Queue和Condition进行线程同步的方法

Queue模块保持线程同步 利用Queue对象先进先出的特性,将每个生产者的数据一次存入队列,而每个消费者将依次从队列中取出数据 import threading # 导入t...

基于Python 装饰器装饰类中的方法实例

基于Python 装饰器装饰类中的方法实例

title: Python 装饰器装饰类中的方法 comments: true date: 2017-04-17 20:44:31 tags: ['Python', 'Decorate'...

Python中偏函数用法示例

本文实例讲述了Python中偏函数用法。分享给大家供大家参考,具体如下: python中偏函数 当一个函数有很多参数时,调用者就需要提供多个参数。如果减少参数个数,就可以简化调用者的负...