使用Pangolon在同一副图中,画出两个轨迹,比较误差
使用 code/ground-truth.txt 和 code/estimate.txt 两条轨迹。请你根据上面公式,实现 RMSE
的计算代码,给出最后的 RMSE 结果。作为验算,参考答案为:2.207。用上题的画图程序将两条轨迹画在同一个图里,看看它们相差多少。
完整题目描述

ground-truth.txt和estimate.txt放在了源文件夹下的data目录下,编写了用于画图的trajectory_compare.cpp文件
相关代码及程序可在我的github中获取,地址:https://github.com/feifanrensheng/trajectory_compare
代码如下:
// trajectory_compare.cpp created by zhang ning 2018/3/23
#include <sophus/se3.h>
#include <string>
#include <iostream>
#include <fstream> // need pangolin for plotting trajectory
#include <pangolin/pangolin.h> using namespace std; // function for plotting trajectory, don't edit this code
// start point is red and end point is blue
void DrawTrajectory(vector<Sophus::SE3, Eigen::aligned_allocator<Sophus::SE3>>,vector<Sophus::SE3, Eigen::aligned_allocator<Sophus::SE3>>); int main(int argc, char **argv) { vector<Sophus::SE3, Eigen::aligned_allocator<Sophus::SE3>> poses1,poses2; /// implement pose reading code
// start your code here (5~10 lines)
ifstream infile;
infile.open("../data/estimated.txt");
if(!infile) cout<<"error"<<endl; cout<<"存入数组"<<endl; //先将文件中的数据存入到一个二维数组中
double data;
double a[][];
double *p=&a[][];
while(infile>>data) //遇到空白符结束
{
*p=data;
p++;
}
infile.close();
for(int i=;i<;i++) //分别对每一行数据生成一个变换矩阵,然后存入动态数组poses中
{
Eigen::Quaterniond q1 = Eigen::Quaterniond(a[i][],a[i][],a[i][],a[i][]);
Eigen::Vector3d t1;
t1<<a[i][],a[i][],a[i][];
Sophus::SE3 SE3_qt1(q1,t1);
poses1.push_back(SE3_qt1);
}
ifstream truth;
truth.open("../data/groundtruth.txt");
if(!truth) cout<<"error"<<endl; cout<<"存入数组"<<endl; //先将文件中的数据存入到一个二维数组中
double data1;
double b[][];
double *p1=&b[][];
while(truth>>data1) //遇到空白符结束
{
*p1=data1;
p1++;
}
truth.close();
for(int i=;i<;i++) //分别对每一行数据生成一个变换矩阵,然后存入动态数组poses中
{
Eigen::Quaterniond q2 = Eigen::Quaterniond(b[i][],b[i][],b[i][],b[i][]);
Eigen::Vector3d t2;
t2<<b[i][],b[i][],b[i][];
Sophus::SE3 SE3_qt2(q2,t2);
poses2.push_back(SE3_qt2);
}
// end your code here // draw trajectory in pangolin
DrawTrajectory(poses1,poses2);
return ;
} /*******************************************************************************************/
void DrawTrajectory(vector<Sophus::SE3, Eigen::aligned_allocator<Sophus::SE3>> poses1,vector<Sophus::SE3, Eigen::aligned_allocator<Sophus::SE3>> poses2) {
if (poses1.empty() || poses2.empty() ) {
cerr << "Trajectory is empty!" << endl;
return;
} // create pangolin window and plot the trajectory
//创建一个窗口
pangolin::CreateWindowAndBind("Trajectory Viewer", , );
//启动深度测试
glEnable(GL_DEPTH_TEST);
//启动混合
glEnable(GL_BLEND);
//混合函数glBlendFunc( GLenum sfactor , GLenum dfactor );sfactor 源混合因子dfactor 目标混合因子
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Define Projection and initial ModelView matrix
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(, , , , , , 0.1, ),
//对应的是gluLookAt,摄像机位置,参考点位置,up vector(上向量)
pangolin::ModelViewLookAt(, -0.1, -1.8, , , , 0.0, -1.0, 0.0)
); pangolin::View &d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(), 1.0, -1024.0f / 768.0f)
.SetHandler(new pangolin::Handler3D(s_cam)); while (pangolin::ShouldQuit() == false) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); d_cam.Activate(s_cam);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glLineWidth();
for (size_t i = ; i < poses1.size() - ; i++) {
glColor3f( - (float) i / poses1.size(), 0.0f, (float) i / poses1.size());
glBegin(GL_LINES);
auto p1 = poses1[i], p2 = poses1[i + ];
glVertex3d(p1.translation()[], p1.translation()[], p1.translation()[]);
glVertex3d(p2.translation()[], p2.translation()[], p2.translation()[]);
glEnd();
} for (size_t j = ; j < poses2.size() - ; j++) {
glColor3f( - (float) j / poses2.size(), 0.0f, (float) j / poses2.size());
glBegin(GL_LINES);
auto p3 = poses2[j], p4 = poses2[j + ];
glVertex3d(p3.translation()[], p3.translation()[], p3.translation()[]);
glVertex3d(p4.translation()[], p4.translation()[], p4.translation()[]);
glEnd(); }
pangolin::FinishFrame();
usleep(); // sleep 5 ms
} }
#CMakeLists.txt
# writed by zhang ning //
cmake_minimum_required( VERSION 2.8 ) project(trajectory_compare) set( CMAKE_BUILD_TYPE "Debug" ) set( CMAKE_CXX_FLAGS "-std=c++11 -O3" ) find_package( Sophus REQUIRED)
find_package( Pangolin REQUIRED) include_directories( "/usr/include/eigen3" )
include_directories( ${Sophus_INCLUDE_DIRS} )
include_directories( ${Pangolin_INCLUDE_DIRS} ) add_executable( trajectory_compare trajectory_compare.cpp) target_link_libraries( trajectory_compare ${Sophus_LIBRARIES} ${Pangolin_LIBRARIES} )
画出效果图如下所示

使用Pangolon在同一副图中,画出两个轨迹,比较误差的更多相关文章
- python—networkx:在一张图中画出多个子图
通过plt.subplot能够在一张图中画出多个子图 #coding: utf-8 #!/usr/bin/env python """ Draw a graph with ...
- 机器学习入门-随机森林温度预测-增加样本数据 1.sns.pairplot(画出两个关系的散点图) 2.MAE(平均绝对误差) 3.MAPE(准确率指标)
在上一个博客中,我们构建了随机森林温度预测的基础模型,并且研究了特征重要性. 在这个博客中,我们将从两方面来研究数据对预测结果的影响 第一方面:特征不变,只增加样本的数据 第二方面:增加特征数,增加样 ...
- wpf 在不同DPI下如何在DrawingVisual中画出清晰的图形
环境Win10 VS2017 .Net Framework4.7.1 本文仅讨论在DrawingVisual中进行的画图. WPF单位,系统DPI,显示器DPI三者的定义及关系 WPF单位:一 ...
- 如何在canvas中画出一个太极图
先放一个效果图: 代码如下 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /&g ...
- matplotlib中在for中画出多张图
import matplotlib.pyplot as plt import numpy as np fig, axes = plt.subplots(2, 2) def showim(): for ...
- Latex中画出函数文件的调用关系拓扑图
流程图,思维导图,拓扑图通常能把我们遇到的一些复杂的关系结构用图形的方式展现出来.在Latex中要想画这样的拓扑图,有一个很好用的绘图工具包 pgf/tikz . 1.pgf/tikz的安装:pgf/ ...
- 百度地图API实时画出动态运行轨迹(一条行驶轨迹),车头实时指向行驶方向,设置角度偏移
参考网址:https://blog.csdn.net/skywqnan/article/details/79036262 改变车的方向:http://www.cnblogs.com/peixuanzh ...
- 使用Eclipse在Excel中找出两张表中相同证件号而姓名或工号却出现不同的的项
1:首先把Excel中的文本复制到txt中,复制如下: A表: 证件号 工号 姓名 310110xxxx220130004 101 傅家宜3101 ...
- 给定一个值S,在有序数组中找出两个元素A和B,使 A+B = S.
在网上看到过一个面试题,感觉挺有意思,看别人的代码写的逻辑不够谨慎,重写了一个,较真了又... package com.array7.algorithm; public class Algorithm ...
随机推荐
- 删除ORACLE目录OCI.dll文件无法删除 (转)
删除ORACLE目录OCI.dll文件无法删除 今天准备把虚拟机里的10g卸载安装11g来研究一些新特性 卸载没有用自带的UnInstall工具之前看warehouse的讲课视频凭记忆手动卸载了下删除 ...
- Linux 添用户报错:useradd:警告:此主目录已经存在
建立mysql用户.组 groupadd mysql useradd -g mysql mysql 然后删除 userdel mysql 再添用户和组加时,提示: 解决方法:删除用户不用userdel ...
- 使用librtmp进行H264与AAC直播
libx264 版本是 128libfaac 版本是 1.28 1.帧的划分 1.1 H.264 帧 对于 H.264 而言每帧的界定符为 00 00 00 01 或者 00 00 01. 比如下面的 ...
- Linux 查看目录大小及文件数量命令
查看当前目录大小: [root@21andy.com]# du -sh 查看指定目录大小: [root@21andy.com]# du -sh /www/21andy.com 查看当前目录文件总数: ...
- Memcached 命令行操作
telnet 用于连接 Memcached: [root@localhost ~]# telnet Trying 127.0.0.1... Connected to 127.0.0.1. Escape ...
- Python迭代器笔记
python中的三大器有迭代器,生成器,装饰器,本文重点讲解下迭代器的概念,使用,自定义迭代器等的介绍. 1.概念: 迭代器是一个对象,一个可以记住遍历位置的对象,迭代器对象从集合的第一个元素开始访问 ...
- MDK972-EK开发板裸调试设置和裸机程序烧写(转)
硬件平台:MDK972-EK开发板编译调试软件:KEIL uVision4仿真工具:JLINK V7/V8 本例子从串口输出信息,如图: KEIL uVision4调试设置如图所示: ...
- ts+antd报错error TS2605: JSX element type Xxx is not a constructor function for JSX elements
antd 3 以前的版本需要在 tsconfig.json 的 compilerOptions 中配置 "allowSyntheticDefaultImports": true
- FTP文件下载
using EnterpriseDT.Net.Ftp; /// <summary> /// 下载FTP文件 /// </summary> /// <param name= ...
- Java枚举根据key获取value
package com.utcip.crm.common.constants; import com.utcip.crm.common.base.process.ScheduleStatusEnum; ...