下面代码主要功能:
- 读取保存有pose的文件,文件格式为:timestamp tx ty tz qw qx qy qz;
- 第3个参数dataset_i表示测试的第i个数据集的轨迹,代码中,直接将第i个数据集的groundtruth写死了.
- opencv绘制轨迹,用红色表示第一个文件中的轨迹,绿色表示第二个文件中的轨迹.
局部效果图:
下面是代码:
//#include<opencv2/opencv.hpp>
#include <opencv2/viz.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/calib3d.hpp>
#include<fstream>
#include<iostream>
#include<vector>
#include<Eigen/Geometry>
#include<Eigen/Core>
using namespace std;
using namespace cv;
int main(int argc,char **argv)
{
if(argc != 4){
cerr << "sytax: ./drawTrajectory trajectory_vio.txt trajectory_viwo.txt dataset_index" << endl;
return 0;
}
string path = argv[1];
ifstream fin_vio(path.c_str());
path = argv[2];
ifstream fin_viwo(path.c_str());
if (!fin_vio || !fin_viwo)
{
cerr << "error in openning the file !" << endl;
return 0;
}
//groundtruth
int dataset_i = atoi(argv[3]);
double t_wcn_gt1[3] = {-0.232988 , 0.178259 , 0.00207278};
double t_wcn_gt2[3] = {0.0099497 , 0.153633 , 0.0190607};
// visualization
cv::viz::Viz3d vis("Visual Odometry");
cv::viz::WCoordinateSystem world_coor(1.0), camera_coor(0.5);
vis.setBackgroundColor(cv::viz::Color::white());
// draw the trace
int i = 0;
Point3d