当前位置:网站首页>【 】 calculating trajectory error
【 】 calculating trajectory error
2022-08-06 06:36:00 【small guest】
评估轨迹的误差
计算均方根误差
A T E = 1 N ∑ 1 N ∣ ∣ l o g ( T g r o u n d , t r u t h − 1 T e s t i m a t e , i ) ∣ ∣ 2 2 ATE = \sqrt{\frac{1}{N} \sum_{1}^{N} ||log(T^{-1}_{ground,truth}T_{estimate,i})||^2_2} ATE=N11∑N∣∣log(Tground,truth−1Testimate,i)∣∣22
The format of the given data:
The following three groups of real data data,Corresponding timestamp is,平移,And the rotation of the quaternion said
- 1305031526.67210007 -0.0355094123046875154 -0.0070967674641926326 0.0100241180501300375 0.747064124448400424 0.448673366467715162 -0.443835884862102847 0.208799213344654372
- 1305031526.71219993 -0.0337215082682291722 -0.00720814225260424379 0.00152885084635434598 0.735554936692470185 0.468316402085190431 -0.441780989823346237 0.210874938473073842
- 1305031526.77220011 -0.0335672539713542939 -0.00830686082356790756 -0.0142845526529947753 -0.715793317510356131 -0.503173810000826283 0.436339717689256446 -0.209913540067406978
The following three groups are estimated data
- 1305031526.67147303 0 0 0 0 0 1 0
- 1305031526.70754695 0.00288319499999999986 -0.00466209999999999975 -0.00225430399999999994 0.0106974147769499078 0.00218949395434721002 0.999875286151759579 0.0114098017620960397
- 1305031526.77148104 0.0139789660000000007 -0.0130823169999999996 -0.0108695960000000005 0.0325266728104138744 0.00326054208123759126 0.998528028878688856 0.0432800180783373817
The brief analysis of the data shows,The time data is aligned,Effective digit is a number
代码编写流程
- 需要的库文件,Sophus,pangolin
- 读入数据,Whether the data really read
- 进行计算(From quaternions structureSE3)
- Drawing visual contrast
- Summary of theC++语言技巧
- bug总结
代码如下
#include <iostream>
#include <fstream>
#include <vector>
//unistd.h为Linux/Unix系统中内置头文件,包含了许多系统服务的函数原型,例如read函数、write函数和getpid函数等.
//其作用相当于windows操作系统的"windows.h",是操作系统为用户提供的统一API接口,方便调用系统提供的一些服务.
#include <unistd.h>
#include <eigen3/Eigen/Core>
#include <pangolin/pangolin.h>
#include <sophus/se3.hpp>
using namespace std;
using namespace Sophus;
const string file_est = "/home/wpf/Test/study_cpp/chapter41/data/estimated.txt";
const string file_truth = "/home/wpf/Test/study_cpp/chapter41/data/groundtruth.txt";
//The return type is so long,So to define a return type
typedef vector<Sophus::SE3d,Eigen::aligned_allocator<Sophus::SE3d>> TrajectortyType;
TrajectortyType ReadTrajectory(const string &path);
//Drawing function just need into two paths array
void DrawTrajectory(const TrajectortyType >,const TrajectortyType &esti);
int main() {
//第一步,读入数据
TrajectortyType groundTruth = ReadTrajectory(file_truth);
TrajectortyType estimated = ReadTrajectory(file_est);
//使用vector中的算法
assert(!groundTruth.empty() && !estimated.empty());
assert(groundTruth.size() == estimated.size());
//计算
double rmse = 0;
for (int i = 0; i < groundTruth.size(); ++i) {
Sophus::SE3d p_est = estimated[i],p_tru = groundTruth[i];
double error_1 = (p_tru.inverse()*p_est).log().norm();
rmse += error_1*error_1;
}
rmse = rmse/groundTruth.size();
rmse = sqrt(rmse);
cout<<"RMSE:"<<rmse<<endl;
//出图像
DrawTrajectory(groundTruth,estimated);
std::cout << "Hi,wpf!You're the best!" << std::endl;
return 0;
}
TrajectortyType ReadTrajectory(const string &path){
ifstream fin(path);
TrajectortyType trajectorty;
if(!fin){
cerr<<"tracjectory"<<path <<" not found"<<endl;
return trajectorty;
}
//如何读数据,数据格式的处理
//getline是以‘\n’截断,不会忽略空格.
//eof是以’空格‘或’\n’截断,Will ignore some indispensable space,如query"华为 9X"
/** * * * */
while(!fin.eof()){
double time,tx,ty,tz,qx,qy,qz,qw;
fin>>time>>tx>>ty>>tz>>qx>>qy>>qz>>qw;
Sophus::SE3d p1(Eigen::Quaterniond(qw,qx,qy,qz),Eigen::Vector3d(tx,ty,tz));
trajectorty.emplace_back(p1);
}
return trajectorty;
}
void DrawTrajectory(const TrajectortyType >, const TrajectortyType &esti) {
// create pangolin window and plot the trajectory
pangolin::CreateWindowAndBind("Trajectory Viewer", 1024, 768);
//Three format
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(1024, 768, 500, 500, 512, 389, 0.1, 1000),
pangolin::ModelViewLookAt(0, -0.1, -1.8, 0, 0, 0, 0.0, -1.0, 0.0)
);
pangolin::View &d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, pangolin::Attach::Pix(175), 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(2);
//Draw the real trajectory images,
for (size_t i = 0; i < gt.size() - 1; i++) {
glColor3f(0.0f, 0.0f, 1.0f); // blue for ground truth
glBegin(GL_LINES);
//Access to data between the first and second,To get the translation vector between
auto p1 = gt[i], p2 = gt[i + 1];
glVertex3d(p1.translation()[0], p1.translation()[1], p1.translation()[2]);
glVertex3d(p2.translation()[0], p2.translation()[1], p2.translation()[2]);
glEnd();
}
//Draw the forecast track,同上
for (size_t i = 0; i < esti.size() - 1; i++) {
glColor3f(1.0f, 0.0f, 0.0f); // red for estimated
glBegin(GL_LINES);
auto p1 = esti[i], p2 = esti[i + 1];
glVertex3d(p1.translation()[0], p1.translation()[1], p1.translation()[2]);
glVertex3d(p2.translation()[0], p2.translation()[1], p2.translation()[2]);
glEnd();
}
pangolin::FinishFrame();
usleep(5000); // sleep 5 ms
}
}
对应的CMakeList.txt如下:
cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 14)
project(chapter41)
find_package(Pangolin REQUIRED)
# 由于SophusLibrary to depend onfmt库,所以安装Sophus之前要先安装fmt
find_package(fmt REQUIRED)
find_package(Sophus REQUIRED)
include_directories("usr/include/eigen3")
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(chapter41 main.cpp)
target_link_libraries(chapter41 ${Pangolin_LIBRARIES} Sophus::Sophus fmt::fmt)
C++Language skills
(1)文件的读写,
//getline是以‘\n’截断,不会忽略空格. //eof是以’空格‘或’\n’截断,Will ignore some indispensable space,如query"华为 9X"If the behavior at the end
使用
//方式一:getline读取 getline(fin, line); //逐行读取fin打开的文件,保存在line里.(分隔符为 \n)If end with Spaces and the behavior,使用
while(!fin.eof) { //当finOpen the file didn't finish read fin >> line; //Will take the Spaces and the\nDelimited text intoline中 }#include <fstream> std::ifstream fin; //定义输入文件流对象 fin.open("data/xxx.txt") //Open the program under the relative path to a file,Additional parameters can also bestd::ios::in等各种 std::string line; //File stream carrier,面向开发人员 //方式一:getline读取 getline(fin, line); //逐行读取fin打开的文件,保存在line里.(分隔符为 \n) //方式二:!eof() while(!fin.eof) { //当finOpen the file didn't finish read fin >> line; //Will take the Spaces and the\nDelimited text intoline中 }(2)使用了typedef关键字
(3)使用了auto 关键字
bug总结
bug_1
问题:QUOTE expectedReason is introduced in the address not join quotes
边栏推荐
- 【Pytorch】torch.nn.functional.conv2d(F.conv2d) same padding实现方法(输入与输出大小相同)
- ZLMediakit独家特性介绍
- 二分法的基本模板
- SourceTree 常用技巧
- 【Programming】编程常用英文术语中文对照,及其解释
- ROS文件的注释说明(不断更新)
- pip命令安装工具包时出现ReadTimeoutError或者THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE问题解决
- Qt教程(2) : Qt元对象系统
- [Multi-sensor fusion] A complete technical learning route
- 学妹深夜语音:想月薪达到30k~50k,我让她看看这个领域
猜你喜欢

阿里云服务器ubuntu安装MySQL并配置端口
![[Multi-sensor fusion] A complete technical learning route](/img/7e/dbbbaf885da7d11e7a02a54f0b271a.png)
[Multi-sensor fusion] A complete technical learning route

利用预训练语言模型ERNIE提供文本相似度(语义匹配)计算服务的简单实例

PyTorch之MLP

7月17日上午,阿里AE技术团队直播专场,分享CVPR挑战赛冠军、亚军方案!

FAQ智能问答系统设计与实现

【Numpy】np.stack()最通俗易懂解释

Cross-compilation libcurl + the openssl library

No URLs will be polled as dynamic configuration sources警告处理

【Binocular Vision】Stereo Matching
随机推荐
工业相机镜头选型
【RGBD视觉】
R爬虫常用的包与用法
【ros下激光雷达的简单使用】(1)
SRS4.0 RTC模块增加Gop cache
Qt implements animation transition when window size changes
R语言模糊匹配
新朋老友齐聚首,共话「图形学」未来 | 将门行动派特别直播企划,就在7月6日晚!
分层架构&SOA架构
AMPCOLOY940 美国进口高导热无铍铜合金
学习笔记15--驾驶舒适度评价体系
List集合遍历的五种方法
九、一起学习Lua 运算符
【Pytorch】torch.nn.functional.conv2d(F.conv2d) same padding实现方法(输入与输出大小相同)
【zed相机的简单使用】(2)
R语言基础(数据类型,运算符,数据整理,管道操作)
Qt 5.14.2 connect to Mysql database
ffplay源码分析:图像格式转换
利用R处理复杂表格1
About the printf function Warning: format string is not a string literal (potentially insecure)!