jjzjj

SLAM评估工具-EVO从安装到使用

Laney_Midory 2024-07-22 原文

1、安装 evo

pip install evo --upgrade --no-binary evo --user

即可直接安装成功

如果说需要更新则更新即可

/usr/local/bin/python3.7 -m pip install --upgrade pip

2、测试

evo_traj euroc 2.txt --plot

报错:
[ERROR] EuRoC format ground truth must have at least 8 entries per row and no trailing delimiter at the end of the rows (comma)

出现这个问题的原因是生成的原始文件中偶尔存在空格等不是完全规范的tum结果文件

解决办法:运行如下命令可以清除多余的空格
使用这个方法尝试解决:

cat results.txt | tr -s [:space:] > results_new.txt

但是报错
[ERROR] TUM trajectory files must have 8 entries per row and no trailing delimiter at the end of the rows (space)

我打开我的txt数据,发现只有七列而要求是八列,因此需要改成八列数据
要求的八列数据是这些:
时间戳+三维坐标+四元数
我之前路径输出的是三个旋转角,哭泣,所以这里需要把他转换成四元数来输出,重新修改代码运行,输出八列数据

就可以顺利运行啦:

把我的真实轨迹文件进行处理,保留八列数据
如图所示,为了使用evo进行绘图,需要格式准确,这样还是报错
首先,需要顶格,不能空格
其次对空格的要求太高,需要删除空格,转换成逗号更保险,于是需要将上面的格式转换成下面图所示
代码放在下面啦:
新建一个create_txt.cpp

#include <ros/ros.h>
#include <ros/time.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/PointCloud.h>
#include <pcl/point_types.h>                 //pcl点云格式头文件
#include <pcl_conversions/pcl_conversions.h> //转换
#include <pcl/point_cloud.h>
#include <pcl/filters/voxel_grid.h>
#include <sensor_msgs/point_cloud_conversion.h>
#include "Eigen/Core"
#include <boost/foreach.hpp>
#include <std_msgs/Int32.h>
#include <std_msgs/String.h>

#include <stdlib.h>
#include <ctime>
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>

#define foreach BOOST_FOREACH
using namespace std;


std::string  txt_path;
struct TRAJECTORY
{
    double time;
    double position_x;
    double position_y;
    double position_z;
    double orientation_w;
    double orientation_x;
    double orientation_y;
    double orientation_z;
};

void read_trajectory_file(std::string filepathIn)
{
    std::ifstream inFile(filepathIn);
    std::ofstream traj_ofs;
    traj_ofs.open( txt_path.c_str(), std::ios::app);
    if (!inFile)
    {
        cout << "open write file fail!" << endl;
    }
    // temp v
    char content[2000];
    std::string content_str = "";

    while (!inFile.eof())
    {
        content_str = "";
        inFile.getline(content, 2000);
        if (strlen(content) < 2)
            break;

        std::istringstream _Readstr(content);
        std::string partOfstr;
        double data[9];

        for (int i = 0; i < 9; i++)
        {
            getline(_Readstr, partOfstr, ' ');
            data[i] = strtold(partOfstr.c_str(), NULL);
        }

        TRAJECTORY trajectory;
        trajectory.time = data[0];
        trajectory.position_x = data[1];
        trajectory.position_y = data[2];
        trajectory.position_z = data[3];
        trajectory.orientation_w = data[4];
        trajectory.orientation_x = data[5];
        trajectory.orientation_y = data[6];
        trajectory.orientation_z = data[7];

        traj_ofs << std::setprecision(16) <<  trajectory.time << "," << trajectory.position_x << "," <<  trajectory.position_y<< "," <<  trajectory.position_z << "," << trajectory.orientation_w << "," << trajectory.orientation_x << "," << trajectory.orientation_y << "," << trajectory.orientation_z<<std::endl;
    }
    inFile.close();
    traj_ofs.close();
    cout << "read trajectory file end!" << endl;

}

int main(int argc, char **argv)
{

    ros::init(argc, argv, "create_txt");
    ros::NodeHandle nh;

    string traj_path = "";
    nh.param<string>("input_trajectory_path", traj_path, "");
    nh.param<string>("output_txt_path", txt_path, "");
    read_trajectory_file(traj_path);

    return 0;
}

这样就可以成功转换啦

接下来使用该命令

evo_traj euroc ground.txt --plot

就可以成功绘图啦
但是我使用evo_traj tum ground.txt --plot就一直报错
应该还是格式的问题

格式转化

evo_traj euroc test.txt --save_as_tum

就可以转化成tum格式了,其他的都类似

3. 轨迹对齐

采用对齐指令将两条轨迹进行对齐。为此需要通过–ref参数指定参考轨迹,并增加参数-a(或–align)进行对齐(旋转与平移)

evo_traj euroc test.txt --ref=ground.txt -p --plot_mode xyz -a --correct_scale

但是报错:
[ERROR] found no matching timestamps between reference and test.txt with max. time diff 0.01 (s) and time offset 0.0 (s)
时间戳对应不上,这可怎么办?
需要时间戳对应才可以进行对比,这就很无语了
这样都把所有的txt文件时间戳改成0,1,2,3…个数一样就可以对齐啦

修改上面代码读取文件把时间戳进行修改
代码如下:

#include <ros/ros.h>
#include <ros/time.h>
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/PointCloud.h>
#include <pcl/point_types.h>                 //pcl点云格式头文件
#include <pcl_conversions/pcl_conversions.h> //转换
#include <pcl/point_cloud.h>
#include <pcl/filters/voxel_grid.h>
#include <sensor_msgs/point_cloud_conversion.h>
#include "Eigen/Core"
#include <boost/foreach.hpp>
#include <std_msgs/Int32.h>
#include <std_msgs/String.h>

#include <stdlib.h>
#include <ctime>
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>

#define foreach BOOST_FOREACH
using namespace std;


std::string  txt_path;
struct TRAJECTORY
{
    double time;
    double position_x;
    double position_y;
    double position_z;
    double orientation_w;
    double orientation_x;
    double orientation_y;
    double orientation_z;
};

void read_trajectory_file(std::string filepathIn)
{
    std::ifstream inFile(filepathIn);
    std::ofstream traj_ofs;
    traj_ofs.open( txt_path.c_str(), std::ios::app);
    if (!inFile)
    {
        cout << "open write file fail!" << endl;
    }
    // temp v
    char content[2000];
    std::string content_str = "";
    int m=0;
    int n= -1;

    while (!inFile.eof())
    {
        content_str = "";
        inFile.getline(content, 2000);
        n++;
        if(n%40==0)
        {
        if (strlen(content) < 2)
            break;

        std::istringstream _Readstr(content);
        std::string partOfstr;
        double data[9];

        for (int i = 0; i < 9; i++)
        {
            getline(_Readstr, partOfstr, ',');
            data[i] = strtold(partOfstr.c_str(), NULL);
        }

        TRAJECTORY trajectory;
        trajectory.time = m;
        trajectory.position_x = data[1];
        trajectory.position_y = data[2];
        trajectory.position_z = data[3];
        trajectory.orientation_w = data[4];
        trajectory.orientation_x = data[5];
        trajectory.orientation_y = data[6];
        trajectory.orientation_z = data[7];

        traj_ofs << std::setprecision(16) <<  trajectory.time << "," << trajectory.position_x << "," <<  trajectory.position_y<< "," <<  trajectory.position_z << "," << trajectory.orientation_w << "," << trajectory.orientation_x << "," << trajectory.orientation_y << "," << trajectory.orientation_z<<std::endl;
        m++;
         }
    
    }
    inFile.close();
    traj_ofs.close();
    cout << "read trajectory file end!" << endl;

}

int main(int argc, char **argv)
{

    ros::init(argc, argv, "create_txt");
    ros::NodeHandle nh;

    string traj_path = "";
    nh.param<string>("input_trajectory_path", traj_path, "");
    nh.param<string>("output_txt_path", txt_path, "");
    read_trajectory_file(traj_path);

    return 0;
}

这样结果就是:
一共5008个数据,再次输入该语句进行轨迹对齐

evo_traj euroc trial.txt --ref=truth.txt -p --plot_mode xyz -a --correct_scale

这个效果与下面效果相同

evo_traj euroc trial.txt --ref truth.txt -p -a

这里有个bug
因为他是完全按照时间戳进行对齐的
要是想让他自动配准再显示出来这个就做不到
因此即使尺度进行了修改,要是点对应不上还是无法进行对比
因此需要在使用evo前自己进行点云轨迹的处理
这里我使用了cloudcompare进行处理进行配准之后在进行轨迹的显示对比
不知道有没有更简单的方法,希望大家多多分享

如果想投影到xy平面进行显示,则输入下面的命令

evo_traj euroc trial.txt --ref=truth.txt -p --plot_mode xy -a --correct_scale

4.计算轨迹的绝对误差(evo_ape)

直接使用下面的语句

evo_ape euroc true.txt  test.txt --plot --plot_mode xy --save_results result.zip

会报错:
[ERROR] TUM trajectory files must have 8 entries per row and no trailing delimiter at the end of the rows (space)

于是我使用上面的格式转换把数据格式转成tum格式
再进行比较

evo_ape tum true.tum test.tum --plot --plot_mode xy --save_results result.zip

5.计算轨迹的绝对误差(evo_ape)

evo_rpe tum true.tum test.tum --plot --plot_mode xy --save_results resultrpe.zip

注意!
这里还要分平移误差和旋转误差,结果可能有区别!

其中-r表示ape所基于的姿态关系
不添加-r/–pose_relation和可选项,则默认为trans_part。

-r/–pose_relation可选参数 含义
full 表示同时考虑旋转和平移误差得到的ape,无单位(unit-less)
trans_part 考虑平移部分得到的ape,单位为m
rot_part 考虑旋转部分得到的ape,无单位(unit-less)
angle_deg 考虑旋转角得到的ape,单位°(deg)
angle_rad 考虑旋转角得到的ape,单位弧度(rad)

–d/–delta表示相对位姿之间的增量,–u/–delta_unit表示增量的单位,可选参数为[f, d, r, m],分别表示[frames, deg, rad, meters]。–d/–delta -u/–delta_unit合起来表示衡量局部精度的单位,如每米,每弧度,每百米等。其中–delta_unit为f时,–delta的参数必须为整形,其余情况下可以为浮点型。–delta 默认为1,–delta_unit默认为f。

因此这里仅仅统计平移的相对精度:

evo_rpe tum true.tum test.tum -r trans_part --delta 1 --delta_unit m --plot --plot_mode xy

全部:

evo_rpe tum true.tum test.tum -r full --delta 1 --delta_unit m -vas --plot --plot_mode xy

我实验的最小的结果:

evo_rpe tum true.tum test.tum -r trans_part --plot --plot_mode xy

但是这个效果对所有实验都很小。。。
有点搞不清楚,这些语句有什么影响了

有关SLAM评估工具-EVO从安装到使用的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  3. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  4. ruby-on-rails - 使用 Ruby on Rails 进行自动化测试 - 最佳实践 - 2

    很好奇,就使用ruby​​onrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提

  5. ruby - 在 Ruby 中使用匿名模块 - 2

    假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于

  6. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  7. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  8. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  9. ruby - 使用 ruby​​ 将 HTML 转换为纯文本并维护结构/格式 - 2

    我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h

  10. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

随机推荐