TUM evaluate_ate.py评测工具

2023-11-11 06:10
文章标签 工具 评测 py evaluate ate tum

本文主要是介绍TUM evaluate_ate.py评测工具,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

绝对轨迹误差脚本直接测量真实轨迹和估计轨迹的点之间的差异。

作为预处理步骤,我们使用时间戳将估计的姿势与地面真实姿势相关联。 基于此关联,我们使用奇异值分解来对齐真实轨迹和估计轨迹。

最后,我们计算每对姿势之间的差异,并输出这些差异的均值/中值/标准差。

此外,脚本还可以将两个轨迹绘制到png或pdf文件,这样一来可以更加直观的看到差异。

接下来,我们分别看一下相应的脚本执行命令

注:需要将evaluate_ate.py、groundtruth.txt、CameraTrajectory.txt、associate.py放在同一位置

(1)仅输出RMSE/cm误差,执行如下命令:

python evaluate_ate.py groundtruth.txt CameraTrajectory.txt

(2)输出真实轨迹和预测轨迹以及误差,并直观显示,执行如下命令:

 python evaluate_ate.py groundtruth.txt CameraTrajectory.txt --plot result.png

(3)输出所有误差,包含平均值,中值等, 执行如下命令:

 python evaluate_ate.py groundtruth.txt CameraTrajectory.txt --verbose

主要功能:
修改轨迹名称,修改图例位置,修改图例字体大小,
下图参考:https://blog.csdn.net/wannna/article/details/102751689
在这里插入图片描述下面代码图例位置设置为 右上角:

plt.legend(loc="upper right")   # 与plt.legend(loc=1)等价

下面代码图例位置设置为 右下角:

ax.legend(loc="lower right")

设置图例文字大小

ax.legend(loc="lower right",fontsize=12)

设置图片保存分辨率:

plt.savefig(args.plot,dpi=800)

以及取消图中difference计算,修改见下面代码

#!/usr/bin/python
"""
This script computes the absolute trajectory error from the ground truth
trajectory and the estimated trajectory.
"""import sys
import numpy
import argparse
import associatedef align(model,data):"""Align two trajectories using the method of Horn (closed-form).Input:model -- first trajectory (3xn)data -- second trajectory (3xn)Output:rot -- rotation matrix (3x3)trans -- translation vector (3x1)trans_error -- translational error per point (1xn)"""numpy.set_printoptions(precision=3,suppress=True)model_zerocentered = model - model.mean(1)data_zerocentered = data - data.mean(1)W = numpy.zeros( (3,3) )for column in range(model.shape[1]):W += numpy.outer(model_zerocentered[:,column],data_zerocentered[:,column])U,d,Vh = numpy.linalg.linalg.svd(W.transpose())S = numpy.matrix(numpy.identity( 3 ))if(numpy.linalg.det(U) * numpy.linalg.det(Vh)<0):S[2,2] = -1rot = U*S*Vhtrans = data.mean(1) - rot * model.mean(1)model_aligned = rot * model + transalignment_error = model_aligned - datatrans_error = numpy.sqrt(numpy.sum(numpy.multiply(alignment_error,alignment_error),0)).A[0]return rot,trans,trans_errordef plot_traj(ax,stamps,traj,style,color,label):"""Plot a trajectory using matplotlib. Input:ax -- the plotstamps -- time stamps (1xn)traj -- trajectory (3xn)style -- line stylecolor -- line colorlabel -- plot legend"""stamps.sort()interval = numpy.median([s-t for s,t in zip(stamps[1:],stamps[:-1])])x = []y = []last = stamps[0]for i in range(len(stamps)):if stamps[i]-last < 2*interval:x.append(traj[i][0])y.append(traj[i][1])elif len(x)>0:ax.plot(x,y,style,color=color,label=label)label=""x=[]y=[]last= stamps[i]if len(x)>0:ax.plot(x,y,style,color=color,label=label)def plot_traj3D(ax,stamps,traj,style,color,label):"""Plot a trajectory using matplotlib. Input:ax -- the plotstamps -- time stamps (1xn)traj -- trajectory (3xn)style -- line stylecolor -- line colorlabel -- plot legend"""stamps.sort()interval = numpy.median([s-t for s,t in zip(stamps[1:],stamps[:-1])])x = []y = []z = []last = stamps[0]for i in range(len(stamps)):if stamps[i]-last < 2*interval:x.append(traj[i][0])y.append(traj[i][1])z.append(traj[i][2])elif len(x)>0:ax.plot(x,y,z,style,color=color,label=label)label=""x=[]y=[]z=[]last= stamps[i]if len(x)>0:ax.plot(x,y,z,style,color=color,label=label)          if __name__=="__main__":# parse command lineparser = argparse.ArgumentParser(description='''This script computes the absolute trajectory error from the ground truth trajectory and the estimated trajectory. ''')parser.add_argument('first_file', help='ground truth trajectory (format: timestamp tx ty tz qx qy qz qw)')parser.add_argument('second_file', help='estimated trajectory (format: timestamp tx ty tz qx qy qz qw)')parser.add_argument('--offset', help='time offset added to the timestamps of the second file (default: 0.0)',default=0.0)parser.add_argument('--scale', help='scaling factor for the second trajectory (default: 1.0)',default=1.0)parser.add_argument('--max_difference', help='maximally allowed time difference for matching entries (default: 0.02)',default=0.02)parser.add_argument('--save', help='save aligned second trajectory to disk (format: stamp2 x2 y2 z2)')parser.add_argument('--save_associations', help='save associated first and aligned second trajectory to disk (format: stamp1 x1 y1 z1 stamp2 x2 y2 z2)')parser.add_argument('--plot', help='plot the first and the aligned second trajectory to an image (format: png)')parser.add_argument('--plot3D', help='plot the first and the aligned second trajectory to as interactive 3D plot (format: png)', action = 'store_true')parser.add_argument('--verbose', help='print all evaluation data (otherwise, only the RMSE absolute translational error in meters after alignment will be printed)', action='store_true')args = parser.parse_args()first_list = associate.read_file_list(args.first_file)second_list = associate.read_file_list(args.second_file)matches = associate.associate(first_list, second_list,float(args.offset),float(args.max_difference))    if len(matches)<2:sys.exit("Couldn't find matching timestamp pairs between groundtruth and estimated trajectory! Did you choose the correct sequence?")first_xyz = numpy.matrix([[float(value) for value in first_list[a][0:3]] for a,b in matches]).transpose()second_xyz = numpy.matrix([[float(value)*float(args.scale) for value in second_list[b][0:3]] for a,b in matches]).transpose()rot,trans,trans_error = align(second_xyz,first_xyz)second_xyz_aligned = rot * second_xyz + transfirst_stamps = first_list.keys()first_stamps.sort()first_xyz_full = numpy.matrix([[float(value) for value in first_list[b][0:3]] for b in first_stamps]).transpose()second_stamps = second_list.keys()second_stamps.sort()second_xyz_full = numpy.matrix([[float(value)*float(args.scale) for value in second_list[b][0:3]] for b in second_stamps]).transpose()second_xyz_full_aligned = rot * second_xyz_full + transif args.verbose:print "compared_pose_pairs %d pairs"%(len(trans_error))print "absolute_translational_error.rmse %f m"%numpy.sqrt(numpy.dot(trans_error,trans_error) / len(trans_error))print "absolute_translational_error.mean %f m"%numpy.mean(trans_error)print "absolute_translational_error.median %f m"%numpy.median(trans_error)print "absolute_translational_error.std %f m"%numpy.std(trans_error)print "absolute_translational_error.min %f m"%numpy.min(trans_error)print "absolute_translational_error.max %f m"%numpy.max(trans_error)else:print "%f"%numpy.sqrt(numpy.dot(trans_error,trans_error) / len(trans_error))if args.save_associations:file = open(args.save_associations,"w")file.write("\n".join(["%f %f %f %f %f %f %f %f"%(a,x1,y1,z1,b,x2,y2,z2) for (a,b),(x1,y1,z1),(x2,y2,z2) in zip(matches,first_xyz.transpose().A,second_xyz_aligned.transpose().A)]))file.close()if args.save:file = open(args.save,"w")file.write("\n".join(["%f "%stamp+" ".join(["%f"%d for d in line]) for stamp,line in zip(second_stamps,second_xyz_full_aligned.transpose().A)]))file.close()if args.plot:import matplotlibmatplotlib.use('Agg')import matplotlib.pyplot as pltimport matplotlib.pylab as pylabfrom matplotlib.patches import Ellipsefig = plt.figure()ax = fig.add_subplot(111)#修改轨迹名称plot_traj(ax,first_stamps,first_xyz_full.transpose().A,'-',"black","Ours")plot_traj(ax,second_stamps,second_xyz_full_aligned.transpose().A,'-',"blue","VINS-Mono")
#注释下面,取消difference计算#       label="difference"#      for (a,b),(x1,y1,z1),(x2,y2,z2) in zip(matches,first_xyz.transpose().A,second_xyz_aligned.transpose().A):#          ax.plot([x1,x2],[y1,y2],'-',color="red",label=label)#         label=""#    修改图例位置ax.legend(loc="lower right")ax.set_xlabel('x [m]')ax.set_ylabel('y [m]')
#dpi 修改图片分辨率plt.savefig(args.plot,dpi=800)if args.plot3D:import matplotlib as mplmpl.use('Qt4Agg')from mpl_toolkits.mplot3d import Axes3Dimport numpy as npimport matplotlib.pyplot as pltfig = plt.figure()ax = fig.gca(projection='3d')
#        ax = fig.add_subplot(111)plot_traj3D(ax,first_stamps,first_xyz_full.transpose().A,'-',"black","ground truth")plot_traj3D(ax,second_stamps,second_xyz_full_aligned.transpose().A,'-',"blue","estimated")label="difference"for (a,b),(x1,y1,z1),(x2,y2,z2) in zip(matches,first_xyz.transpose().A,second_xyz_aligned.transpose().A):ax.plot([x1,x2],[y1,y2],[z1,z2],'-',color="red",label=label)label=""            ax.legend()ax.set_xlabel('x [m]')ax.set_ylabel('y [m]')print "Showing"plt.show(block=True)plt.savefig("./test.png",dpi=90)
#        answer = raw_input('Back to main and window visible? ')
#        if answer == 'y':
#            print('Excellent')
#        else:
#            print('Nope')#plt.savefig(args.plot,dpi=90)

这篇关于TUM evaluate_ate.py评测工具的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/388066

相关文章

SQLite3命令行工具最佳实践指南

《SQLite3命令行工具最佳实践指南》SQLite3是轻量级嵌入式数据库,无需服务器支持,具备ACID事务与跨平台特性,适用于小型项目和学习,sqlite3.exe作为命令行工具,支持SQL执行、数... 目录1. SQLite3简介和特点2. sqlite3.exe使用概述2.1 sqlite3.exe

基于Python实现一个Windows Tree命令工具

《基于Python实现一个WindowsTree命令工具》今天想要在Windows平台的CMD命令终端窗口中使用像Linux下的tree命令,打印一下目录结构层级树,然而还真有tree命令,但是发现... 目录引言实现代码使用说明可用选项示例用法功能特点添加到环境变量方法一:创建批处理文件并添加到PATH1

使用jenv工具管理多个JDK版本的方法步骤

《使用jenv工具管理多个JDK版本的方法步骤》jenv是一个开源的Java环境管理工具,旨在帮助开发者在同一台机器上轻松管理和切换多个Java版本,:本文主要介绍使用jenv工具管理多个JD... 目录一、jenv到底是干啥的?二、jenv的核心功能(一)管理多个Java版本(二)支持插件扩展(三)环境隔

Python使用smtplib库开发一个邮件自动发送工具

《Python使用smtplib库开发一个邮件自动发送工具》在现代软件开发中,自动化邮件发送是一个非常实用的功能,无论是系统通知、营销邮件、还是日常工作报告,Python的smtplib库都能帮助我们... 目录代码实现与知识点解析1. 导入必要的库2. 配置邮件服务器参数3. 创建邮件发送类4. 实现邮件

CnPlugin是PL/SQL Developer工具插件使用教程

《CnPlugin是PL/SQLDeveloper工具插件使用教程》:本文主要介绍CnPlugin是PL/SQLDeveloper工具插件使用教程,具有很好的参考价值,希望对大家有所帮助,如有错... 目录PL/SQL Developer工具插件使用安装拷贝文件配置总结PL/SQL Developer工具插

Python使用FFmpeg实现高效音频格式转换工具

《Python使用FFmpeg实现高效音频格式转换工具》在数字音频处理领域,音频格式转换是一项基础但至关重要的功能,本文主要为大家介绍了Python如何使用FFmpeg实现强大功能的图形化音频转换工具... 目录概述功能详解软件效果展示主界面布局转换过程截图完成提示开发步骤详解1. 环境准备2. 项目功能结

Linux系统之stress-ng测压工具的使用

《Linux系统之stress-ng测压工具的使用》:本文主要介绍Linux系统之stress-ng测压工具的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、理论1.stress工具简介与安装2.语法及参数3.具体安装二、实验1.运行8 cpu, 4 fo

Maven项目中集成数据库文档生成工具的操作步骤

《Maven项目中集成数据库文档生成工具的操作步骤》在Maven项目中,可以通过集成数据库文档生成工具来自动生成数据库文档,本文为大家整理了使用screw-maven-plugin(推荐)的完... 目录1. 添加插件配置到 pom.XML2. 配置数据库信息3. 执行生成命令4. 高级配置选项5. 注意事

Python使用pynput模拟实现键盘自动输入工具

《Python使用pynput模拟实现键盘自动输入工具》在日常办公和软件开发中,我们经常需要处理大量重复的文本输入工作,所以本文就来和大家介绍一款使用Python的PyQt5库结合pynput键盘控制... 目录概述:当自动化遇上可视化功能全景图核心功能矩阵技术栈深度效果展示使用教程四步操作指南核心代码解析

如何基于Python开发一个微信自动化工具

《如何基于Python开发一个微信自动化工具》在当今数字化办公场景中,自动化工具已成为提升工作效率的利器,本文将深入剖析一个基于Python的微信自动化工具开发全过程,有需要的小伙伴可以了解下... 目录概述功能全景1. 核心功能模块2. 特色功能效果展示1. 主界面概览2. 定时任务配置3. 操作日志演示